-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(oidc): apply acr values to redirect url (#11447)
- Loading branch information
1 parent
b17d776
commit a754d52
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
datahub-frontend/app/auth/sso/oidc/custom/CustomOidcRedirectionActionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package auth.sso.oidc.custom; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.pac4j.core.context.WebContext; | ||
import org.pac4j.core.exception.http.RedirectionAction; | ||
import org.pac4j.core.exception.http.RedirectionActionHelper; | ||
import org.pac4j.oidc.client.OidcClient; | ||
import org.pac4j.oidc.config.OidcConfiguration; | ||
import org.pac4j.oidc.redirect.OidcRedirectionActionBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
public class CustomOidcRedirectionActionBuilder extends OidcRedirectionActionBuilder { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(OidcRedirectionActionBuilder.class); | ||
public CustomOidcRedirectionActionBuilder(OidcConfiguration configuration, OidcClient client) { | ||
super(configuration, client); | ||
} | ||
|
||
@Override | ||
public Optional<RedirectionAction> getRedirectionAction(WebContext context) { | ||
Map<String, String> params = this.buildParams(); | ||
String computedCallbackUrl = this.client.computeFinalCallbackUrl(context); | ||
params.put("redirect_uri", computedCallbackUrl); | ||
this.addStateAndNonceParameters(context, params); | ||
if (this.configuration.getMaxAge() != null) { | ||
params.put("max_age", this.configuration.getMaxAge().toString()); | ||
} | ||
|
||
String location = this.buildAuthenticationRequestUrl(params); | ||
|
||
logger.debug("Custom parameters: {}", this.configuration.getCustomParams()); | ||
|
||
String acrValues = this.configuration.getCustomParam("acr_values"); | ||
|
||
if (acrValues != null && !location.contains("acr_values=")) { | ||
location += (location.contains("?") ? "&" : "?") + "acr_values=" + acrValues; | ||
} | ||
|
||
logger.debug("Authentication request url: {}", location); | ||
return Optional.of(RedirectionActionHelper.buildRedirectUrlAction(context, location)); | ||
} | ||
|
||
} |