|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
The Authenticator interface defines a set of methods for generating and handling account credentials and session identifiers. The goal of this interface is to encourage developers to protect credentials from disclosure to the maximum extent possible.
Once possible implementation relies on the use of a thread local variable to store the current user's identity. The application is responsible for calling setCurrentUser() as soon as possible after each HTTP request is received. The value of getCurrentUser() is used in several other places in this API. This eliminates the need to pass a user object to methods throughout the library. For example, all of the logging, access control, and exception calls need access to the currently logged in user.
The goal is to minimize the responsibility of the developer for authentication. In this example, the user simply calls authenticate with the current request and the name of the parameters containing the username and password. The implementation should verify the password if necessary, create a session if necessary, and set the user as the current user.
public void doPost(ServletRequest request, ServletResponse response) {
try {
User user = ESAPI.authenticator().login(request, response);
// continue with authenticated user
} catch (AuthenticationException e) {
// handle failed authentication (it's already been logged)
}
| 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()
Clear the current user. |
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)
Returns the User matching the provided accountName. |
java.util.Set |
getUserNames()
Gets a collection containing all the existing 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)
Authenticates the user's credentials from the HttpServletRequest if necessary, creates a session if necessary, and sets the user as the current user. |
void |
logout()
Logs out the current user. |
void |
removeUser(java.lang.String accountName)
Removes the account. |
void |
setCurrentUser(User user)
Sets the currently logged in User. |
void |
verifyAccountNameStrength(java.lang.String accountName)
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. |
| Method Detail |
public void clearCurrent()
public User login(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws AuthenticationException
request - the current HTTP requestresponse - the response
AuthenticationException - the authentication exception
public boolean verifyPassword(User user,
java.lang.String password)
user - the userpassword - the password
public void logout()
public User createUser(java.lang.String accountName,
java.lang.String password1,
java.lang.String password2)
throws AuthenticationException
accountName - 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 java.lang.String generateStrongPassword()
public java.lang.String generateStrongPassword(User user,
java.lang.String oldPassword)
oldPassword - the old passworduser - the user
public void changePassword(User user,
java.lang.String currentPassword,
java.lang.String newPassword,
java.lang.String newPassword2)
throws AuthenticationException
user - 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 occurpublic User getUser(java.lang.String accountName)
accountName - the account name
public java.util.Set getUserNames()
public User getCurrentUser()
public void setCurrentUser(User user)
user - the current user
public java.lang.String hashPassword(java.lang.String password,
java.lang.String accountName)
throws EncryptionException
password - the passwordaccountName - the account name
EncryptionException
public void removeUser(java.lang.String accountName)
throws AuthenticationException
accountName - the account name
AuthenticationException - the authentication exception
public void verifyAccountNameStrength(java.lang.String accountName)
throws AuthenticationException
accountName - the account name
AuthenticationException - the authentication exception
public void verifyPasswordStrength(java.lang.String oldPassword,
java.lang.String newPassword)
throws AuthenticationException
oldPassword - the old passwordnewPassword - the new password
AuthenticationException - the authentication exceptionpublic boolean exists(java.lang.String accountName)
accountName - the account name
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||