Added password token to use inplace of plain-text password for totp
This commit is contained in:
1 parent
55d614fce8
commit
b9d0f64f74
11 files changed
+265
-21
No files matched your search
@@ -265,29 +265,37 @@ public class AuthenticationManager {
|
||||
|
||||
if (types.contains(CredentialRepresentation.PASSWORD)) {
|
||||
List<UserCredentialModel> credentials = new LinkedList<UserCredentialModel>();
|
||||
|
||||
String password = formData.getFirst(CredentialRepresentation.PASSWORD);
|
||||
if (password == null) {
|
||||
if (password != null) {
|
||||
credentials.add(UserCredentialModel.password(password));
|
||||
}
|
||||
|
||||
String passwordToken = formData.getFirst(CredentialRepresentation.PASSWORD_TOKEN);
|
||||
if (passwordToken != null) {
|
||||
credentials.add(UserCredentialModel.passwordToken(passwordToken));
|
||||
}
|
||||
|
||||
String totp = formData.getFirst(CredentialRepresentation.TOTP);
|
||||
if (totp != null) {
|
||||
credentials.add(UserCredentialModel.totp(totp));
|
||||
}
|
||||
|
||||
if (password == null && passwordToken == null) {
|
||||
logger.debug("Password not provided");
|
||||
return AuthenticationStatus.MISSING_PASSWORD;
|
||||
}
|
||||
credentials.add(UserCredentialModel.password(password));
|
||||
|
||||
if (user.isTotp()) {
|
||||
String token = formData.getFirst(CredentialRepresentation.TOTP);
|
||||
if (token == null) {
|
||||
logger.debug("TOTP token not provided");
|
||||
return AuthenticationStatus.MISSING_TOTP;
|
||||
}
|
||||
credentials.add(UserCredentialModel.totp(token));
|
||||
|
||||
}
|
||||
|
||||
logger.debug("validating password for user: " + username);
|
||||
logger.debugv("validating password for user: {0}", username);
|
||||
|
||||
if (!session.users().validCredentials(realm, user, credentials)) {
|
||||
return AuthenticationStatus.INVALID_CREDENTIALS;
|
||||
}
|
||||
|
||||
if (user.isTotp() && totp == null) {
|
||||
return AuthenticationStatus.MISSING_TOTP;
|
||||
}
|
||||
|
||||
if (!user.getRequiredActions().isEmpty()) {
|
||||
return AuthenticationStatus.ACTIONS_REQUIRED;
|
||||
} else {
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.keycloak.events.EventBuilder;
|
||||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.jose.jws.JWSBuilder;
|
||||
import org.keycloak.login.LoginFormsProvider;
|
||||
import org.keycloak.models.ApplicationModel;
|
||||
import org.keycloak.models.ClientModel;
|
||||
@@ -38,6 +39,7 @@ import org.keycloak.services.ForbiddenException;
|
||||
import org.keycloak.services.managers.AccessCode;
|
||||
import org.keycloak.services.managers.AuthenticationManager;
|
||||
import org.keycloak.services.managers.AuthenticationManager.AuthenticationStatus;
|
||||
import org.keycloak.representations.PasswordToken;
|
||||
import org.keycloak.services.managers.ResourceAdminManager;
|
||||
import org.keycloak.services.managers.TokenManager;
|
||||
import org.keycloak.services.messages.Messages;
|
||||
@@ -545,6 +547,11 @@ public class TokenService {
|
||||
event.error(Errors.USER_DISABLED);
|
||||
return Flows.forms(this.session, realm, client, uriInfo).setError(Messages.ACCOUNT_DISABLED).setFormData(formData).createLogin();
|
||||
case MISSING_TOTP:
|
||||
formData.remove(CredentialRepresentation.PASSWORD);
|
||||
|
||||
String passwordToken = new JWSBuilder().jsonContent(new PasswordToken(realm.getName(), user.getId())).rsa256(realm.getPrivateKey());
|
||||
formData.add(CredentialRepresentation.PASSWORD_TOKEN, passwordToken);
|
||||
|
||||
return Flows.forms(this.session, realm, client, uriInfo).setFormData(formData).createLoginTotp();
|
||||
case INVALID_USER:
|
||||
event.error(Errors.USER_NOT_FOUND);
|
||||
|
||||
Reference in new issue
Block a user