|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.owasp.esapi.reference.AbstractAuthenticator
org.owasp.esapi.reference.FileBasedAuthenticator
public class FileBasedAuthenticator
Reference implementation of the Authenticator 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 Authenticator 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 id | account name | hashed password | roles | lockout | status | old password hashes | last hostname | last change | last login | last failed | expiration | failed --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1203123710837 | mitch | 44k/NAzQUlrCq9musTGGkcMNmdzEGJ8w8qZTLzpxLuQ= | admin,user | unlocked | enabled | u10dW4vTo3ZkoM5xP+blayWCz7KdPKyKUojOn9GJobg= | 192.168.1.255 | 1187201000926 | 1187200991568 | 1187200605330 | 2187200605330 | 1
Authenticator
Field Summary |
---|
Fields inherited from class org.owasp.esapi.reference.AbstractAuthenticator |
---|
USER |
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. |
User |
createUser(java.lang.String accountName,
java.lang.String password1,
java.lang.String password2)
Creates a new User with the information provided. |
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. |
static Authenticator |
getInstance()
|
User |
getUser(long accountId)
Returns the User matching the provided accountId. |
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. |
protected void |
loadUsersIfNecessary()
Load users if they haven't been loaded in a while. |
protected void |
loadUsersImmediately()
|
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 of the specified accountName. |
void |
saveUsers()
Saves the user database to the file system. |
protected void |
saveUsers(java.io.PrintWriter writer)
Save users. |
void |
verifyAccountNameStrength(java.lang.String newAccountName)
Ensures that the account name passes site-specific complexity requirements, like minimum length. |
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,
User user)
Ensures that the password meets site-specific complexity requirements, like length or number of character sets. |
Methods inherited from class org.owasp.esapi.reference.AbstractAuthenticator |
---|
clearCurrent, exists, getCurrentUser, getUserFromRememberToken, getUserFromSession, login, login, logout, setCurrentUser |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Authenticator getInstance()
public static void main(java.lang.String[] args) throws java.lang.Exception
java -Dorg.owasp.esapi.resources="/path/resources" -classpath esapi.jar org.owasp.esapi.Authenticator alice password admin
args
- the arguments (username, password, role)
java.lang.Exception
- the exceptionpublic User createUser(java.lang.String accountName, java.lang.String password1, java.lang.String password2) throws AuthenticationException
accountName
- the account name of the new userpassword1
- the password of the new userpassword2
- the password of the new user. This field is to encourage user interface designers to include two password fields in their forms.
AuthenticationException
- if user creation fails due to any of the qualifications listed in this method's descriptionpublic java.lang.String generateStrongPassword()
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 boolean verifyPassword(User user, java.lang.String password)
user
- the user who requires verificationpassword
- the hashed user-supplied password
public java.lang.String generateStrongPassword(User user, java.lang.String oldPassword)
user
- the user whose information to use when generating passwordoldPassword
- the old password to use when verifying strength of new password. The new password may be checked for fragments of oldPassword.
public User getUser(long accountId)
accountId
- the account id
public User getUser(java.lang.String accountName)
accountName
- the account name
public java.util.Set getUserNames()
public java.lang.String hashPassword(java.lang.String password, java.lang.String accountName) throws EncryptionException
password
- the password to hashaccountName
- the account name to use as the salt
EncryptionException
protected void loadUsersIfNecessary()
protected void loadUsersImmediately()
public void removeUser(java.lang.String accountName) throws AuthenticationException
accountName
- the account name to remove
AuthenticationException
- the authentication exception if user does not existpublic void saveUsers() throws AuthenticationException
AuthenticationException
- if the user file could not be writtenprotected void saveUsers(java.io.PrintWriter writer) throws AuthenticationCredentialsException
writer
- the print writer to use for saving
AuthenticationCredentialsException
public void verifyAccountNameStrength(java.lang.String newAccountName) throws AuthenticationException
newAccountName
-
AuthenticationException
- if account name does not meet complexity requirementspublic void verifyPasswordStrength(java.lang.String oldPassword, java.lang.String newPassword, User user) throws AuthenticationException
oldPassword
- the old passwordnewPassword
- the new passworduser
- the user
AuthenticationException
- if newPassword is too similar to oldPassword or if newPassword does not meet complexity requirements
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |