Class DefaultRedirectUriCreationFunction
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
-
- net.shibboleth.idp.plugin.authn.oidc.rp.impl.DefaultRedirectUriCreationFunction
-
- All Implemented Interfaces:
BiFunction<javax.servlet.http.HttpServletRequest,ProfileRequestContext,URI>,Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent
@ThreadSafeAfterInit public class DefaultRedirectUriCreationFunction extends AbstractIdentifiableInitializableComponent implements BiFunction<javax.servlet.http.HttpServletRequest,ProfileRequestContext,URI>
Constructive, pure, function that returns a redirect_uri from one of (ordered):- A pre-registered redirect_uri on the
OAuth2ClientContext.getRedirectUriOverride(). Or, if none are pre-registered; - Derived from the HTTP Servlet request server parameters, checking the origin against an allowed set of origins - to prevent Host header injection.
Returns null if one can not be constructed.
Is thread-safe and immutable
-
-
Field Summary
Fields Modifier and Type Field Description private Set<String>allowedOriginsA set of 'allowed' origins that can be used as the scheme, host, and port portion of the redirectURI.private StringcallbackServletPathThe path, excluding the context and servlet paths, to the RP callback handler.private org.slf4j.LoggerlogClass logger.private Function<ProfileRequestContext,OAuth2ClientContext>oauth2ClientContextLookupStrategyThe strategy used to lookup or create theOAuth2ClientContextfor storing the client_id.
-
Constructor Summary
Constructors Constructor Description DefaultRedirectUriCreationFunction()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description URIapply(javax.servlet.http.HttpServletRequest request, ProfileRequestContext prc)private StringbuildOrigin(URI uri)Builds the 'origin' (see RFC 6454) from given URI.private URIbuildURIIgnoreDefaultPorts(String scheme, String host, int port, String path)Build aURIfrom the given parameters.protected voiddoInitialize()voidsetAllowedOrigins(Set<String> origins)Set the allowed origins to use if a redirect_uri is computed.voidsetCallbackServletPath(String path)Set the path segment relative to the servlet path of the callback endpoint.voidsetOAuth2ClientContextLookupStrategy(Function<ProfileRequestContext,OAuth2ClientContext> strgy)Set the strategy to lookup theOAuth2ClientContextfrom theProfileRequestContext.-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
setId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
getId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, doDestroy, initialize, isDestroyed, isInitialized
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.function.BiFunction
andThen
-
Methods inherited from interface net.shibboleth.utilities.java.support.component.IdentifiedComponent
getId
-
-
-
-
Field Detail
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
oauth2ClientContextLookupStrategy
@Nonnull private Function<ProfileRequestContext,OAuth2ClientContext> oauth2ClientContextLookupStrategy
The strategy used to lookup or create theOAuth2ClientContextfor storing the client_id.
-
callbackServletPath
@NonnullAfterInit @NotEmpty private String callbackServletPath
The path, excluding the context and servlet paths, to the RP callback handler.
-
allowedOrigins
@NonnullAfterInit private Set<String> allowedOrigins
A set of 'allowed' origins that can be used as the scheme, host, and port portion of the redirectURI. Can be null, if so a redirect_uri must be specified in the context tree.
-
-
Method Detail
-
doInitialize
protected void doInitialize() throws ComponentInitializationException- Overrides:
doInitializein classAbstractIdentifiedInitializableComponent- Throws:
ComponentInitializationException
-
setCallbackServletPath
public void setCallbackServletPath(@Nonnull @NotEmpty String path)
Set the path segment relative to the servlet path of the callback endpoint.- Parameters:
path- the callback servlet path
-
setAllowedOrigins
public void setAllowedOrigins(@Nullable Set<String> origins)Set the allowed origins to use if a redirect_uri is computed.- Parameters:
origins- the origins
-
setOAuth2ClientContextLookupStrategy
public void setOAuth2ClientContextLookupStrategy(@Nonnull Function<ProfileRequestContext,OAuth2ClientContext> strgy)Set the strategy to lookup theOAuth2ClientContextfrom theProfileRequestContext.- Parameters:
strgy- the strategy.
-
apply
@Nullable public URI apply(@Nonnull javax.servlet.http.HttpServletRequest request, @Nonnull ProfileRequestContext prc)
- Specified by:
applyin interfaceBiFunction<javax.servlet.http.HttpServletRequest,ProfileRequestContext,URI>
-
buildOrigin
@Nonnull private String buildOrigin(@Nonnull URI uri) throws URISyntaxException
Builds the 'origin' (see RFC 6454) from given URI. Omits default or unknown ports.- Parameters:
uri- the URI to build the origin from- Returns:
- the origin
- Throws:
URISyntaxException- if there is an error getting information from the URI.
-
buildURIIgnoreDefaultPorts
@Nonnull private final URI buildURIIgnoreDefaultPorts(@Nonnull String scheme, @Nonnull String host, @Nonnull int port, @Nonnull String path) throws URISyntaxException
Build aURIfrom the given parameters. If the scheme is either 'http' or 'https' with their respective default port, the port is set to -1.- Parameters:
scheme- the schemehost- the hostnameport- the portpath- the path- Returns:
- a fully built URI from the given parameters.
- Throws:
URISyntaxException- if the URI can not be constructed.
-
-