|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.owasp.esapi.Authenticator
Reference implementation of the IAuthenticator interface. This reference implementation is backed by a simple text file that contains serialized information about users. Many organizations will want to create their own implementation of the methods provided in the IAuthenticator interface backed by their own user repository. This reference implementation captures information about users in a simple text file format that contains user information separated by the pipe "|" character. Here's an example of a single line from the users.txt file:
account name | hashed password | roles | lockout | status | remember token | old password hashes | last hostname | last change | last login | last failed | expiration | failed --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- mitch | 44k/NAzQUlrCq9musTGGkcMNmdzEGJ8w8qZTLzpxLuQ= | admin,user | unlocked | enabled | token | u10dW4vTo3ZkoM5xP+blayWCz7KdPKyKUojOn9GJobg= | 192.168.1.255 | 1187201000926 | 1187200991568 | 1187200605330 | 2187200605330 | 1
IAuthenticator| Constructor Summary | |
Authenticator()
|
|
| Method Summary | |
void |
clearCurrent()
Clears all threadlocal variables from the thread. |
IUser |
createUser(java.lang.String accountName,
java.lang.String password1,
java.lang.String password2)
Creates the user. |
boolean |
exists(java.lang.String accountName)
Verifies the account exists. |
java.lang.String |
generateStrongPassword()
Generate a strong password. |
java.lang.String |
generateStrongPassword(java.lang.String oldPassword,
IUser user)
Generate strong password that takes into account the user's information and old password. |
IUser |
getCurrentUser()
Returns the currently logged in User. |
IUser |
getUser(java.lang.String accountName)
Gets the user object with the matching account name or null if there is no match. |
IUser |
getUserFromSession()
Gets the user from session. |
java.util.Set |
getUserNames()
Gets the user names. |
java.lang.String |
hashPassword(java.lang.String password,
java.lang.String accountName)
Returns a string representation of the hashed password, using the accountName as the salt. |
IUser |
login(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This method should be called for every HTTP request, to login the current user either from the session of HTTP request. |
void |
logout()
Log out the current user. |
static void |
main(java.lang.String[] args)
Fail safe main program to add or update an account in an emergency. |
void |
removeUser(java.lang.String accountName)
Removes the account. |
void |
setCurrentUser(IUser user)
Sets the currently logged in User. |
void |
verifyAccountNameStrength(java.lang.String newAccountName)
Validate password strength. |
void |
verifyPasswordStrength(java.lang.String newPassword,
java.lang.String oldPassword)
Validate password strength. |
boolean |
verifyRememberToken()
Verifies the current User's remember cookie from the current request. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Authenticator()
| Method Detail |
public static void main(java.lang.String[] args)
throws java.lang.Exception
Warning: this method does not perform the level of validation and checks generally required in ESAPI, and can therefore be used to create a username and password that do not comply with the username and password strength requirements.
Example: Use this to add the alice account with the admin role to the users file:
java -Dorg.owasp.esapi.resources="/path/resources" -classpath esapi.jar org.owasp.esapi.Authenticator alice password admin
args - the args
AuthenticationException - the authentication exception
java.lang.Exceptionpublic void clearCurrent()
clearCurrent in interface IAuthenticator
public IUser createUser(java.lang.String accountName,
java.lang.String password1,
java.lang.String password2)
throws AuthenticationException
IAuthenticator
createUser in interface IAuthenticatoraccountName - the account namepassword1 - the passwordpassword2 - copy of the password
AuthenticationException - the authentication exceptionpublic boolean exists(java.lang.String accountName)
IAuthenticator
exists in interface IAuthenticatoraccountName - the account name
public java.lang.String generateStrongPassword()
IAuthenticator
generateStrongPassword in interface IAuthenticator
public java.lang.String generateStrongPassword(java.lang.String oldPassword,
IUser user)
IAuthenticator
generateStrongPassword in interface IAuthenticatoroldPassword - the old passworduser - the user
public IUser getCurrentUser()
IAuthenticator
getCurrentUser in interface IAuthenticatorpublic IUser getUser(java.lang.String accountName)
getUser in interface IAuthenticatoraccountName - the account name
public IUser getUserFromSession()
public boolean verifyRememberToken()
public java.util.Set getUserNames()
getUserNames in interface IAuthenticator
public java.lang.String hashPassword(java.lang.String password,
java.lang.String accountName)
throws EncryptionException
IAuthenticator
hashPassword in interface IAuthenticatorpassword - the passwordaccountName - the account name
EncryptionException
public void removeUser(java.lang.String accountName)
throws AuthenticationException
IAuthenticator
removeUser in interface IAuthenticatoraccountName - the account name
AuthenticationException - the authentication exception
public IUser login(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws AuthenticationException
login in interface IAuthenticatorrequest - the requestresponse - the response
AuthenticationException - the authentication exceptionpublic void logout()
logout in interface IAuthenticatorpublic void setCurrentUser(IUser user)
IAuthenticator
setCurrentUser in interface IAuthenticatoruser - the current user
public void verifyAccountNameStrength(java.lang.String newAccountName)
throws AuthenticationException
IAuthenticator
verifyAccountNameStrength in interface IAuthenticatornewAccountName - the account name
AuthenticationException - the authentication exception
public void verifyPasswordStrength(java.lang.String newPassword,
java.lang.String oldPassword)
throws AuthenticationException
IAuthenticator
verifyPasswordStrength in interface IAuthenticatornewPassword - the new passwordoldPassword - the old password
AuthenticationException - the authentication exception
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||