|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.owasp.esapi.reference.FileBasedAuthenticator
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
Authenticator| Constructor Summary | |
FileBasedAuthenticator()
|
|
| Method Summary | |
void |
changePassword(User user,
java.lang.String currentPassword,
java.lang.String newPassword,
java.lang.String newPassword2)
Changes the password for the specified user. |
void |
clearCurrent()
Clears all threadlocal variables from the thread. |
User |
createUser(java.lang.String accountName,
java.lang.String password1,
java.lang.String password2)
Creates the user. |
boolean |
exists(java.lang.String accountName)
Determine if the account already exists. |
java.lang.String |
generateStrongPassword()
Generate a strong password. |
java.lang.String |
generateStrongPassword(User user,
java.lang.String oldPassword)
Generate strong password that takes into account the user's information and old password. |
User |
getCurrentUser()
Returns the currently logged in User. |
User |
getUser(java.lang.String accountName)
Gets the user object with the matching account name or null if there is no match. |
User |
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. |
User |
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(User user)
Sets the currently logged in User. |
void |
verifyAccountNameStrength(java.lang.String newAccountName)
Ensures that the account name passes site-specific complexity requirements. |
boolean |
verifyPassword(User user,
java.lang.String password)
Verify that the supplied password matches the password for this user. |
void |
verifyPasswordStrength(java.lang.String oldPassword,
java.lang.String newPassword)
Ensures that the password meets site-specific complexity requirements. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public FileBasedAuthenticator()
| 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 Authenticator
public User createUser(java.lang.String accountName,
java.lang.String password1,
java.lang.String password2)
throws AuthenticationException
Authenticator
createUser in interface AuthenticatoraccountName - the account namepassword1 - the passwordpassword2 - copy of the password
AuthenticationException - the authentication exception
FIXME RD: We should throw a specific exception if the account name already exists
Also, should callers synchronize while checking exists() and calling createUser()?public boolean exists(java.lang.String accountName)
Authenticator
exists in interface AuthenticatoraccountName - the account name
public java.lang.String generateStrongPassword()
Authenticator
generateStrongPassword in interface Authenticator
public void changePassword(User user,
java.lang.String currentPassword,
java.lang.String newPassword,
java.lang.String newPassword2)
throws AuthenticationException
Authenticator
changePassword in interface Authenticatoruser - the user to change the password forcurrentPassword - the current password for the specified usernewPassword - the new password to usenewPassword2 - a verification copy of the new password
AuthenticationException - if any errors occur
public boolean verifyPassword(User user,
java.lang.String password)
Authenticator
verifyPassword in interface Authenticatoruser - the userpassword - the password
public java.lang.String generateStrongPassword(User user,
java.lang.String oldPassword)
Authenticator
generateStrongPassword in interface AuthenticatoroldPassword - the old passworduser - the user
public User getCurrentUser()
Authenticator
getCurrentUser in interface Authenticatorpublic User getUser(java.lang.String accountName)
getUser in interface AuthenticatoraccountName - the account name
public User getUserFromSession()
public java.util.Set getUserNames()
getUserNames in interface Authenticator
public java.lang.String hashPassword(java.lang.String password,
java.lang.String accountName)
throws EncryptionException
Authenticator
hashPassword in interface Authenticatorpassword - the passwordaccountName - the account name
EncryptionException
public void removeUser(java.lang.String accountName)
throws AuthenticationException
Authenticator
removeUser in interface AuthenticatoraccountName - the account name
AuthenticationException - the authentication exception
public User login(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws AuthenticationException
login in interface Authenticatorrequest - the requestresponse - the response
AuthenticationException - the authentication exceptionpublic void logout()
logout in interface Authenticatorpublic void setCurrentUser(User user)
Authenticator
setCurrentUser in interface Authenticatoruser - the current user
public void verifyAccountNameStrength(java.lang.String newAccountName)
throws AuthenticationException
Authenticator
verifyAccountNameStrength in interface AuthenticatornewAccountName - the account name
AuthenticationException - the authentication exception
public void verifyPasswordStrength(java.lang.String oldPassword,
java.lang.String newPassword)
throws AuthenticationException
Authenticator
verifyPasswordStrength in interface AuthenticatoroldPassword - the old passwordnewPassword - the new password
AuthenticationException - the authentication exception
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||