diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateOTP.java b/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateOTP.java index a9ea094626..69968ccb31 100755 --- a/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateOTP.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateOTP.java @@ -53,9 +53,7 @@ public class ValidateOTP extends AbstractDirectGrantAuthenticator { } return; } - MultivaluedMap inputData = context.getHttpRequest().getDecodedFormParameters(); - List credentials = new LinkedList<>(); - String otp = inputData.getFirst(CredentialRepresentation.TOTP); + String otp = retrieveOTP(context); if (otp == null) { if (context.getUser() != null) { context.getEvent().user(context.getUser()); @@ -142,4 +140,9 @@ public class ValidateOTP extends AbstractDirectGrantAuthenticator { public String getId() { return PROVIDER_ID; } + + protected String retrieveOTP(AuthenticationFlowContext context) { + MultivaluedMap inputData = context.getHttpRequest().getDecodedFormParameters(); + return inputData.getFirst(CredentialRepresentation.TOTP); + } } diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidatePassword.java b/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidatePassword.java index 0de3b2a6fa..b992225013 100755 --- a/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidatePassword.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidatePassword.java @@ -43,9 +43,7 @@ public class ValidatePassword extends AbstractDirectGrantAuthenticator { @Override public void authenticate(AuthenticationFlowContext context) { - MultivaluedMap inputData = context.getHttpRequest().getDecodedFormParameters(); - List credentials = new LinkedList<>(); - String password = inputData.getFirst(CredentialRepresentation.PASSWORD); + String password = retrievePassword(context); boolean valid = context.getSession().userCredentialManager().isValid(context.getRealm(), context.getUser(), UserCredentialModel.password(password)); if (!valid) { context.getEvent().user(context.getUser()); @@ -118,4 +116,9 @@ public class ValidatePassword extends AbstractDirectGrantAuthenticator { public String getId() { return PROVIDER_ID; } + + protected String retrievePassword(AuthenticationFlowContext context) { + MultivaluedMap inputData = context.getHttpRequest().getDecodedFormParameters(); + return inputData.getFirst(CredentialRepresentation.PASSWORD); + } } diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateUsername.java b/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateUsername.java index d9e8c4b2f0..da7a67f1f7 100755 --- a/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateUsername.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/directgrant/ValidateUsername.java @@ -47,8 +47,7 @@ public class ValidateUsername extends AbstractDirectGrantAuthenticator { @Override public void authenticate(AuthenticationFlowContext context) { - MultivaluedMap inputData = context.getHttpRequest().getDecodedFormParameters(); - String username = inputData.getFirst(AuthenticationManager.FORM_USERNAME); + String username = retrieveUsername(context); if (username == null) { context.getEvent().error(Errors.USER_NOT_FOUND); Response challengeResponse = errorResponse(Response.Status.UNAUTHORIZED.getStatusCode(), "invalid_request", "Missing parameter: username"); @@ -154,4 +153,9 @@ public class ValidateUsername extends AbstractDirectGrantAuthenticator { public String getId() { return PROVIDER_ID; } + + protected String retrieveUsername(AuthenticationFlowContext context) { + MultivaluedMap inputData = context.getHttpRequest().getDecodedFormParameters(); + return inputData.getFirst(AuthenticationManager.FORM_USERNAME); + } } diff --git a/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java b/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java index 235f123445..311627a6bf 100644 --- a/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java +++ b/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java @@ -57,7 +57,7 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider { public void send(RealmModel realm, UserModel user, String subject, String textBody, String htmlBody) throws EmailException { Transport transport = null; try { - String address = user.getEmail(); + String address = retrieveEmailAddress(user); Map config = realm.getSmtpConfig(); Properties props = new Properties(); @@ -136,6 +136,10 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider { } } } + + protected String retrieveEmailAddress(UserModel user) { + return user.getEmail(); + } private void setupTruststore(Properties props) throws NoSuchAlgorithmException, KeyManagementException {