CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.security Tags:
Item Type: NewsGroup Date Entered: 1/26/2004 5:44:45 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 13 Views: 26 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
14 Items, 1 Pages 1 |< << Go >> >|
ahughes
Asp.Net User
LDAP authentication1/26/2004 5:44:45 PM

0/0

Hi

I'm looking for a simple tutorial for setting up LDAP forms authentication for a website preferably in vb.net. I have searched these forums but have not been able to find exactly what I am looking for.

Can anyone help?
keithadler
Asp.Net User
Re: LDAP authentication1/26/2004 7:38:21 PM

0/0

http://msdn.microsoft.com/library/en-us/dnnetsec/html/SecNetHT02.asp?frame=true

Great tutorial.
ahughes
Asp.Net User
Re: LDAP authentication1/27/2004 9:19:11 AM

0/0

Thanks, I have seen that article. I'm looking for a VB example and also that example requires you have visualstudio.net which I don't have. Do you know of any straight code examples?
kfuller
Asp.Net User
Re: LDAP authentication1/27/2004 2:37:16 PM

0/0

Check out this, its the same article but written in VB
http://support.microsoft.com/default.aspx?kbid=326340

Also, you may want to check out the following code for checking a user against an AD group. I found this on a post somewhere, and I tested it successfully. What I did was create a new web app, default settings. Anonymous is off, windows authentication is on, and impersonation is true. I simply added a label and a button. Put the code below in for the button to display a true or false in the label if the user connecting was in the group.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim GroupAD As Object
Dim temp As Boolean
'get the users domain and ID
Dim tempStr As String = Context.User.Identity.Name
Dim userIDExprs() As String
'split the domain and user ID into an array 0=domain 1=userid
userIDExprs = Split(tempStr, "\")
'get group from Active Directory
GroupAD = GetObject("WinNT://domain/adgroupname")
'return true or false if user id exists in group
temp = GroupAD.IsMember("WinNT://domain/" & userIDExprs(1))
'show result on page
lblAD.Text = temp.ToString
End Sub


Hope this helps,
-Kirk
ahughes
Asp.Net User
Re: LDAP authentication2/2/2004 12:53:51 PM

0/0

Thanks for the article. I have a couple of questions though

I'm not using visualstudio.net so not sure on some of the instructions in the article. To add the reference to System.DirectoryServices.dll do I need to add


<%@ Assembly Name="System.DirectoryServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>


to every page.

Also getting an error on the global.asax page, where exactly do I place the


Imports System.Web.Security
Imports System.Security.Principal


The article mentions global.asax.vb file, what is that?, I just have a global.asax file, here is the code


<%@ Application language="VB" %>



<script runat="server">

Imports System.Web.Security
Imports System.Security.Principal



Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)


' Fires upon attempting to authenticate the use
Dim cookieName As String = FormsAuthentication.FormsCookieName
Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName)

If (authCookie Is Nothing) Then
'There is no authentication cookie.
Return
End If

Dim authTicket As FormsAuthenticationTicket = Nothing

Try
authTicket = FormsAuthentication.Decrypt(authCookie.Value)
Catch ex As Exception
'Write the exception to the Event Log.
Return
End Try

If (authTicket Is Nothing) Then
'Cookie failed to decrypt.
Return
End If

'When the ticket was created, the UserData property was assigned a
'pipe-delimited string of group names.
Dim groups As String() = authTicket.UserData.Split(New Char() {"|"})

'Create an Identity.
Dim id As GenericIdentity = New GenericIdentity(authTicket.Name, "LdapAuthentication")

'This principal flows throughout the request.
Dim principal As GenericPrincipal = New GenericPrincipal(id, groups)

Context.User = principal

End Sub

</script>



kfuller
Asp.Net User
Re: LDAP authentication2/2/2004 1:28:12 PM

0/0

Well, I'm not sure about how to add the System.DirectoryServices.dll outside of Visual Studio.Net (which is what I use).

As for the global.asax.vb file, it is simply Visual Studio's notation of the code behind the global.asax file. The file you have includes all the functions that are in my global.asax.vb file.

