How to make it work: SVN and Windows authentication
I thought I would post some information to help other users who may run into the same issues with integrated Windows authentication as I did. A support call with Saar got me most of the way there and a previous post by casagrandeale (http://support.countersoft.com/forums/thread/11708.aspx) was also very helpful. Thanks to both of you!
Some information about my setup
Subversion and Gemini servers are on two different servers in the same domain. They are both Windows 2003 R2 x64 with SP2. We are using VisualSVN server for our subversion server (currently v 2.05)
The IIS site for Gemini and the Apache site for SVN are both configured to use SSL.
Anonymous access is disabled for the Gemini IIS site (Enable Anomymous Access is unchecked) and Integrated Windows authentication is enabled (checked). The web.config file for Gemini is using Window as the authentication mode.
<authentication mode="Windows">
<forms name=".Gemini35" loginUrl="Default.aspx" timeout="60" path="/">
</forms>
</authentication>
Getting Started with SVN commits
I did a build of the CounterSoft.Gemini.SourceControl.SVN and put the dll's and config file in the hooks folder on the SVN server. The only change I made to the config file was to change the path to the SVN bin files to match the path on our x64 server. For my initial attempts, I was using manager/manager in the CounterSoft.Gemini.SourceControl.SVN.exe.config file.
Troubleshooting Problems
I had serveral problems along the way.
1) I was getting a windows pop-up login box rather than being authenticated directly by the network. The solution to this was to add the Gemini URL to my intranet sites in IE (Internet options > Security tab > Local Intranet Sites > Sites > Advanced > Add). You will also need Enable Integrated Windows authentication checked under the Advanced tab but that should be on by default.
2) Windows authentication credentials weren't getting passed to the Gemini site. In talking with Saar, he said the easiest way to solve that was to create a second IIS site for Gemini and use Forms authentication for that site.
<authentication mode="Forms">
<forms name=".Gemini35" loginUrl="Default.aspx" timeout="60" path="/">
</forms>
</authentication>
3) The comment for the issue showed the author as my Windows login but the notification email and the heading in gemini were using the gemini forms login as defined in the CounterSoft.Gemini.SourceControl.SVN.exe.config file. That is, the email said "A comment has been added by Manager Person to the following issue." I wanted the email and Gemini to show the Windows user name at every place.
I modified the code posted by casagrandeale and now I've got that functionality working also. My modified code is below:
In PostCommitHandler.cs, comment line 135 as shown and replace with call to new helper function GetUserId.
//sourceControlComment.UserID = Program.GeminiServiceManager.UsersService.WhoAmI().UserID;
//Added customized code to extract Windows user name
sourceControlComment.UserID = GetUserId(author);
Add the following two helper functions to PostCommitHandler.cs:
/// <summary>
/// Extract the matching Windows User from Gemini users
/// </summary>
/// <param name="author">SVN author</param>
/// <returns>Id of the Gemini user</returns>
private int GetUserId(string svnAuthor)
{
int toReturn = 0;
string author = svnAuthor.ToLower().Trim();
DiagnosticsManager.TraceMessage("Searching users...");
UserEN[] users = Program.GeminiServiceManager.UsersService.GetUsers();
DiagnosticsManager.TraceMessage("Users: " + users.Length);
UserEN gemUser = null;
foreach (UserEN user in users)
{
DiagnosticsManager.TraceMessage("USER: " + user.UserName);
string userName = UserNameWithoutDomain(user.UserName);
if (userName == author)
{
gemUser = user;
break;
}
}
if (gemUser != null)
{
DiagnosticsManager.TraceMessage("Found Author: " + author + " UserID: " + gemUser.UserID);
toReturn = gemUser.UserID;
}
else
{
DiagnosticsManager.TraceMessage("not Found Author: " + author);
toReturn = Program.GeminiServiceManager.UsersService.WhoAmI().UserID;
}
return toReturn;
}
/// <summary>
/// Remove the Domain prefix from a Windows user name
/// Input of "Domain\UserName" returns as "username"
/// </summary>
/// <param name="userName"></param>
/// <returns>Lower-case and trimmed username without a domain prefix</returns>
private string UserNameWithoutDomain(string userName)
{
string toReturn = userName.ToLower().Trim();
int slashIndex = userName.IndexOf(@"\");
if (slashIndex > 0)
{
toReturn = toReturn.Substring(slashIndex + 1);
}
return toReturn;
}
I hope this helps some others along the way.
|
dgsiss
· 1 |
|
| Friday, August 21, 2009, 6:27:05 PM | |




