[Minor] logging of authentication attempts
This commit is contained in:
parent
d2dff36b4b
commit
7e82285306
|
@ -608,6 +608,9 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
||||||
@Override
|
@Override
|
||||||
public Certificate authenticate(String username, String password) {
|
public Certificate authenticate(String username, String password) {
|
||||||
|
|
||||||
|
// create certificate
|
||||||
|
Certificate certificate;
|
||||||
|
try {
|
||||||
// both username and password must at least have 3 characters in length
|
// both username and password must at least have 3 characters in length
|
||||||
if (username == null || username.length() < 3)
|
if (username == null || username.length() < 3)
|
||||||
throw new PrivilegeException("The given username is shorter than 3 characters");
|
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);
|
User user = this.persistenceHandler.getUser(username);
|
||||||
// no user means no authentication
|
// no user means no authentication
|
||||||
if (user == null)
|
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
|
// validate password
|
||||||
String pwHash = user.getPassword();
|
String pwHash = user.getPassword();
|
||||||
|
@ -632,7 +636,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
||||||
|
|
||||||
// validate if user is allowed to login
|
// validate if user is allowed to login
|
||||||
if (user.getUserState() != UserState.ENABLED)
|
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
|
// validate user has at least one role
|
||||||
if (user.getRoles().isEmpty()) {
|
if (user.getRoles().isEmpty()) {
|
||||||
|
@ -646,15 +651,19 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
||||||
// get next session id
|
// get next session id
|
||||||
String sessionId = nextSessionId();
|
String sessionId = nextSessionId();
|
||||||
|
|
||||||
// create certificate
|
certificate = new Certificate(sessionId, username, authToken, authPassword, user.getLocale());
|
||||||
Certificate certificate = new Certificate(sessionId, username, authToken, authPassword, user.getLocale());
|
|
||||||
|
|
||||||
// create and save a new session
|
// create and save a new session
|
||||||
Session session = new Session(sessionId, username, authToken, authPassword, System.currentTimeMillis());
|
Session session = new Session(sessionId, username, authToken, authPassword, System.currentTimeMillis());
|
||||||
this.sessionMap.put(sessionId, new CertificateSessionPair(session, certificate));
|
this.sessionMap.put(sessionId, new CertificateSessionPair(session, certificate));
|
||||||
|
|
||||||
// log
|
// 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 the certificate
|
||||||
return certificate;
|
return certificate;
|
||||||
|
|
Loading…
Reference in New Issue