I had issues dealing with MS's description of the forms authentication. Which is why I opted to use the code I supplied with my last post. It doesn't require any special thing other than capturing the uses id.

You may want to check out this
http://www.wwwcoder.com/main/parentid/260/site/2150/68/default.aspx
it is another explanation of how to control AD from ASP. It includes code for group queries, etc. Again, I didn't use this as the simple code provided the solution I required.

Hope this helps,
-Kirk
dunnry
Asp.Net User
Re: LDAP authentication2/2/2004 2:10:16 PM

0/0

Hi ahughes -

Check this post on how to reference System.DirectoryServices without VS: view post 455196

If you want to use 'Imports' statements in your aspx file, you need to use a different syntax, here is an example:
<%@ Import Namespace="System.DirectoryServices" %>
Please note that that does not reference the dll, it simply allows you to use the classes without fully qualifying them (i.e. the post above still applies!)
Ryan Dunn
Weblog
The Book
LDAP Programming Help
ahughes
Asp.Net User
Re: LDAP authentication2/2/2004 3:37:15 PM

0/0

Thank you both very much for your help. Think i am almost here, will give the simple code method a go but quite keen to get this working first.

I get the error below


Compiler Error Message: BC30002: Type 'LdapAuthentication' is not defined.

Source Error:


Line 10: Dim adAuth as LdapAuthentication = new LdapAuthentication(adPath)


with this code on my login.aspx page



<%@ Page Language="vb" autoeventwireup="true" %>
<%@ import Namespace="FormsAuthAd.FormsAuth" %>
<%@ Import Namespace="System.DirectoryServices" %>
<%@ Assembly Name="System.DirectoryServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%>
<script runat="server">

sub Login_Click(sender as object,e as EventArgs)
Dim adPath as String = ""path to ldap serer here(didn't want to post it)"
Dim adAuth as LdapAuthentication = new LdapAuthentication(adPath)
try
if(true = adAuth.IsAuthenticated(txtDomain.Text, txtUsername.Text, txtPassword.Text)) then
Dim groups as string = adAuth.GetGroups()

'Create the ticket, and add the groups.
Dim isCookiePersistent as boolean = chkPersist.Checked
Dim authTicket as FormsAuthenticationTicket = new FormsAuthenticationTicket(1, _
txtUsername.Text,DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups)

'Encrypt the ticket.
Dim encryptedTicket as String = FormsAuthentication.Encrypt(authTicket)

'Create a cookie, and then add the encrypted ticket to the cookie as data.
Dim authCookie as HttpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)

if(isCookiePersistent = true) then
authCookie.Expires = authTicket.Expiration
end if
'Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie)

'You can redirect now.
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false))

else
errorLabel.Text = "Authentication did not succeed. Check user name and password."
end if

catch ex as Exception
errorLabel.Text = "Error authenticating. " & ex.Message
end try
end sub

</script>
<html>
<head>
</head>
<body>
<form id="Login" method="post" runat="server">
<asp:Label id="Label1" runat="server">Domain:</asp:Label>
<asp:TextBox id="txtDomain" Runat="server"></asp:TextBox>
<br />
<asp:Label id="Label2" runat="server">Username:</asp:Label>
<asp:TextBox id="txtUsername" Runat="server"></asp:TextBox>
<br />
<asp:Label id="Label3" runat="server">Password:</asp:Label>
<asp:TextBox id="txtPassword" Runat="server" TextMode="Password"></asp:TextBox>
<br />
<asp:Button id="btnLogin" onclick="Login_Click" Runat="server" Text="Login"></asp:Button>
<br />
<asp:Label id="errorLabel" runat="server" forecolor="#ff3300"></asp:Label>
<br />
<asp:CheckBox id="chkPersist" Runat="server" Text="Persist Cookie"></asp:CheckBox>
</form>
</body>
</html>



kfuller
Asp.Net User
Re: LDAP authentication2/2/2004 4:33:10 PM

0/0

