Class AuthWidget
- java.lang.Object
-
public class AuthWidget extends WTemplateFormView
An authentication widget.The authentication widget is a widget that provides a login or logout function (depending on whether the user is currently logged in). You can use it for either or both purposes.
Loginor logout events are signalled to aLoginobject on which this widget acts.The widget also processes environmental information related to authentication:
- email tokens, which are indicated in an internal path. The widget uses dialogs (by default) to interact with the user to act on the token.
- authentication tokens, which are stored in browser cookies, to implement remember-me functionality.
The
processEnvironment()method initiates this process, and should typically be called only at application startup time.The authentication widget is implemented as a View for an
AuthModel, which can be set usingsetModel(). The login logic (at this moment only for password-based authentication) is handled by this model.It is very likely that the off-the shelf authentication widget does not satisfy entirely to your taste or functional requirements. The widget uses three methods to allow customization:
- as a
WTemplateFormView, you may change the layout and styling of to your liking. - the authentication logic is delegated to an
AuthModeland can can be specialized or can be used with a custom view altogether. - the views are created using virtual methods, which may be specialized to create a customized view or to apply changes to the default view.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WTemplate
WTemplate.Function, WTemplate.Functions
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefault
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Constructor Description AuthWidget(AuthService baseAuth, AbstractUserDatabase users, Login login)Constructor.AuthWidget(AuthService baseAuth, AbstractUserDatabase users, Login login, WContainerWidget parentContainer)Constructor.AuthWidget(Login login)Constructor.AuthWidget(Login login, WContainerWidget parentContainer)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcreate()Creates the user-interface.protected WWidgetcreateFormWidget(java.lang.String field)Creates a form widget.protected voidcreateLoggedInView()Creates the view shown when the user is logged in.protected voidcreateLoginView()Creates the login view.AbstractMfaProcesscreateMfaProcess()Create the MFA process.voidcreateMfaView()Shows the MFA process in the UI.protected voidcreateOAuthLoginView()Creates a widget to login using OAuth.protected voidcreatePasswordLoginView()Creates a password login view.WDialogcreatePasswordPromptDialog(Login login)Creates a password prompt dialog.WWidgetcreateRegistrationView(Identity id)Creates a registration view.WWidgetcreateUpdatePasswordView(User user, boolean promptPassword)Creates a view to update a user's password.voiddisplayError(java.lang.CharSequence m)Displays the error message.voiddisplayInfo(java.lang.CharSequence m)Displays the info message.WWidgetgetCreateLostPasswordView()Creates a lost password view.protected RegistrationModelgetCreateRegistrationModel()Creates a registration model.WWidgetgetCreateResendEmailVerificationView()Creates a view to resend the email verification email.java.lang.StringgetInternalBasePath()Returns the internal path.LogingetLogin()Returns the login object.AuthModelgetModel()Returns the model.voidhandleLostPassword()Lets the user "recover" a lost password.voidletResendEmailVerification()Lets the user resend the verification email.voidletUpdatePassword(User user, boolean promptPassword)Lets the user update his password.voidprocessEnvironment()Processes the (initial) environment.voidregisterNewUser()Starts a new registration process.voidregisterNewUser(Identity oauth)Starts a new registration process.voidremove()Destructor.protected voidrender(java.util.EnumSet<RenderFlag> flags)Renders the widget.voidsetInternalBasePath(java.lang.String basePath)Sets an internal path for authentication services.voidsetModel(AuthModel model)Sets a model.voidsetRegistrationEnabled(boolean enabled)Configures registration capabilities.protected WDialogshowDialog(java.lang.CharSequence title, WWidget contents)Shows a dialog.-
Methods inherited from class eu.webtoolkit.jwt.WTemplateFormView
indicateValidation, setFormWidget, setFormWidget, updateModel, updateModelField, updateModelValue, updateModelValue, updateView, updateViewField, updateViewValue, updateViewValue
-
Methods inherited from class eu.webtoolkit.jwt.WTemplate
addFunction, applyArguments, bindEmpty, bindInt, bindString, bindString, bindWidget, clear, conditionValue, enableAjax, format, format, format, format, getConditionsSet, getErrorText, getTemplateText, getWidgetIdMode, getWidgets, handleUnresolvedVariable, hasInternalPathEncoding, isEncodeTemplateText, iterateChildren, refresh, removeWidget, removeWidget, renderTemplate, renderTemplateText, reset, resolveFunction, resolveString, resolveStringValue, resolveWidget, setCondition, setEncodeTemplateText, setInternalPathEncoding, setTemplateText, setTemplateText, setWidgetIdMode, varName
-
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
-
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, createDomElement, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getDomChanges, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName, setFormData
-
-
-
-
Constructor Detail
-
AuthWidget
public AuthWidget(AuthService baseAuth, AbstractUserDatabase users, Login login, WContainerWidget parentContainer)
Constructor.Creates a new authentication widget. This creates an
AuthModelusing the given authentication servicebaseAuthand user databaseusers.The result of authentication changes is propagated to the rest of the application using a
loginobject.Authentication services need to be configured in the
getModel().
-
AuthWidget
public AuthWidget(AuthService baseAuth, AbstractUserDatabase users, Login login)
Constructor.
-
AuthWidget
public AuthWidget(Login login, WContainerWidget parentContainer)
Constructor.Creates a new authentication widget.
The result of authentication changes is propagated to the rest of the application using a
loginobject.You need to call
setModel()to configure a model for this view.
-
AuthWidget
public AuthWidget(Login login)
Constructor.
-
-
Method Detail
-
remove
public void remove()
Description copied from class:WWidgetDestructor.Deletes a widget and all contained contents.
- Overrides:
removein classWTemplate- See Also:
WWidget.removeWidget(WWidget widget)
-
setModel
public void setModel(AuthModel model)
Sets a model.This sets a model to be used for authentication.
-
getModel
public AuthModel getModel()
Returns the model.The model is used only for the login function.
- See Also:
setModel(AuthModel model)
-
getLogin
public Login getLogin()
Returns the login object.This login object is used to keep track of the user currently authenticated.
-
setInternalBasePath
public void setInternalBasePath(java.lang.String basePath)
Sets an internal path for authentication services.Only the registration function is made available through an internal path (so that one can redirect a user to the registration page). Other internal paths involved in authentication are configured in the service classes:
AuthService#setEmailRedirectInternalPath(): email tokens- OAuthService::redirectInternalPath(): an internal path used during the oauth process.
-
getInternalBasePath
public java.lang.String getInternalBasePath()
Returns the internal path.- See Also:
setInternalBasePath(String basePath)
-
setRegistrationEnabled
public void setRegistrationEnabled(boolean enabled)
Configures registration capabilities.Although the
AuthWidgetitself does not implement a registration view, it may offer a button/link to do so, and callsregisterNewUser()when a user wishes to register.Even if registration is not enabled, the result of an
OAuthServicelogin process may be that a new user is identified. Then thecreateRegistrationView()is also used to present this new user with a registration view, passing the information obtained through OAuth.
-
registerNewUser
public void registerNewUser()
Starts a new registration process.This calls
registerNewUser(0).
-
registerNewUser
public void registerNewUser(Identity oauth)
Starts a new registration process.This starts a new registration process, and may be called in response to a user action, an internal path change, or an
OAuthServicelogin procedure which identified a new user. In the latter case, the OAuth-provided information is passed as parameteroauth.The default implementation creates a view using
createRegistrationView(), and shows it in a dialog usingshowDialog().
-
processEnvironment
public void processEnvironment()
Processes the (initial) environment.This method process environmental information that may be relevant to authentication:
- email tokens, which are indicated through an internal path. The widget uses dialogs (by default) to interact with the user to act on the token.
- authentication tokens, which are stored in browser cookies, to implement remember-me
functionality. When logging in using an authentication token, the login is considered
"weak" (since a user may have inadvertently forgotten to logout from a public
computer). You should let the user authenticate using another, primary method before
doing sensitive operations. The
createPasswordPromptDialog()method may be useful for this. This token denotes a regular username/password login. If the "remember-me" functionality is enabled for it, and selected, a token will be produced, named according toAuthService.getAuthTokenCookieName(), and valid forAuthService.getAuthTokenValidity()(in minutes). Both can be set by enabling authentication tokens with AuthService::setAuthTokenaEnabled(). By default the cookie will be called "wtauth" and will be valid for two weeks.
-
letUpdatePassword
public void letUpdatePassword(User user, boolean promptPassword)
Lets the user update his password.This creates a view to let the user enter his new password.
The default implementation creates a new view using
createUpdatePasswordView()and shows it in a dialog usingshowDialog().
-
handleLostPassword
public void handleLostPassword()
Lets the user "recover" a lost password.This creates a view to let the user enter his email address, used to send an email containing instructions to enter a new password.
The default implementation creates a new view using
getCreateLostPasswordView()and shows it in a dialog usingshowDialog().
-
getCreateLostPasswordView
public WWidget getCreateLostPasswordView()
Creates a lost password view.When email verification has been enabled, the user may indicate that he has lost his password – then proof of controlling the same email address that had associated with his account is sufficient to allow him to enter a new password.
This creates the widget used to let the user enter his email address. The default implementation creates a new
LostPasswordWidget.- See Also:
handleLostPassword()
-
createRegistrationView
public WWidget createRegistrationView(Identity id)
Creates a registration view.This creates a registration view, optionally using information already obtained from a third party identification service (such as an OAuth provider).
The default implementation creates a new
RegistrationWidgetwith a model created usinggetCreateRegistrationModel().- See Also:
registerNewUser()
-
letResendEmailVerification
public void letResendEmailVerification()
Lets the user resend the verification email.This creates a view to let the user resend the email to verify their email address.
The default implementation creates a new view using
getCreateResendEmailVerificationView()and shows it in a dialog usingshowDialog().
-
getCreateResendEmailVerificationView
public WWidget getCreateResendEmailVerificationView()
Creates a view to resend the email verification email.If
AuthService.isEmailVerificationRequired()istrue, a button will be shown next to the user name field to resend the verification email (if the email was not yet verified). This button will show a dialog containing the widget returned by this method. The default implementation instantiates aResendEmailVerificationWidget.This creates the widget used to let the user chose a new password. The default implementation instantiates an
UpdatePasswordWidget.Note that if email verification is optional, the application should provide its own mechanism to resend the verification email (e.g. in a user settings widget).
-
createUpdatePasswordView
public WWidget createUpdatePasswordView(User user, boolean promptPassword)
Creates a view to update a user's password.If
promptPasswordistrue, the user has to enter his current password in addition to a new password.This creates the widget used to let the user chose a new password. The default implementation instantiates an
UpdatePasswordWidget.
-
createPasswordPromptDialog
public WDialog createPasswordPromptDialog(Login login)
Creates a password prompt dialog.This creates a dialog password. The user is taken from the
loginobject, which also signals an eventual success using itsLogin.changed()signal.The default implementation instantiates a
PasswordPromptDialog.
-
createMfaProcess
public AbstractMfaProcess createMfaProcess()
Create the MFA process.When MFA is enabled (
AuthService#setMfaProvider()is set), this will be called to create a specific MFA process. This can be used by developers to provide their own implementation, and ensure that the right widgets are shown to the user.By default this will generate a
TotpProcess.
-
createMfaView
public void createMfaView()
Shows the MFA process in the UI.This functionality manages how the MFA step is shown to the user. Developers can override this to show the step in any way they see fit. This can be shown as part of the main view, as a pop-up, ...
It will also need to decide whether the setup view (
AbstractMfaProcess.createSetupView()) or input view (AbstractMfaProcess.createInputView()) is shown to the user.By default this will show the process in the main view, replacing the normal login widget with the right view on the MFA process.
-
displayError
public void displayError(java.lang.CharSequence m)
Displays the error message.This method display an dialog showing the error
-
displayInfo
public void displayInfo(java.lang.CharSequence m)
Displays the info message.This method display an dialog showing the info
-
create
protected void create()
Creates the user-interface.This method is called just before an initial rendering, and creates the initial view.
The default implementation calls
createLoginView()orcreateLoggedInView()depending on whether a user is currently logged in.If MFA is enabled (
AuthService.isMfaEnabled()), this may callcreateMfaView(). This will be called if the user that is logging in has this step enabled (AuthModel#hasMfaStep()).
-
createLoginView
protected void createLoginView()
Creates the login view.This creates a view that allows the user to login, and is shown when no user is current logged in.
The default implementation renders the
"Wt.Auth.template.login"template, and binds fields usingcreatePasswordLoginView()andcreateOAuthLoginView().
-
createLoggedInView
protected void createLoggedInView()
Creates the view shown when the user is logged in.The default implementation renders the
"Wt.Auth.template.logged-in"template.
-
createPasswordLoginView
protected void createPasswordLoginView()
Creates a password login view.This is used by the default implementation of
createLoginView()to prompt for the information needed for logging in using a username and password. The default implementation implements a view guided by thegetModel().- See Also:
createLoginView()
-
createOAuthLoginView
protected void createOAuthLoginView()
Creates a widget to login using OAuth.The default implementation adds an icon for each OAuth service provider available. The icon that will be used for each service is a PNG file with a path based on the
OAuthService.getName()of the service. If the name is is "myService", then the icon path will be "css/oauth-myService.png". JWt does not bundle any icons by default, so you should make sure that the icon is in place.There's a lot to say about making a usable login mechanism for OAuth (and federated login services in general), see https://sites.google.com/site/oauthgoog/UXFedLogin.
- See Also:
createLoginView()
-
showDialog
protected WDialog showDialog(java.lang.CharSequence title, WWidget contents)
Shows a dialog.This shows a dialog. The default method creates a standard
WDialog, with the giventitleandcontentsas central widget.When the central widget is deleted, it deletes the dialog.
-
getCreateRegistrationModel
protected RegistrationModel getCreateRegistrationModel()
Creates a registration model.This method creates a registration model. The default implementation creates a RegistrationModel() but you may want to reimplement this function to return a specialized registration model (complementing a specialized registration view).
- See Also:
registerNewUser()
-
createFormWidget
protected WWidget createFormWidget(java.lang.String field)
Description copied from class:WTemplateFormViewCreates a form widget.This method is called by
updateViewField()when it needs to create a form widget for a field, and none was specified usingsetFormWidget().- Overrides:
createFormWidgetin classWTemplateFormView
-
render
protected void render(java.util.EnumSet<RenderFlag> flags)
Description copied from class:WWidgetRenders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender().The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
- Overrides:
renderin classWInteractWidget
-
-