Merge pull request #3592 from sldab/default-hooks
KEYCLOAK-4074 Decoupling of default provider implementations
This commit is contained in:
commit
a4cbf130b4
4 changed files with 23 additions and 9 deletions
|
@ -53,9 +53,7 @@ public class ValidateOTP extends AbstractDirectGrantAuthenticator {
|
|||
}
|
||||
return;
|
||||
}
|
||||
MultivaluedMap<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
||||
List<UserCredentialModel> 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<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
||||
return inputData.getFirst(CredentialRepresentation.TOTP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,9 +43,7 @@ public class ValidatePassword extends AbstractDirectGrantAuthenticator {
|
|||
|
||||
@Override
|
||||
public void authenticate(AuthenticationFlowContext context) {
|
||||
MultivaluedMap<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
||||
List<UserCredentialModel> 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<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
||||
return inputData.getFirst(CredentialRepresentation.PASSWORD);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,7 @@ public class ValidateUsername extends AbstractDirectGrantAuthenticator {
|
|||
|
||||
@Override
|
||||
public void authenticate(AuthenticationFlowContext context) {
|
||||
MultivaluedMap<String, String> 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<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
||||
return inputData.getFirst(AuthenticationManager.FORM_USERNAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, String> 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 {
|
||||
|
||||
|
|
Loading…
Reference in a new issue