From: <m_h...@us...> - 2006-07-07 00:01:28
|
Revision: 81 Author: m_hildebrand Date: 2006-07-06 17:01:18 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/tcdb/?rev=81&view=rev Log Message: ----------- Got the authentication hooked up to AD Modified Paths: -------------- Design/Architecture/Namespace, Class, and Public Method Definitions.doc Website/App_Code/TCDB_Constants.cs Website/App_Code/TCDB_Users.cs Website/App_Themes/Python/python.css Website/Includes/Header_User.ascx Website/web.config Added Paths: ----------- Website/App_Code/AD_Authentication.cs Website/Includes/AdministrationTree.ascx Website/Includes/SqlDatabase.ascx Modified: Design/Architecture/Namespace, Class, and Public Method Definitions.doc =================================================================== (Binary files differ) Added: Website/App_Code/AD_Authentication.cs =================================================================== --- Website/App_Code/AD_Authentication.cs (rev 0) +++ Website/App_Code/AD_Authentication.cs 2006-07-07 00:01:18 UTC (rev 81) @@ -0,0 +1,79 @@ +using System; +using System.Data; +using System.DirectoryServices; +using System.Configuration; +using System.Web; +using System.Web.Security; +using System.Web.UI; +using System.Web.UI.WebControls; +using System.Web.UI.WebControls.WebParts; +using System.Web.UI.HtmlControls; +using TCDB_Users; + +namespace AD_Auth +{ + /// <summary> + /// Summary description for AD_Authentication + /// </summary> + public static class AD_Authentication + { + public static bool AD_Authenticate(string strDomain, string strUserName, string strPassword) + { + bool result = false; + DirectoryEntry de = new DirectoryEntry("LDAP://" + strDomain, strUserName, strPassword); + DirectorySearcher ds = new DirectorySearcher(de); + ds.SearchScope = SearchScope.OneLevel; + try + { + SearchResult sr = ds.FindOne(); + if (sr != null) result = true; + } + catch + { + result = false; + } + + return result; + } + + public static TCDB_User AD_GetUserInfo(string strDomain, string strUserName, string strPassword) + { + DirectoryEntry de = new DirectoryEntry("LDAP://" + strDomain, strUserName, strPassword); + DirectorySearcher ds = new DirectorySearcher(de); + ds.SearchScope = SearchScope.Subtree; + ds.Filter = "(&(objectClass=user)(sAMAccountName=" + strUserName + "))"; + TCDB_User user = new TCDB_User(); + + user.USERID = TCDB_Constants.TCDB_Constant.USER_NEWUSER; + user.AUTOMATION = false; + user.ISAUTHENTICATED = true; + user.USERNAME = strUserName; + string myText = ""; + try + { + SearchResult sr = ds.FindOne(); + if (sr != null) + { + ResultPropertyCollection rpc = sr.Properties; + + user.FIRSTNAME = rpc["givenName"][0].ToString(); + user.LASTNAME = rpc["sn"][0].ToString(); + user.EMAIL = rpc["mail"][0].ToString(); + user.HOMEPHONE = rpc["homePhone"][0].ToString(); + user.OFFICEPHONE = rpc["telephoneNumber"][0].ToString(); + } + } + catch + { + } + finally + { + ds.Dispose(); + de.Dispose(); + } + + return user; + } + + } +} \ No newline at end of file Modified: Website/App_Code/TCDB_Constants.cs =================================================================== --- Website/App_Code/TCDB_Constants.cs 2006-07-06 22:45:02 UTC (rev 80) +++ Website/App_Code/TCDB_Constants.cs 2006-07-07 00:01:18 UTC (rev 81) @@ -17,5 +17,6 @@ { public static int USER_FAILEDLOGIN = -2; public static int USER_NOTREGISTERED = -1; + public static int USER_NEWUSER = -1; } } \ No newline at end of file Modified: Website/App_Code/TCDB_Users.cs =================================================================== --- Website/App_Code/TCDB_Users.cs 2006-07-06 22:45:02 UTC (rev 80) +++ Website/App_Code/TCDB_Users.cs 2006-07-07 00:01:18 UTC (rev 81) @@ -1,6 +1,5 @@ using System; using System.Data; -using System.DirectoryServices; using System.Data.SqlClient; using System.Configuration; using System.Web; @@ -13,6 +12,7 @@ using TCDB_Constants; using System.Collections; using System.Collections.Generic; +using AD_Auth; namespace TCDB_Users @@ -37,34 +37,43 @@ /// <value> /// An <c>int</c> representing the user's ID or DefaultValue if the process fails /// </value> - public static int TCDB_AuthenticateUser(string strUserName, string strPassword) + public static TCDB_User TCDB_AuthenticateUser(string strDomain, string strUserName, string strPassword) { // TODO: Add logic here to determine and use the appropriate // authentication method based on configuration data - bool result = false; - DirectoryEntry de = new DirectoryEntry("LDAP://slam", strUserName, strPassword); - DirectorySearcher ds = new DirectorySearcher(de); - ds.SearchScope = SearchScope.OneLevel; - try + + // Using AD authentication + if (!AD_Authentication.AD_Authenticate(strDomain, strUserName, strPassword)) { - SearchResult sr = ds.FindOne(); - if (sr != null) result = true; + // We can't authenticate, so return the guest user + return new TCDB_User(); } - catch - { - result = false; - } - if (!result) + // Determine if the user exists in the DB or not. If not, we need to get + // the basic info + TCDB_User user = TCDB_GetUserInfo(strUserName); + if (user.USERID > 1) { - return TCDB_Constant.USER_FAILEDLOGIN; + user.ISAUTHENTICATED = true; + return user; } - // TODO: Look up the user ID from the DB now that we have a valid user - // and return the user object - return 0; + // Using AD authentication + user = AD_Authentication.AD_GetUserInfo(strDomain, strUserName, strPassword); + + + + return user; } + + public static TCDB_User TCDB_GetUserInfo(string strUserName) + { + // TODO: Check against the DB for user information + return new TCDB_User(); + } + + } /// <summary> @@ -183,6 +192,7 @@ public bool ISAUTHENTICATED { get { return isAuthenticated; } + set { isAuthenticated = value; } } } Modified: Website/App_Themes/Python/python.css =================================================================== --- Website/App_Themes/Python/python.css 2006-07-06 22:45:02 UTC (rev 80) +++ Website/App_Themes/Python/python.css 2006-07-07 00:01:18 UTC (rev 81) @@ -83,17 +83,17 @@ } /* Define the username and password box sizes */ -#User #UserName, #User #Password +#User #UserNameControl, #User #PasswordControl { display: inline; } -#UserName input, #Password input +#UserNameControl input, #PasswordControl input { width: 80px; } -#User #RememberMe +#User #RememberMeControl { display: inline; position: relative; Added: Website/Includes/AdministrationTree.ascx =================================================================== --- Website/Includes/AdministrationTree.ascx (rev 0) +++ Website/Includes/AdministrationTree.ascx 2006-07-07 00:01:18 UTC (rev 81) @@ -0,0 +1,5 @@ +<%@ Control Language="C#" ClassName="AdministrationTree" %> + +<script runat="server"> + +</script> Modified: Website/Includes/Header_User.ascx =================================================================== --- Website/Includes/Header_User.ascx 2006-07-06 22:45:02 UTC (rev 80) +++ Website/Includes/Header_User.ascx 2006-07-07 00:01:18 UTC (rev 81) @@ -2,30 +2,25 @@ <%@ Import Namespace="TCDB_Users" %> <script runat="server"> - - protected void Login_Click(object sender, EventArgs e) - {/* - if (TCDB_UserDB.TCDB_AuthenticateUser(UserNameControl.Text, PasswordControl.Text) > 0) - { - } - else - { - - }*/ + protected void Login_Authenticate(object sender, EventArgs e) + { + int temp = 1; + string [] user = ((System.Web.UI.WebControls.Login)sender).UserName.Split("\\".ToCharArray()); + TCDB_UserDB.TCDB_AuthenticateUser(user[0], user[1], ((System.Web.UI.WebControls.Login)sender).Password); } </script> -<asp:LoginView ID="LoginView1" runat="server"> +<asp:LoginView ID="LoginView" runat="server"> <AnonymousTemplate> -<asp:Login ID="Login1" runat="server"> +<asp:Login ID="Login1" OnAuthenticate="Login_Authenticate" runat="server"> <LayoutTemplate> <asp:Label ID="lblMessage" runat="server" Text="" /> - Username: <div id="UserName"><asp:TextBox ID="UserNameControl" runat="server" /></div> - <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserNameControl" Text="*" /> - Password: <div id="Password"><asp:TextBox ID="PasswordControl" runat="server" TextMode="password" /></div> - <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="PasswordControl" Text="*" /> - Remember Me: <div id="RememberMe"><asp:CheckBox ID="RememberMeControl" runat="server" /></div> - <asp:LinkButton ID="Login" CommandName="Login" Text="Login" runat="server" OnClick="Login_Click" /> + Username: <div id="UserNameControl"><asp:TextBox ID="UserName" runat="server" /></div> + <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" Text="*" /> + Password: <div id="PasswordControl"><asp:TextBox ID="Password" runat="server" TextMode="password" /></div> + <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" Text="*" /> + Remember Me: <div id="RememberMeControl"><asp:CheckBox ID="RememberMe" runat="server" /></div> + <asp:LinkButton ID="LoginControl" CommandName="Login" Text="Login" runat="server" /> </LayoutTemplate> </asp:Login> </AnonymousTemplate> Added: Website/Includes/SqlDatabase.ascx =================================================================== --- Website/Includes/SqlDatabase.ascx (rev 0) +++ Website/Includes/SqlDatabase.ascx 2006-07-07 00:01:18 UTC (rev 81) @@ -0,0 +1,5 @@ +<%@ Control Language="C#" ClassName="SqlDatabase" %> + + + + Modified: Website/web.config =================================================================== --- Website/web.config 2006-07-06 22:45:02 UTC (rev 80) +++ Website/web.config 2006-07-07 00:01:18 UTC (rev 81) @@ -44,9 +44,15 @@ --> </microsoft.web> <appSettings/> - <connectionStrings/> + <connectionStrings> + <add name="dadConnectionString" connectionString="Data Source=dad\sqlserver2005;Initial Catalog=tcdb;Persist Security Info=True;User ID=tcdb;Password=tcdbpw" + providerName="System.Data.SqlClient" /> + </connectionStrings> <system.web> - <pages theme="Python" styleSheetTheme="Python"> + <authentication mode="Forms"> + <forms loginUrl="login.aspx" /> + </authentication> + <pages styleSheetTheme="Python"> <!-- TODO: Make sure the theme is being pulled dynamically --> <controls> <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |