Class FreeMarkerLoginFormsProvider
- java.lang.Object
-
- org.keycloak.forms.login.freemarker.FreeMarkerLoginFormsProvider
-
- All Implemented Interfaces:
LoginFormsProvider
,Provider
public class FreeMarkerLoginFormsProvider extends Object implements LoginFormsProvider
- Author:
- Stian Thorgersen
-
-
Field Summary
Fields Modifier and Type Field Description protected String
accessCode
protected URI
actionUri
protected Map<String,Object>
attributes
protected AuthenticationSessionModel
authenticationSession
authenticationSession can be null for some renderings, mainly error pagesprotected ClientModel
client
protected List<AuthorizationDetails>
clientScopesRequested
protected AuthenticationFlowContext
context
protected String
execution
protected javax.ws.rs.core.MultivaluedMap<String,String>
formData
protected FreeMarkerProvider
freeMarker
protected Map<String,String>
httpResponseHeaders
protected List<FormMessage>
messages
protected MessageType
messageType
protected RealmModel
realm
protected KeycloakSession
session
protected javax.ws.rs.core.Response.Status
status
protected javax.ws.rs.core.UriInfo
uriInfo
protected UserModel
user
-
Fields inherited from interface org.keycloak.forms.login.LoginFormsProvider
IDENTITY_PROVIDER_BROKER_CONTEXT, REGISTRATION_DISABLED, UPDATE_PROFILE_CONTEXT_ATTR, USERNAME_HIDDEN
-
-
Constructor Summary
Constructors Constructor Description FreeMarkerLoginFormsProvider(KeycloakSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LoginFormsProvider
addError(FormMessage errorMessage)
void
addScript(String scriptUrl)
Adds a script to the html headerLoginFormsProvider
addSuccess(FormMessage errorMessage)
Add a success message to the formvoid
close()
javax.ws.rs.core.Response
createCode()
protected void
createCommonAttributes(Theme theme, Locale locale, Properties messagesBundle, javax.ws.rs.core.UriBuilder baseUriBuilder, LoginFormsPages page)
Create common attributes used in all templates.javax.ws.rs.core.Response
createErrorPage(javax.ws.rs.core.Response.Status status)
javax.ws.rs.core.Response
createForm(String form)
javax.ws.rs.core.Response
createFrontChannelLogoutPage()
javax.ws.rs.core.Response
createIdpLinkConfirmLinkPage()
javax.ws.rs.core.Response
createIdpLinkEmailPage()
javax.ws.rs.core.Response
createInfoPage()
javax.ws.rs.core.Response
createLoginExpiredPage()
javax.ws.rs.core.Response
createLoginPassword()
javax.ws.rs.core.Response
createLoginRecoveryAuthnCode()
javax.ws.rs.core.Response
createLoginTotp()
javax.ws.rs.core.Response
createLoginUsername()
javax.ws.rs.core.Response
createLoginUsernamePassword()
javax.ws.rs.core.Response
createLoginWebAuthn()
javax.ws.rs.core.Response
createLogoutConfirmPage()
javax.ws.rs.core.Response
createOAuth2DeviceVerifyUserCodePage()
javax.ws.rs.core.Response
createOAuthGrant()
javax.ws.rs.core.Response
createPasswordReset()
javax.ws.rs.core.Response
createRegistration()
protected javax.ws.rs.core.Response
createResponse(LoginFormsPages page)
javax.ws.rs.core.Response
createResponse(UserModel.RequiredAction action)
javax.ws.rs.core.Response
createSamlPostForm()
javax.ws.rs.core.Response
createSelectAuthenticator()
javax.ws.rs.core.Response
createUpdateProfilePage()
javax.ws.rs.core.Response
createWebAuthnErrorPage()
javax.ws.rs.core.Response
createX509ConfirmPage()
protected String
formatMessage(FormMessage message, Properties messagesBundle, Locale locale)
protected String
getFirstMessageUnformatted()
String
getMessage(String message)
protected Theme
getTheme()
Get Theme used for page rendering.protected void
handleMessages(Locale locale, Properties messagesBundle)
Handle messages to be shown on the page - set them to template attributesprotected Properties
handleThemeResources(Theme theme, Locale locale)
Load message bundle and place it intomsg
template attribute.protected javax.ws.rs.core.UriBuilder
prepareBaseUriBuilder(boolean resetRequestUriParams)
Prepare base uri builder for later useprotected javax.ws.rs.core.Response
processTemplate(Theme theme, String templateName, Locale locale)
Process FreeMarker template and prepare Response.LoginFormsProvider
setAccessRequest(List<AuthorizationDetails> clientScopesRequested)
LoginFormsProvider
setActionUri(URI actionUri)
LoginFormsProvider
setAttribute(String name, Object value)
LoginFormsProvider
setAuthContext(AuthenticationFlowContext context)
LoginFormsProvider
setAuthenticationSession(AuthenticationSessionModel authenticationSession)
LoginFormsProvider
setClientSessionCode(String accessCode)
FreeMarkerLoginFormsProvider
setError(String message, Object... parameters)
Set one global error message.LoginFormsProvider
setErrors(List<FormMessage> messages)
Set multiple error messages.LoginFormsProvider
setExecution(String execution)
FreeMarkerLoginFormsProvider
setFormData(javax.ws.rs.core.MultivaluedMap<String,String> formData)
FreeMarkerLoginFormsProvider
setInfo(String message, Object... parameters)
protected void
setMessage(MessageType type, String message, Object... parameters)
LoginFormsProvider
setResponseHeader(String headerName, String headerValue)
LoginFormsProvider
setStatus(javax.ws.rs.core.Response.Status status)
FreeMarkerLoginFormsProvider
setSuccess(String message, Object... parameters)
FreeMarkerLoginFormsProvider
setUser(UserModel user)
-
-
-
Field Detail
-
accessCode
protected String accessCode
-
status
protected javax.ws.rs.core.Response.Status status
-
clientScopesRequested
protected List<AuthorizationDetails> clientScopesRequested
-
actionUri
protected URI actionUri
-
execution
protected String execution
-
context
protected AuthenticationFlowContext context
-
messages
protected List<FormMessage> messages
-
messageType
protected MessageType messageType
-
session
protected KeycloakSession session
-
authenticationSession
protected AuthenticationSessionModel authenticationSession
authenticationSession can be null for some renderings, mainly error pages
-
realm
protected RealmModel realm
-
client
protected ClientModel client
-
uriInfo
protected javax.ws.rs.core.UriInfo uriInfo
-
freeMarker
protected FreeMarkerProvider freeMarker
-
user
protected UserModel user
-
-
Constructor Detail
-
FreeMarkerLoginFormsProvider
public FreeMarkerLoginFormsProvider(KeycloakSession session)
-
-
Method Detail
-
addScript
public void addScript(String scriptUrl)
Description copied from interface:LoginFormsProvider
Adds a script to the html header- Specified by:
addScript
in interfaceLoginFormsProvider
-
createResponse
public javax.ws.rs.core.Response createResponse(UserModel.RequiredAction action)
- Specified by:
createResponse
in interfaceLoginFormsProvider
-
createResponse
protected javax.ws.rs.core.Response createResponse(LoginFormsPages page)
-
createForm
public javax.ws.rs.core.Response createForm(String form)
- Specified by:
createForm
in interfaceLoginFormsProvider
-
prepareBaseUriBuilder
protected javax.ws.rs.core.UriBuilder prepareBaseUriBuilder(boolean resetRequestUriParams)
Prepare base uri builder for later use- Parameters:
resetRequestUriParams
- - for some reason Resteasy 2.3.7 doesn't like query params and form params with the same name and will null out the code form param, so we have to reset them for some pages- Returns:
- base uri builder
-
getTheme
protected Theme getTheme() throws IOException
Get Theme used for page rendering.- Returns:
- theme for page rendering, never null
- Throws:
IOException
- in case of Theme loading problem
-
handleThemeResources
protected Properties handleThemeResources(Theme theme, Locale locale)
Load message bundle and place it intomsg
template attribute. Also load Theme properties and place them intoproperties
template attribute.- Parameters:
theme
- actual Theme to load bundle fromlocale
- to load bundle for- Returns:
- message bundle for other use
-
handleMessages
protected void handleMessages(Locale locale, Properties messagesBundle)
Handle messages to be shown on the page - set them to template attributes- Parameters:
locale
- to be used for message text loadingmessagesBundle
- to be used for message text loading- See Also:
messageType
,messages
-
getMessage
public String getMessage(String message)
- Specified by:
getMessage
in interfaceLoginFormsProvider
-
createCommonAttributes
protected void createCommonAttributes(Theme theme, Locale locale, Properties messagesBundle, javax.ws.rs.core.UriBuilder baseUriBuilder, LoginFormsPages page)
Create common attributes used in all templates.- Parameters:
theme
- actual Theme used (provided bygetTheme()
)locale
- actual localemessagesBundle
- actual message bundle (provided byhandleThemeResources()
)baseUriBuilder
- actual base uri builder (provided byprepareBaseUriBuilder()
)page
- in case if common page is rendered, is null if called fromcreateForm()
-
processTemplate
protected javax.ws.rs.core.Response processTemplate(Theme theme, String templateName, Locale locale)
Process FreeMarker template and prepare Response. Some fields are used for rendering also.- Parameters:
theme
- to be used (provided bygetTheme()
)templateName
- name of the template to be renderedlocale
- to be used- Returns:
- Response object to be returned to the browser, never null
-
createLoginUsernamePassword
public javax.ws.rs.core.Response createLoginUsernamePassword()
- Specified by:
createLoginUsernamePassword
in interfaceLoginFormsProvider
-
createLoginUsername
public javax.ws.rs.core.Response createLoginUsername()
- Specified by:
createLoginUsername
in interfaceLoginFormsProvider
-
createLoginPassword
public javax.ws.rs.core.Response createLoginPassword()
- Specified by:
createLoginPassword
in interfaceLoginFormsProvider
-
createPasswordReset
public javax.ws.rs.core.Response createPasswordReset()
- Specified by:
createPasswordReset
in interfaceLoginFormsProvider
-
createLoginTotp
public javax.ws.rs.core.Response createLoginTotp()
- Specified by:
createLoginTotp
in interfaceLoginFormsProvider
-
createLoginRecoveryAuthnCode
public javax.ws.rs.core.Response createLoginRecoveryAuthnCode()
- Specified by:
createLoginRecoveryAuthnCode
in interfaceLoginFormsProvider
-
createLoginWebAuthn
public javax.ws.rs.core.Response createLoginWebAuthn()
- Specified by:
createLoginWebAuthn
in interfaceLoginFormsProvider
-
createRegistration
public javax.ws.rs.core.Response createRegistration()
- Specified by:
createRegistration
in interfaceLoginFormsProvider
-
createInfoPage
public javax.ws.rs.core.Response createInfoPage()
- Specified by:
createInfoPage
in interfaceLoginFormsProvider
-
createUpdateProfilePage
public javax.ws.rs.core.Response createUpdateProfilePage()
- Specified by:
createUpdateProfilePage
in interfaceLoginFormsProvider
-
createIdpLinkConfirmLinkPage
public javax.ws.rs.core.Response createIdpLinkConfirmLinkPage()
- Specified by:
createIdpLinkConfirmLinkPage
in interfaceLoginFormsProvider
-
createLoginExpiredPage
public javax.ws.rs.core.Response createLoginExpiredPage()
- Specified by:
createLoginExpiredPage
in interfaceLoginFormsProvider
-
createIdpLinkEmailPage
public javax.ws.rs.core.Response createIdpLinkEmailPage()
- Specified by:
createIdpLinkEmailPage
in interfaceLoginFormsProvider
-
createErrorPage
public javax.ws.rs.core.Response createErrorPage(javax.ws.rs.core.Response.Status status)
- Specified by:
createErrorPage
in interfaceLoginFormsProvider
-
createWebAuthnErrorPage
public javax.ws.rs.core.Response createWebAuthnErrorPage()
- Specified by:
createWebAuthnErrorPage
in interfaceLoginFormsProvider
-
createOAuthGrant
public javax.ws.rs.core.Response createOAuthGrant()
- Specified by:
createOAuthGrant
in interfaceLoginFormsProvider
-
createSelectAuthenticator
public javax.ws.rs.core.Response createSelectAuthenticator()
- Specified by:
createSelectAuthenticator
in interfaceLoginFormsProvider
-
createOAuth2DeviceVerifyUserCodePage
public javax.ws.rs.core.Response createOAuth2DeviceVerifyUserCodePage()
- Specified by:
createOAuth2DeviceVerifyUserCodePage
in interfaceLoginFormsProvider
-
createCode
public javax.ws.rs.core.Response createCode()
- Specified by:
createCode
in interfaceLoginFormsProvider
-
createX509ConfirmPage
public javax.ws.rs.core.Response createX509ConfirmPage()
- Specified by:
createX509ConfirmPage
in interfaceLoginFormsProvider
-
createSamlPostForm
public javax.ws.rs.core.Response createSamlPostForm()
- Specified by:
createSamlPostForm
in interfaceLoginFormsProvider
-
createFrontChannelLogoutPage
public javax.ws.rs.core.Response createFrontChannelLogoutPage()
- Specified by:
createFrontChannelLogoutPage
in interfaceLoginFormsProvider
-
createLogoutConfirmPage
public javax.ws.rs.core.Response createLogoutConfirmPage()
- Specified by:
createLogoutConfirmPage
in interfaceLoginFormsProvider
-
setMessage
protected void setMessage(MessageType type, String message, Object... parameters)
-
getFirstMessageUnformatted
protected String getFirstMessageUnformatted()
-
formatMessage
protected String formatMessage(FormMessage message, Properties messagesBundle, Locale locale)
-
setError
public FreeMarkerLoginFormsProvider setError(String message, Object... parameters)
Description copied from interface:LoginFormsProvider
Set one global error message.- Specified by:
setError
in interfaceLoginFormsProvider
- Parameters:
message
- key of messageparameters
- to be formatted into message
-
setErrors
public LoginFormsProvider setErrors(List<FormMessage> messages)
Description copied from interface:LoginFormsProvider
Set multiple error messages.- Specified by:
setErrors
in interfaceLoginFormsProvider
- Parameters:
messages
- to be set
-
addError
public LoginFormsProvider addError(FormMessage errorMessage)
- Specified by:
addError
in interfaceLoginFormsProvider
-
addSuccess
public LoginFormsProvider addSuccess(FormMessage errorMessage)
Description copied from interface:LoginFormsProvider
Add a success message to the form- Specified by:
addSuccess
in interfaceLoginFormsProvider
- Returns:
-
setSuccess
public FreeMarkerLoginFormsProvider setSuccess(String message, Object... parameters)
- Specified by:
setSuccess
in interfaceLoginFormsProvider
-
setInfo
public FreeMarkerLoginFormsProvider setInfo(String message, Object... parameters)
- Specified by:
setInfo
in interfaceLoginFormsProvider
-
setAuthenticationSession
public LoginFormsProvider setAuthenticationSession(AuthenticationSessionModel authenticationSession)
- Specified by:
setAuthenticationSession
in interfaceLoginFormsProvider
-
setUser
public FreeMarkerLoginFormsProvider setUser(UserModel user)
- Specified by:
setUser
in interfaceLoginFormsProvider
-
setFormData
public FreeMarkerLoginFormsProvider setFormData(javax.ws.rs.core.MultivaluedMap<String,String> formData)
- Specified by:
setFormData
in interfaceLoginFormsProvider
-
setClientSessionCode
public LoginFormsProvider setClientSessionCode(String accessCode)
- Specified by:
setClientSessionCode
in interfaceLoginFormsProvider
-
setAccessRequest
public LoginFormsProvider setAccessRequest(List<AuthorizationDetails> clientScopesRequested)
- Specified by:
setAccessRequest
in interfaceLoginFormsProvider
-
setAttribute
public LoginFormsProvider setAttribute(String name, Object value)
- Specified by:
setAttribute
in interfaceLoginFormsProvider
-
setStatus
public LoginFormsProvider setStatus(javax.ws.rs.core.Response.Status status)
- Specified by:
setStatus
in interfaceLoginFormsProvider
-
setActionUri
public LoginFormsProvider setActionUri(URI actionUri)
- Specified by:
setActionUri
in interfaceLoginFormsProvider
-
setExecution
public LoginFormsProvider setExecution(String execution)
- Specified by:
setExecution
in interfaceLoginFormsProvider
-
setResponseHeader
public LoginFormsProvider setResponseHeader(String headerName, String headerValue)
- Specified by:
setResponseHeader
in interfaceLoginFormsProvider
-
setAuthContext
public LoginFormsProvider setAuthContext(AuthenticationFlowContext context)
- Specified by:
setAuthContext
in interfaceLoginFormsProvider
-
-