While you have the following in your code:
<%@ Import Namespace="FormsAuthAd.FormsAuth" %>
It doesn't appear to be importing the class file correctly. Maybe try this when declaring your new variable
Dim adAuth as FormsAuth.LdapAuthentication = new FormsAuth.LdapAuthentication(adPath)
or
Dim adAuth as FormsAuthAd.FormsAuth.LdapAuthentication = new FormsAuthAd.FormsAuth.LdapAuthentication(adPath)

Wish I could help more but it just adds it properly under VStudio. I'll take another look if I get some free time later today.

-Kirk
ahughes
Asp.Net User
Re: LDAP authentication2/4/2004 10:26:16 AM

0/0

I think the problem lies with me not using visual studio, for example the instructions below

Start Microsoft Visual Studio .NET.
On the File menu, point to New, and then click Project.
Click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates.
In the Location box, type http://<servername>/FormsAuthAd (Replacing http://localhost if you are using the local server (so as to have http://localhost/FormsAuthAd, and then click OK.
Right-click the References node in Solution Explorer, and then click Add Reference.
On the .NET tab in the Add Reference dialog box, click System.DirectoryServices.dll, click Select, and then click OK.


I did not create a new project but simply created the files in the root folder, so I did not name anything FormsAuthAD

I guess this is why

<%@ import Namespace="FormsAuthAd.FormsAuth" %>

does not import the class properly.

I tried using simply

<%@ import Namespace="FormsAuth" %>

but still get the error

Compiler Error Message: BC30002: Type 'LdapAuthentication' is not defined.

ahughes
Asp.Net User
Re: LDAP authentication2/10/2004 12:07:44 PM

0/0

can anyone help?
kfuller
Asp.Net User
Re: LDAP authentication2/10/2004 1:23:46 PM

0/0

Well, I haven't done much with standard ASP outside of Visual Studio, so I'm not sure if this will help. However, I found that previously if you wanted to include a class file you had to use this syntax:
<!--#include file = "classFile.asp"-->
instead of what the documentation shows for inheriting the file. The class file would be your FormsAuth class file and you could need to include the relative path as seen by IIS.

I'll look a little more, but I belive this is the direction you want to be heading in.

-Kirk
JasonJIn
Asp.Net User
Re: LDAP authentication2/11/2004 1:36:29 AM

0/0

thanks
ahughes
Asp.Net User
Re: LDAP authentication2/12/2004 12:25:59 PM

0/0

thanks for all your help but getting the same error. Can someone who has used this example and got it to work please post the full code for the login.aspx page

many thanks :-)
14 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Stealing the Network: How to Own the Box Authors: Ryan Russell, Jeff Moss, Pages: 448, Published: 2003
Linux: The Complete Reference Authors: Richard Petersen, Pages: 830, Published: 2007
Practical UNIX and Internet Security Authors: Simson Garfinkel, Gene Spafford, Alan Schwartz, Pages: 954, Published: 2003
PHP Cookbook Authors: David Sklar, Adam Trachtenberg, Pages: 784, Published: 2006
Professional Joomla! Authors: Dan Rahmel, Pages: 457, Published: 2007
Linux Server Security Authors: Michael D. Bauer, Pages: 522, Published: 2005
Red Hat Linux Networking and System Administration Authors: Terry Collings, Kurt Wall, Pages: 992, Published: 2005
Linux in a Windows World Authors: Roderick W. Smith, Pages: 478, Published: 2005
Security+ Study Guide and DVD Training System: study guide & DVD training system Authors: Syngress, Michael Cross, Norris L. Johnson, Robert J. Shimonski, Tony Piltzecker, Debra Littlejohn Shinder, Pages: 784, Published: 2002
Mechanics of User Identification and Authentication: Fundamentals of Identity Management Authors: Dobromir Todorov, Pages: 728, Published: 2007

