[Minor] logging of authentication attempts

This commit is contained in:
eitch 2011-07-29 00:30:08 +00:00
parent d2dff36b4b
commit 7e82285306
1 changed files with 53 additions and 44 deletions

View File

@ -608,6 +608,9 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
@Override
public Certificate authenticate(String username, String password) {
// create certificate
Certificate certificate;
try {
// both username and password must at least have 3 characters in length
if (username == null || username.length() < 3)
throw new PrivilegeException("The given username is shorter than 3 characters");
@ -621,7 +624,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
User user = this.persistenceHandler.getUser(username);
// no user means no authentication
if (user == null)
throw new AccessDeniedException("There is no user defined with the credentials: " + username + " / ***...");
throw new AccessDeniedException("There is no user defined with the credentials: " + username
+ " / ***...");
// validate password
String pwHash = user.getPassword();
@ -632,7 +636,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
// validate if user is allowed to login
if (user.getUserState() != UserState.ENABLED)
throw new AccessDeniedException("User " + username + " is not ENABLED. State is: " + user.getUserState());
throw new AccessDeniedException("User " + username + " is not ENABLED. State is: "
+ user.getUserState());
// validate user has at least one role
if (user.getRoles().isEmpty()) {
@ -646,15 +651,19 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
// get next session id
String sessionId = nextSessionId();
// create certificate
Certificate certificate = new Certificate(sessionId, username, authToken, authPassword, user.getLocale());
certificate = new Certificate(sessionId, username, authToken, authPassword, user.getLocale());
// create and save a new session
Session session = new Session(sessionId, username, authToken, authPassword, System.currentTimeMillis());
this.sessionMap.put(sessionId, new CertificateSessionPair(session, certificate));
// log
logger.info("Authenticated: " + session);
logger.info("User " + username + " authenticated: " + session);
} catch (RuntimeException e) {
logger.error("User " + username + " Failed to authenticate: " + e.getLocalizedMessage());
throw e;
}
// return the certificate
return certificate;