Class OidcClient
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
LoginConlet
that handles the
communication with the OIDC provider.“OidcClient” is a bit
of a misnomer because this class not only initiates requests
to the OIDC provider but also serves the redirect URI that the
provider uses as callback. However, the callback can be seen
as the asynchronous response to the authentication request
that the OidcClient
sends initially, therefore the
component primarily acts as a client nevertheless.
The component requires an HTTP connector (usually an
instance of HttpConnector
) to exist that handles the
Request.Out
events that this component fires. There
must also be an HTTP server (usually an instance of
HttpServer
) that converts the provider’s calls to the
redirect URI from the provider to a Request.In.Get
event.
Details about configuring the various channels used can be found
in the description of the constructor
.
The component has a single configuration property that sets the value of the redirect URI sent to the OIDC provider.
"...":
"/OidcClient":
redirectUri: "https://localhost:5443/vjconsole/oauth/callback"
While it is tempting to simply use as redirect URI the host/port from the HTTP server component together with the request path passed to the constructor, there are two reasons why the redirect URI has to be configured explicitly. First, the framework does not support querying the host/port properties from the server component. Second, and more import, the HTTP server component will often be placed behind a firewall or reverse proxy and therefore the URL that it serves will usually differ from the redirect URI sent to the OIDC provider.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The configuration information.Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
-
Constructor Summary
ConstructorDescriptionOidcClient
(Channel componentChannel, Channel httpClientChannel, Channel httpServerChannel, URI redirectTarget, int priority) Instantiates a new OIDC client. -
Method Summary
Modifier and TypeMethodDescriptionvoid
onAuthCallback
(Request.In.Get event, IOSubchannel channel) On callback from the authorization request.void
The component can be configured with events that include a path (see @linkConfigurationUpdate.paths()
) that matches this components path (seeManager.componentPath()
).void
onConnected
(HttpConnected event, IOSubchannel clientChannel) Invoked when the connection to the provider has been established.void
onDataInput
(DataInput<Map<String, Object>> event, IOSubchannel clientChannel) On data input.void
onInput
(Input<ByteBuffer> event, IOSubchannel clientChannel) Collect and process input from the provider.void
onResponse
(Response response, IOSubchannel clientChannel) Invoked when a response is received from the provider.void
On start provider login.Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
OidcClient
public OidcClient(Channel componentChannel, Channel httpClientChannel, Channel httpServerChannel, URI redirectTarget, int priority) Instantiates a new OIDC client.The OIDC uses three channels.
-
It is a helper component for the
LoginConlet
and therefore uses its “primary” (component) channel to exchange events with the conlet. -
It uses the
httpClientChannel
to accesses the provider as client, i.e. when it firesRequest.Out
events to obtain information from the provider. -
It defines a request handler that listens on the
httpServerChannel
for handling the authorization callback from the provider.
- Parameters:
componentChannel
- the component’s channelhttpClientChannel
- the channel used for connecting the providerhttpServerChannel
- the channel used by someHttpServer
to send theRequest.In
events from the provider callbackredirectTarget
- defines the path handled byonAuthCallback(org.jgrapes.http.events.Request.In.Get, org.jgrapes.io.IOSubchannel)
priority
- the priority of theonAuthCallback(org.jgrapes.http.events.Request.In.Get, org.jgrapes.io.IOSubchannel)
handler. Must be higher than the default priority of request handlers if the callback URL uses a sub-path of the web console’s URL.
-
-
-
Method Details
-
onConfigUpdate
The component can be configured with events that include a path (see @linkConfigurationUpdate.paths()
) that matches this components path (seeManager.componentPath()
).The following properties are recognized:
redirectUri
- The redirect URI as defined in the OIDC provider.
- Parameters:
event
- the event
-
onStartProviderLogin
On start provider login.- Parameters:
event
- the event- Throws:
URISyntaxException
-
onConnected
@Handler(channels=org.jgrapes.webconlet.oidclogin.OidcClient.HttpClientChannel.class) public void onConnected(HttpConnected event, IOSubchannel clientChannel) Invoked when the connection to the provider has been established.- Parameters:
event
- the eventclientChannel
- the client channel
-
onResponse
@Handler(channels=org.jgrapes.webconlet.oidclogin.OidcClient.HttpClientChannel.class) public void onResponse(Response response, IOSubchannel clientChannel) throws URISyntaxException Invoked when a response is received from the provider.- Parameters:
response
- the responseclientChannel
- the client channel- Throws:
URISyntaxException
-
onInput
@Handler(channels=org.jgrapes.webconlet.oidclogin.OidcClient.HttpClientChannel.class) public void onInput(Input<ByteBuffer> event, IOSubchannel clientChannel) throws IOException Collect and process input from the provider.- Parameters:
event
- the eventclientChannel
- the client channel- Throws:
IOException
- Signals that an I/O exception has occurred.
-
onDataInput
@Handler(channels=org.jgrapes.webconlet.oidclogin.OidcClient.HttpClientChannel.class) public void onDataInput(DataInput<Map<String, Object>> event, IOSubchannel clientChannel) throws MalformedURLException, URISyntaxException, com.fasterxml.jackson.databind.JsonMappingException, com.fasterxml.jackson.core.JsonProcessingExceptionOn data input.- Parameters:
event
- the eventclientChannel
- the client channel- Throws:
MalformedURLException
- the malformed URL exceptionURISyntaxException
- the URI syntax exceptioncom.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.databind.JsonMappingException
-
onAuthCallback
@RequestHandler(channels=org.jgrapes.webconlet.oidclogin.OidcClient.HttpServerChannel.class, dynamic=true) public void onAuthCallback(Request.In.Get event, IOSubchannel channel) On callback from the authorization request.(Path selector defined in constructor.)
- Parameters:
event
- the eventchannel
- the channel
-