Web:
LDAP Authentication In the LDAP, authentication information is supplied in the "bind" operation. In LDAP v2, a client initiates a connection with the LDAP server by sending the ...
System Authentication using LDAP Apache can also use LDAP for authentication - this would simplify restricting access to certain areas of the company intranet, for example. ...
Authentication using LDAP In LDAP, authentication is supplied in the "bind" operation. Ldapv3 supports three types of authentication: anonymous, simple and SASL authentication. ...
LDAP Authentication In Linux | HowtoForge - Linux Howtos and Tutorials This howto will show you howto store your users in LDAP and authenticate some of the services against it. I will not show howto install particular packages, ...
Submerged - Subversion Blog - Subversion LDAP Authentication ... LDAP Authentication & Authorization is final; do not check other databases # I was paranoid that if i set this on it would impact some other authentication ...
Instructions for doing authentication with LDAP I defined these in a file "init.ldif": # initial attributes for LDAP authentication database # Specify root value, Group and People. ...
Authentication Methods for LDAP Standards Track [Page 7] RFC 2829 Authentication Methods for LDAP May 2000 6. Password-based authentication LDAP implementations MUST support authentication ...
Linux.com :: Linux LDAP authentication When you have to administer a network of many machines, you quickly find out how much duplication of effort is involved with normal ...
WordPress, LDAP, and Playing Nicely - Zilla Smash! So here’s version 1.01 of my LDAP Authentication plugin for WordPress 1.5.1. ... Il plugin LDAP Authentication per WordPress rende posibile l’autenticazione ...
LDAP Client Login Authentication YoLinux tutorial on login authentication using LDAP.

Videos:
LDAP for Authentication Neil Ferguson gives a short talk on LDAP, what it is, how it is structured and how it can be used to manage users across a network. See http://www.h...
Rapid Identity Demos - Scenario 4 - Linux LDAP Configuration This scenario demonstrates how the Linux servers in the solution use LDAP for authentication, access control and authorization. The servers are alre...
Screencast: AM LDAP Bug Serious security vulnerability using Sun Access Manager 7.1 update 1 authenticating against Sun Directory Server 5.2. Originally mentioned in: http:...
FSOSS2007: Implementing and Supporting Moodle Neal Stephenson - speaking at Seneca's Open Source Symposium in 2007 With the successful piloting of Moodle at York University, Moodle is now being ...
Rapid Identity Demos - Scenario 4 Intro This is the introduction to Identity Automation's Rapid Identity solution demos. Scenario 4 deals with configuring the users to use LDAP for Linux au...
pnMeeting 2007: Mark West talks about .8/.9 In his final presentation for this year Mark West presented some of the user side highlights of .8 Mark Ronchera asked for the use of OpenID in fut...
WANdisco Free Security for Subversion and CVS * Prevents unauthorized access attempts and alerts security administrators immediately when they occur. * Allows access control to be implemented at...
HP LaserJet M3035xs MultiFunction Laser Printer Visit http://tiger.tv/more_info/?292 to empower work teams with print, copy, scan, and digital sending functionality in one convenient device. the HP...
Integrating Bomgar into your Help Desk Infrastructure http://www.bomgar.com/remotedesktopaccess/b300integration.htm - Bomgar offers a number of ways to integrate the Bomgar Box into your existing help de...
Integrating Bomgar into your Help Desk Bomgar offers a number of ways to integrate the Bomgar Box into your existing help desk infrastructure. [LDAP for Active Directory & Universal Direct...




Search This Site:










"the operation could not be completed" using the open command in the command window

updating database

runs slow the first time

using hidden fields

search engine optimization

querystring alternative and encrypting the querystring value

visual web developer 2005 locking up on exit.

hi all - newbie with a query...

programatically identifying themes in the app_themes directory

save remote image

file download counter

migration strategies for dnn

getchildcontroltype method

treeview - onselectednodechanged

gallery: popup image size

capturing the selected item in a list box

variable scope?

no new item templates, no command window

gallerypa_3[1].0.10.zip

help c# snippet. causing a global error.

renaming web part verbs

urgent:i need to prove dnn works for a client.i get a blank no error messages after login with admin or host

dotnetnuke.com registration problem

how to download critical updates without installing immediately?

side comment bar

pageindex in url

'hasrows' is not a member of 'system.data.idatareader'

javascript with masterpage - keystroke listener

arraylist help -using select case

how to test a windows authenticated website for load testing?

 
All Times Are GMT