Merge pull request #3592 from sldab/default-hooks

KEYCLOAK-4074 Decoupling of default provider implementations
This commit is contained in:
Bill Burke 2016-12-16 08:42:55 -05:00 committed by GitHub
commit a4cbf130b4
4 changed files with 23 additions and 9 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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();
@ -137,6 +137,10 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider {
}
}
protected String retrieveEmailAddress(UserModel user) {
return user.getEmail();
}
private void setupTruststore(Properties props) throws NoSuchAlgorithmException, KeyManagementException {
JSSETruststoreConfigurator configurator = new JSSETruststoreConfigurator(session);