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;
|
return;
|
||||||
}
|
}
|
||||||
MultivaluedMap<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
String otp = retrieveOTP(context);
|
||||||
List<UserCredentialModel> credentials = new LinkedList<>();
|
|
||||||
String otp = inputData.getFirst(CredentialRepresentation.TOTP);
|
|
||||||
if (otp == null) {
|
if (otp == null) {
|
||||||
if (context.getUser() != null) {
|
if (context.getUser() != null) {
|
||||||
context.getEvent().user(context.getUser());
|
context.getEvent().user(context.getUser());
|
||||||
|
@ -142,4 +140,9 @@ public class ValidateOTP extends AbstractDirectGrantAuthenticator {
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return PROVIDER_ID;
|
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
|
@Override
|
||||||
public void authenticate(AuthenticationFlowContext context) {
|
public void authenticate(AuthenticationFlowContext context) {
|
||||||
MultivaluedMap<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
String password = retrievePassword(context);
|
||||||
List<UserCredentialModel> credentials = new LinkedList<>();
|
|
||||||
String password = inputData.getFirst(CredentialRepresentation.PASSWORD);
|
|
||||||
boolean valid = context.getSession().userCredentialManager().isValid(context.getRealm(), context.getUser(), UserCredentialModel.password(password));
|
boolean valid = context.getSession().userCredentialManager().isValid(context.getRealm(), context.getUser(), UserCredentialModel.password(password));
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
context.getEvent().user(context.getUser());
|
context.getEvent().user(context.getUser());
|
||||||
|
@ -118,4 +116,9 @@ public class ValidatePassword extends AbstractDirectGrantAuthenticator {
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return PROVIDER_ID;
|
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
|
@Override
|
||||||
public void authenticate(AuthenticationFlowContext context) {
|
public void authenticate(AuthenticationFlowContext context) {
|
||||||
MultivaluedMap<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
|
String username = retrieveUsername(context);
|
||||||
String username = inputData.getFirst(AuthenticationManager.FORM_USERNAME);
|
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
context.getEvent().error(Errors.USER_NOT_FOUND);
|
context.getEvent().error(Errors.USER_NOT_FOUND);
|
||||||
Response challengeResponse = errorResponse(Response.Status.UNAUTHORIZED.getStatusCode(), "invalid_request", "Missing parameter: username");
|
Response challengeResponse = errorResponse(Response.Status.UNAUTHORIZED.getStatusCode(), "invalid_request", "Missing parameter: username");
|
||||||
|
@ -154,4 +153,9 @@ public class ValidateUsername extends AbstractDirectGrantAuthenticator {
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return PROVIDER_ID;
|
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 {
|
public void send(RealmModel realm, UserModel user, String subject, String textBody, String htmlBody) throws EmailException {
|
||||||
Transport transport = null;
|
Transport transport = null;
|
||||||
try {
|
try {
|
||||||
String address = user.getEmail();
|
String address = retrieveEmailAddress(user);
|
||||||
Map<String, String> config = realm.getSmtpConfig();
|
Map<String, String> config = realm.getSmtpConfig();
|
||||||
|
|
||||||
Properties props = new Properties();
|
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 {
|
private void setupTruststore(Properties props) throws NoSuchAlgorithmException, KeyManagementException {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue