Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(keycloak-integration): incorrect redirect url to janssen from the janssen authenticator plugin #7651 #7662

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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