|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
The IAuthenticator 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 {
ESAPI.authenticator().authenticate(request, response, "username","password");
// continue with authenticated user
} catch (AuthenticationException e) {
// handle failed authentication (it's already been logged)
}
| Method Summary | |
void |
clearCurrent()
Clear the current user, request, and response. |
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)
Returns the User matching the provided accountName. |
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)
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(IUser user)
Sets the currently logged in User. |
void |
verifyAccountNameStrength(java.lang.String accountName)
Validate password strength. |
void |
verifyPasswordStrength(java.lang.String newPassword,
java.lang.String oldPassword)
Validate password strength. |
| Method Detail |
public void clearCurrent()
public IUser login(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws AuthenticationException
request - the current HTTP requestresponse - the response
AuthenticationException - the authentication exceptionpublic void logout()
public IUser 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 exceptionpublic java.lang.String generateStrongPassword()
public java.lang.String generateStrongPassword(java.lang.String oldPassword,
IUser user)
oldPassword - the old passworduser - the user
public IUser getUser(java.lang.String accountName)
accountName - the account name
public java.util.Set getUserNames()
public IUser getCurrentUser()
public void setCurrentUser(IUser 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 newPassword,
java.lang.String oldPassword)
throws AuthenticationException
newPassword - the new passwordoldPassword - the old 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 | ||||||||||