|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.codepin.ldaphack.ldapauth
public class ldapauth
Simple implementation of an authorization mechanism for ldap. The intention of this class is to be used in hacking LDAP authentication into a third-party software application.
Example code to illustrate:
// code before integrating hack:
if (isAuthenticatedUser(username,password) {
userObject = getUserObject(username);
System.out.println("You are authorized");
} else {
System.out.println("You are not authorized!");
System.exit(1);
}
// code after integrating hack (assumes you created properties file, see ldapauth(String)):
ldapauth la = new ldapauth();
String userDN = la.searchfordn(username);
if (userDN != null) {
// authenticate via LDAP if found in LDAP
if (la.bindauthdn(userDN,password) {
userObject = getUserObject(username);
System.out.println("You are authorized via LDAP");
} else {
System.out.println("You are not authorized via LDAP");
System.exit(1);
}
} else if (isAuthenticatedUser(username,password) {
// else authenticate via the application if not found in LDAP
userObject = getUserObject(username);
System.out.println("You are authorized");
} else {
System.out.println("You are not authorized!");
System.exit(1);
}
| Constructor Summary | |
|---|---|
ldapauth()
Create an initialized instance of ldapauth using object's default property file. |
|
ldapauth(java.lang.String propertiesFile)
Create an initialized instance of ldapauth with given property file. |
|
| Method Summary | |
|---|---|
boolean |
bindauthdn(java.lang.String userDN)
Attempt to authenticate a user from a provided user DN and the password set in the object which by default the password is an empty string. |
boolean |
bindauthdn(java.lang.String userDN,
java.lang.String password)
Attempt to authenticate a user from a provided user DN and password |
boolean |
bindauthusername()
Attempt to authenticate a user from the username and password set in the object. |
boolean |
bindauthusername(java.lang.String username)
Attempt to authenticate a user from a provided username and the password set in the object which by default the password is an empty string. |
boolean |
bindauthusername(java.lang.String username,
java.lang.String password)
Attempt to authenticate a user from a provided username and password. |
boolean |
getAllowEmptyPassword()
Get the value of allowing empty passwords during authentication. |
java.lang.String |
getAuthAttribute()
Get the attribute set to uniquely identify the user in LDAP for authentication purposes. |
java.lang.String |
getBaseDN()
Get the Base DN set to confine the connection or search within the LDAP server. |
java.lang.String |
getBindDN()
Get the Manager DN set to bind to LDAP for searching purposes |
java.lang.String |
getBindPassword()
Get the password set for the Manager DN |
java.lang.String |
getCompletedSearchFilter()
Get the search filter resulting from substituting the username into it. |
java.lang.String |
getCompletedSearchFilter(java.lang.String username)
Get the search filter resulting from substituting the username into it. |
java.lang.String |
getCompletedSearchFilter(java.lang.String searchFilter,
java.lang.String username)
Get the search filter resulting from substituting the username into it. |
java.lang.String |
getPassword()
Get the password set to authorize the username with |
java.util.Properties |
getProperties()
Get the Properties object of this object |
java.lang.String |
getPropertyFile()
Get the Property File set for this object |
java.lang.String |
getProviderUrl()
Get the LDAP URL to be used for connecting to the LDAP server. |
java.lang.String |
getSearchFilter()
Get the search filter set to be use when searching for authorized accounts within LDAP. |
java.lang.String |
getUsername()
Get the username set to authorize |
void |
reloadProperties()
Reload the Properties into this object from the properties file. |
java.lang.String |
searchfordn()
Search for the userDN using the searchFilter and username set in this object. |
java.lang.String |
searchfordn(java.lang.String username)
Search for the userDN using the provided username and the searchFilter set in this object. |
java.lang.String |
searchfordn(java.lang.String searchFilter,
java.lang.String username)
Search for the userDN using the provided searchFilter and username. |
void |
setAllowEmptyPassword(boolean allowEmptyPassword)
Set true to allow empty password to be used with username authentication, or false to disallow empty passwords to be used in attempting authentication. If an empty password is provided, some LDAP servers will successfully bind the user as anonymous. |
void |
setAuthAttribute(java.lang.String ldapAuthAttribute)
Set the attribute used to uniquely identify the user in LDAP for authentication purposes. |
void |
setBaseDN(java.lang.String BaseDN)
Set the Base DN you want to confine your connection or search to within the LDAP server. |
void |
setBindDN(java.lang.String ManagerBindDN)
Set the Manager DN to bind to LDAP for searching purposes. |
void |
setBindPassword(java.lang.String ManagerBindPassword)
Set the password of the Manager DN |
void |
setPassword(java.lang.String userPassword)
Set the password to authorize the username with |
void |
setProperties(java.util.Properties properties)
Set the Properties object of this object |
void |
setPropertyFile(java.lang.String propertiesFile)
Set the Property File for this object. |
void |
setProviderUrl(java.lang.String providerUrl)
Set the LDAP URL to be used for connecting to the LDAP server. |
void |
setSearchFilter(java.lang.String searchFilter)
Set the search filter you want to have used when searching for authorized accounts within LDAP. |
void |
setUsername(java.lang.String userName)
Set the username to authorize |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ldapauth(java.lang.String propertiesFile)
Create an initialized instance of ldapauth with given property file.
Upon creation the provided property file is read in and the obect is
set up with the values.
The Property File by default is attempted to be found in the classpath
as "ldaphack.ldapauth.properties" and is expected to be in XML format.
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="ProviderUrl">ldap://ldap.example.org:389</entry>
<entry key="SearchFilter">(&(uid={0})(objectClass=inetOrgPerson))</entry>
<entry key="BaseDN">dc=example,dc=org</entry>
<entry key="AllowEmptyPassword">false</entry>
<entry key="AuthAttribute">uid</entry>
<entry key="BindDN">uid=ldapreadonlyuser,ou=People,o=cait.org</entry>
<entry key="BindPassword">secret</entry>
<entry key="DEBUG">false</entry>
</properties>
Note that & must be escaped as
& in XML, or you'll get an error when loaded.
If you do not use a property file, an error will be send to System.err, but you can still use the object and use the setter methods to set your properties for the object.
propertiesFile - public ldapauth()
Create an initialized instance of ldapauth using object's default
property file.
Upon creation the property file is read in and the obect is
set up with the values.
The propertyFile by default is attempted to be found in the classpath
as "ldaphack.ldapauth.properties" and is expected to be in XML format.
Refer to ldapauth(String) for an example properties
file.
| Method Detail |
|---|
public void setPropertyFile(java.lang.String propertiesFile)
property key: PropertyFile
propertiesFile - public java.lang.String getPropertyFile()
property key: PropertyFile
public void setProperties(java.util.Properties properties)
properties - public java.util.Properties getProperties()
public void reloadProperties()
public void setUsername(java.lang.String userName)
userName - public java.lang.String getUsername()
public void setPassword(java.lang.String userPassword)
userPassword - public java.lang.String getPassword()
public void setBindDN(java.lang.String ManagerBindDN)
searchfordn(String,String)
and bindauthusername(String,String) functions.
property key: BindDN
ManagerBindDN - public java.lang.String getBindDN()
property key: BindDN
public void setBindPassword(java.lang.String ManagerBindPassword)
property key: BindPassword
ManagerBindPassword - public java.lang.String getBindPassword()
property key: BindPassword
public void setAuthAttribute(java.lang.String ldapAuthAttribute)
property key: AuthAttribute
ldapAuthAttribute - public java.lang.String getAuthAttribute()
property key: AuthAttribute
public void setAllowEmptyPassword(boolean allowEmptyPassword)
property key: AllowEmptyPassword
allowEmptyPassword - public boolean getAllowEmptyPassword()
property key: AllowEmptyPassword
public void setProviderUrl(java.lang.String providerUrl)
property key: ProviderUrl
providerUrl - public java.lang.String getProviderUrl()
property key: ProviderUrl
public void setBaseDN(java.lang.String BaseDN)
property key: BaseDN
BaseDN - public java.lang.String getBaseDN()
property key: BaseDN
public void setSearchFilter(java.lang.String searchFilter)
property key: SearchFilter
searchFilter - public java.lang.String getSearchFilter()
property key: SearchFilter
public java.lang.String getCompletedSearchFilter()
public java.lang.String getCompletedSearchFilter(java.lang.String username)
username -
public java.lang.String getCompletedSearchFilter(java.lang.String searchFilter,
java.lang.String username)
searchFilter - username - public boolean bindauthusername()
bindauthusername(String,String))
public boolean bindauthusername(java.lang.String username)
bindauthusername(String,String))
username -
public boolean bindauthusername(java.lang.String username,
java.lang.String password)
searchfordn(String)
to retrieve a DN for the user, then the result of the userDN and given
password being passed into bindauthdn(String,String)
is returned.
username - password - public boolean bindauthdn(java.lang.String userDN)
userDN -
public boolean bindauthdn(java.lang.String userDN,
java.lang.String password)
userDN - password - public java.lang.String searchfordn()
public java.lang.String searchfordn(java.lang.String username)
username -
public java.lang.String searchfordn(java.lang.String searchFilter,
java.lang.String username)
setBindDN(java.lang.String) and setBindPassword(java.lang.String) or
setting the equivelant property in the property file.
searchFilter - username -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||