Enterprise Library LDAP/AD Authentication

  • Thread starter Thread starter wooboo
  • Start date Start date
W

wooboo

Has anyone seen how to authenticate user by LDAP in Enterprise Library?
It seems to be simple. A new classes like this:
public class ADAuthenticationProvider : ConfigurationProvider,
IAuthenticationProvider{
public bool Authenticate(object credentials, out IIdentity
userIdentity)
{ bool result = false;
userIdentity = null;
NamePasswordCredential namePasswordCredentials =
credentials as NamePasswordCredential;
if (namePasswordCredentials != null &&
namePasswordCredentials.Name.Length > 0){

SecurityAuthenticationCheckEvent.Fire(namePasswordCredentials.Name);
try{ DirectoryEntry entry = new DirectoryEntry
adAuthenticationProviderData.DomainPath,userName,password.ToString(),AuthenticationTypes.ServerBind);
result = true;
}catch(Exception){
result = fasle;
}
if (result){
userIdentity = new
GenericIdentity(namePasswordCredentials.Name, GetAuthenticationType());
}else{

SecurityAuthenticationFailedEvent.Fire(namePasswordCredentials.Name);
}
}
return result;
}
}

[XmlRoot("authenticationProvider",
Namespace=SecuritySettings.ConfigurationNamespace)]
public class ADAuthenticationProviderData :
AuthenticationProviderData
{
private string strDomainPath;
public ADAuthenticationProviderData() : this(string.Empty,
string.Empty){}
public ADAuthenticationProviderData(string name) : this(name,
string.Empty){}
public ADAuthenticationProviderData(string name, string
domainPath) : base(name){
this.strDomainPath = domainPath;
}
[XmlAttribute("domainPath")]
public string DomainPath
{ get { return this.strDomainPath; }
set { this.strDomainPath = value; } }
[XmlIgnore]
public override string TypeName
{ get { return
typeof(ADAuthenticationProvider).AssemblyQualifiedName; }
set { }
}
}
But I don't know what next...
Has anyone seen that kind of authenticationProvider already done? Or
some examples how to create custom authentication providers.
It's too simple to be the first doing this... or i'm wrong...
 
Back
Top