Class LoginConlet
- All Implemented Interfaces:
Iterable<ComponentType>,Channel,ComponentType,Eligible,Manager
OIDC providers can be configured as property “oidcProviders” of the conlet:
"...":
"/LoginConlet":
oidcProviders:
- name: my-provider
displayName: My Provider
configurationEndpoint: https://test.com/.well-known/openid-configuration
# If no configurationEndpoint is available, the authorizationEndpoint
# and the tokenEndpoint can be configured instead
# authorizationEndpoint: ...
# tokenEndpoint: ...
clientId: "WebConsoleTest"
secret: "(unknown)"
# The size of the popup window for the provider's login dialog
popup:
# Size of the popup windows for authentication. Either
# relative to the browser window's size or absolute in pixels
factor: 0.6
# width: 1600
# height: 600
# Only users with one of the roles listed here are allowed to login.
# The check is performed against the roles reported by the provider
# before any role mappings are applied (see below).
# An empty role name in this list allows users without any role
# to login.
authorizedRoles:
- "admin"
- "user"
- ""
# Mappings to be applied to the preferred user name reported
# by the provider. The list is evaluated up to the first match.
userMappings:
- from: "(.*)"
to: "$1@oidc"
# Mappings to be applied to the role names reported by the
# provider. The list is evaluated up to the first match.
roleMappings:
- from: "(.*)"
to: "$1@oidc"
The user id of the authenticated user is taken from the ID token’s
claim preferred_username, the display name from the claim name.
Roles are created from the ID token’s claim roles. Reporting the
latter has usually to be added in the provider’s configuration.
Of course, roles can also be added independently based on the
user id by using another component, thus separating the authentication
by the OIDC provider from the role management.
The component requires that an instance of OidcClient
handles the StartOidcLogin events fired on the component’s
channel.
As a fallback, local users can be configured as property “users”:
"...":
"/LoginConlet":
users:
- name: admin
# Full name is optional
fullName: Administrator
password: "$2b$05$NiBd74ZGdplLC63ePZf1f.UtjMKkbQ23cQoO2OKOFalDBHWAOy21."
- name: test
fullName: Test Account
email: test@test.com
password: "$2b$05$hZaI/jToXf/d3BctZdT38Or7H7h6Pn2W3WiB49p5AyhDHFkkYCvo2"
Passwords are hashed using bcrypt.
The local login part of the dialog is only shown if at least one user is configured.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.jgrapes.webconsole.base.AbstractConlet
AbstractConlet.ConletTrackingInfoNested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default -
Field Summary
Fields inherited from class org.jgrapes.webconsole.base.AbstractConlet
TYPE_INSTANCE_SEPARATOR -
Constructor Summary
ConstructorsConstructorDescriptionLoginConlet(Channel componentChannel) Creates a new component with its channel set to the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected Optional<LoginConlet.AccountModel> createNewState(AddConletRequest event, ConsoleConnection session, String conletId) As a model has already been created indoUpdateConletState(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection, org.jgrapes.webconlet.oidclogin.LoginConlet.AccountModel), the “new” model may already exist in the session.protected Optional<LoginConlet.AccountModel> createStateRepresentation(Event<?> event, ConsoleConnection channel, String conletId) Creates an instance of the type that represents the conlet’s state, initialized with default values.protected Set<Conlet.RenderMode> doRenderConlet(RenderConletRequestBase<?> event, ConsoleConnection channel, String conletId, LoginConlet.AccountModel model) Called byAbstractConlet.onAddConletRequest(AddConletRequest, ConsoleConnection)andAbstractConlet.onRenderConletRequest(RenderConletRequest, ConsoleConnection)to complete rendering the web console component.protected booleandoSetLocale(SetLocale event, ConsoleConnection channel, String conletId) Do set locale.protected voiddoUpdateConletState(NotifyConletModel event, ConsoleConnection connection, LoginConlet.AccountModel model) Called byAbstractConlet.onNotifyConletModel(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection)to complete handling the notification.protected StringgenerateInstanceId(AddConletRequest event, ConsoleConnection session) Create the instance specific part of a conlet id.voidThe component can be configured with events that include a path (see @linkConfigurationUpdate.paths()) that matches this components path (seeManager.componentPath()).voidonConsolePrepared(ConsolePrepared event, ConsoleConnection channel) Handle web console page loaded.voidonConsoleReady(ConsoleReady event, ConsoleConnection channel) Register conlet.voidonOidcError(OidcError event, Channel channel) On oidc error.voidonOpenLoginWindow(OpenLoginWindow event, Channel channel) Invoked when the OIDC client has assembled the required information for contacting the provider.voidonUserAuthenticated(UserAuthenticated event, Channel channel) Invoked when a user has been authenticated.Methods inherited from class org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet
doGetResource, fmConletModel, fmModel, fmModel, fmSessionModel, fmTypeModel, freemarkerConfig, processTemplate, processTemplateMethods inherited from class org.jgrapes.webconsole.base.AbstractConlet
afterOnClosed, conletIds, conletIdsByConsoleConnection, conletViews, doConletDeleted, doRemoveConletType, l10nBundles, localizations, onAddConletRequest, onClosed, onConletDeleted, onConletResourceRequest, onDetached, onNotifyConletModel, onRenderConletRequest, onSetLocale, putInSession, readContent, readContent, recreateState, removeState, resourceBundle, setPeriodicRefresh, stateFromSession, statesFromSession, supportedLocales, trackConlet, trackedConnections, type, typeFromIdMethods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setNameMethods 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, unregisterAsGeneratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
LoginConlet
Creates a new component with its channel set to the given channel.- Parameters:
componentChannel- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)sends the event to
-
-
Method Details
-
generateInstanceId
Description copied from class:AbstractConletCreate the instance specific part of a conlet id.The default implementation generates a UUID. Derived classes override this method if e.g. the instance specific part must include a key that associates the conlet’s state with some backing store.
- Overrides:
generateInstanceIdin classAbstractConlet<LoginConlet.AccountModel>- Parameters:
event- the event that triggered the creation of a new conlet, which may contain required information (seeAddConletRequest.properties())session- the console connection; usually not required but provided as context- Returns:
- the web console component id
-
onConsoleReady
@Handler public void onConsoleReady(ConsoleReady event, ConsoleConnection channel) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException Register conlet.- Parameters:
event- the eventchannel- the channel- Throws:
TemplateNotFoundException- the template not found exceptionMalformedTemplateNameException- the malformed template name exceptionParseException- the parse exceptionIOException- Signals that an I/O exception has occurred.
-
createNewState
protected Optional<LoginConlet.AccountModel> createNewState(AddConletRequest event, ConsoleConnection session, String conletId) throws Exception As a model has already been created indoUpdateConletState(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection, org.jgrapes.webconlet.oidclogin.LoginConlet.AccountModel), the “new” model may already exist in the session.- Overrides:
createNewStatein classAbstractConlet<LoginConlet.AccountModel>- Parameters:
event- the eventsession- the console connectionconletId- the conlet id- Returns:
- the state representation or
Optional.empty()if none is required - Throws:
Exception- if an exception occurs
-
createStateRepresentation
protected Optional<LoginConlet.AccountModel> createStateRepresentation(Event<?> event, ConsoleConnection channel, String conletId) throws IOException Description copied from class:AbstractConletCreates an instance of the type that represents the conlet’s state, initialized with default values.The default implementation returns
Optional.isEmpty(), thus indicating that no state information is needed or available.This method should always be overridden if conlet instances have associated state.
- Overrides:
createStateRepresentationin classAbstractConlet<LoginConlet.AccountModel>- Parameters:
event- the event, which may contain required information (seeAddConletRequest.properties())channel- the console connection, sometimes required to send events to components that provide a backing storeconletId- the conlet id calculated astype() + TYPE_INSTANCE_SEPARATOR + generateInstanceId(...)- Returns:
- the state representation or
Optional.empty()if none is required - Throws:
IOException
-
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:
users- See
LoginConlet.
- Parameters:
event- the event
-
onConsolePrepared
@Handler(priority=1000) public void onConsolePrepared(ConsolePrepared event, ConsoleConnection channel) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException Handle web console page loaded.- Parameters:
event- the eventchannel- the channel- Throws:
IOExceptionParseExceptionMalformedTemplateNameExceptionTemplateNotFoundException
-
doRenderConlet
protected Set<Conlet.RenderMode> doRenderConlet(RenderConletRequestBase<?> event, ConsoleConnection channel, String conletId, LoginConlet.AccountModel model) throws Exception Description copied from class:AbstractConletCalled byAbstractConlet.onAddConletRequest(AddConletRequest, ConsoleConnection)andAbstractConlet.onRenderConletRequest(RenderConletRequest, ConsoleConnection)to complete rendering the web console component.The
- Specified by:
doRenderConletin classAbstractConlet<LoginConlet.AccountModel>- Parameters:
event- the eventchannel- the channelconletId- the component idmodel- the conlet’s state; may benullif the conlet doesn’t have associated state information- Returns:
- the rendered modes
- Throws:
Exception- the exception
-
doUpdateConletState
protected void doUpdateConletState(NotifyConletModel event, ConsoleConnection connection, LoginConlet.AccountModel model) throws Exception Description copied from class:AbstractConletCalled byAbstractConlet.onNotifyConletModel(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection)to complete handling the notification.The default implementation does nothing.
- Overrides:
doUpdateConletStatein classAbstractConlet<LoginConlet.AccountModel>- Parameters:
event- the eventconnection- the channelmodel- the conlet’s state; may benullif the conlet doesn’t have associated state information- Throws:
Exception
-
onOpenLoginWindow
Invoked when the OIDC client has assembled the required information for contacting the provider.- Parameters:
event- the eventchannel- the channel
-
onOidcError
On oidc error.- Parameters:
event- the eventchannel- the channel
-
onUserAuthenticated
Invoked when a user has been authenticated.- Parameters:
event- the eventchannel- the channel
-
doSetLocale
protected boolean doSetLocale(SetLocale event, ConsoleConnection channel, String conletId) throws Exception Do set locale.- Overrides:
doSetLocalein classAbstractConlet<LoginConlet.AccountModel>- Parameters:
event- the eventchannel- the channelconletId- the conlet id- Returns:
- true, if successful
- Throws:
Exception- the exception
-