Skip to content

Commit

Permalink
fix(keycloak-integration): incorrect redirect url to janssen from aut…
Browse files Browse the repository at this point in the history
…henticator plugin #7651

Signed-off-by: Rolain Djeumen <uprightech@gmail.com>
  • Loading branch information
uprightech committed Feb 6, 2024
1 parent 243919d commit cf3de6d
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;

import java.text.MessageFormat;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class JansAuthenticator implements Authenticator {
private static final String JANS_LOGIN_URL_ATTRIBUTE = "jansLoginUrl";
private static final String OPENID_AUTH_PARAMS_ATTRIBUTE = "openIdAuthParams";

private static final String URI_PATH_TO_REST_SERVICE = "/realms/{0}/{1}/auth-complete";
private static final String URI_PATH_TO_REST_SERVICE = "realms/{realm}/{providerid}/auth-complete";


private OIDCService oidcService;
Expand Down Expand Up @@ -206,14 +207,19 @@ private Configuration extractAndValidateConfiguration(AuthenticationFlowContext

private URI createRedirectUri(AuthenticationFlowContext context) {

URI serverUri = context.getSession().getContext().getUri().getBaseUri();
String realmname = context.getRealm().getName();
String rest_svc_uri = MessageFormat.format(URI_PATH_TO_REST_SERVICE,realmname,ProviderIDs.JANS_AUTH_RESPONSE_REST_PROVIDER);
return serverUri.resolve(rest_svc_uri);
try {
String realmname = context.getRealm().getName();
return UriBuilder.fromUri(context.getSession().getContext().getUri().getBaseUri())
.path(URI_PATH_TO_REST_SERVICE)
.build(realmname,ProviderIDs.JANS_AUTH_RESPONSE_REST_PROVIDER);
}catch(IllegalArgumentException e) {
log.warnv(e,"Could not create redirect URIs");
return null;
}
}

private UserModel findUserByNameOrEmail(AuthenticationFlowContext context, String username,String email) {

UserModel user = KeycloakModelUtils.findUserByNameOrEmail(context.getSession(),context.getRealm(),username);
if(user == null) {
user = KeycloakModelUtils.findUserByNameOrEmail(context.getSession(),context.getRealm(),email);
Expand Down

0 comments on commit cf3de6d

Please sign in to comment.