I would like to show a different status message, when a suspended user tries to login. If the user is active we return true from the authenticate method, if not we add a custom StatusMessage message mentioning that the "User X has been suspended". The underlying Identity authentication also fails and adds a StatusMessage. I tried removing the seam generated statusMessage with the following methods, but it doesn't seem to work and shows me 2 different status messages (my custom message, seam generated). What would be the issue here?
StatusMessages statusMessages;
statusMessages.clear()
statusMessages.clearGlobalMessages()
statusMessages.clearKeyedMessages(id)
EDIT1:
public boolean authenticate() {
log.info("Authenticating {0}", identity.getCredentials().getUsername());
String username = identity.getCredentials().getUsername();
String password = identity.getCredentials().getPassword();
// return true if the authentication was
// successful, false otherwise
try {
Query query = entityManager.createNamedQuery("user.by.login.id");
query.setParameter("loginId", username);
// only active users can log in
query.setParameter("status", "ACTIVE");
currentUser = (User)query.getSingleResult();
} catch (PersistenceException ignore) {
// Provide a status message for the locked account
statusMessages.clearGlobalMessages();
statusMessages.addFromResourceBundle(
"login.account.locked", new Object[] { username });
return false;
}
IdentityManager identityManager = IdentityManager.instance();
if (!identityManager.authenticate(username, "password")) {
return false;
} else {
log.info("Authenticated user {0} successfully", username);
}
}