org.keycloak.forms.login.freemarker

## 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 and Description
    --- | ---
    `protected String` | `accessCode`
    `protected URI` | `actionUri`
    `protected Map<String,Object>` | `attributes`
    `protected AuthenticationSessionModel` | `authenticationSession` authenticationSession can be null for some renderings, mainly error pages
    `protected ClientModel` | `client`
    `protected List<ClientScopeModel>` | `clientScopesRequested`
    `protected javax.ws.rs.core.MediaType` | `contentType`
    `protected AuthenticationFlowContext` | `context`
    `protected String` | `execution`
    `protected javax.ws.rs.core.MultivaluedMap<String,String>` | `formData`
    `protected FreeMarkerUtil` | `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_EDIT_DISABLED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FreeMarkerLoginFormsProvider(KeycloakSession session, FreeMarkerUtil freeMarker)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `LoginFormsProvider` | `addError(FormMessage errorMessage)`
    `void` | `addScript(String scriptUrl)` Adds a script to the html header
    `LoginFormsProvider` | `addSuccess(FormMessage errorMessage)` Add a success message to the form
    `void` | `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` | `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` | `createLoginTotp()`
    `javax.ws.rs.core.Response` | `createLoginUsername()`
    `javax.ws.rs.core.Response` | `createLoginUsernamePassword()`
    `javax.ws.rs.core.Response` | `createLoginWebAuthn()`
    `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)`
    `String` | `getMessage(String message, String... parameters)`
    `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 attributes
    `protected Properties` | `handleThemeResources(Theme theme, Locale locale)` Load message bundle and place it into `msg` template attribute.
    `protected javax.ws.rs.core.UriBuilder` | `prepareBaseUriBuilder(boolean resetRequestUriParams)` Prepare base uri builder for later use
    `protected javax.ws.rs.core.Response` | `processTemplate(Theme theme, String templateName, Locale locale)` Process FreeMarker template and prepare Response.
    `LoginFormsProvider` | `setAccessRequest(List<ClientScopeModel> 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)`
    `LoginFormsProvider` | `setMediaType(javax.ws.rs.core.MediaType type)`
    `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)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### accessCode

          protected String accessCode

    - #### status

          protected javax.ws.rs.core.Response.Status status

    - #### contentType

          protected javax.ws.rs.core.MediaType contentType

    - #### clientScopesRequested

          protected List<ClientScopeModel> clientScopesRequested

    - #### httpResponseHeaders

          protected Map<String,String> httpResponseHeaders

    - #### actionUri

          protected URI actionUri

    - #### execution

          protected String execution

    - #### context

          protected AuthenticationFlowContext context

    - #### messages

          protected List<FormMessage> messages

    - #### messageType

          protected MessageType messageType

    - #### formData

          protected javax.ws.rs.core.MultivaluedMap<String,String> formData

    - #### 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 FreeMarkerUtil freeMarker

    - #### user

          protected UserModel user

    - #### attributes

          protected final Map<String,Object> attributes

  - ### Constructor Detail

    - #### FreeMarkerLoginFormsProvider

          public FreeMarkerLoginFormsProvider(KeycloakSession session,
                                              FreeMarkerUtil freeMarker)

  - ### Method Detail

    - #### addScript

          public void addScript(String scriptUrl)

      Description copied from interface: `LoginFormsProvider`
      Adds a script to the html header
      Specified by:
        `addScript` in interface `LoginFormsProvider`

    - #### createResponse

          public javax.ws.rs.core.Response createResponse(UserModel.RequiredAction action)

      Specified by:
        `createResponse` in interface `LoginFormsProvider`

    - #### createResponse

          protected javax.ws.rs.core.Response createResponse(LoginFormsPages page)

    - #### createForm

          public javax.ws.rs.core.Response createForm(String form)

      Specified by:
        `createForm` in interface `LoginFormsProvider`

    - #### 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 into `msg` template attribute. Also load Theme properties and place them into `properties` template attribute.
      Parameters:
        `theme` - actual Theme to load bundle from
        `locale` - 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 loading
        `messagesBundle` - to be used for message text loading
      See Also:
        `messageType`, `messages`

    - #### getMessage

          public String getMessage(String message)

      Specified by:
        `getMessage` in interface `LoginFormsProvider`

    - #### getMessage

          public String getMessage(String message,
                                   String... parameters)

      Specified by:
        `getMessage` in interface `LoginFormsProvider`

    - #### 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 by `getTheme()`)
        `locale` - actual locale
        `messagesBundle` - actual message bundle (provided by `handleThemeResources()`)
        `baseUriBuilder` - actual base uri builder (provided by `prepareBaseUriBuilder()`)
        `page` - in case if common page is rendered, is null if called from `createForm()`

    - #### 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 by `getTheme()`)
        `templateName` - name of the template to be rendered
        `locale` - 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 interface `LoginFormsProvider`

    - #### createLoginUsername

          public javax.ws.rs.core.Response createLoginUsername()

      Specified by:
        `createLoginUsername` in interface `LoginFormsProvider`

    - #### createLoginPassword

          public javax.ws.rs.core.Response createLoginPassword()

      Specified by:
        `createLoginPassword` in interface `LoginFormsProvider`

    - #### createPasswordReset

          public javax.ws.rs.core.Response createPasswordReset()

      Specified by:
        `createPasswordReset` in interface `LoginFormsProvider`

    - #### createLoginTotp

          public javax.ws.rs.core.Response createLoginTotp()

      Specified by:
        `createLoginTotp` in interface `LoginFormsProvider`

    - #### createLoginWebAuthn

          public javax.ws.rs.core.Response createLoginWebAuthn()

      Specified by:
        `createLoginWebAuthn` in interface `LoginFormsProvider`

    - #### createRegistration

          public javax.ws.rs.core.Response createRegistration()

      Specified by:
        `createRegistration` in interface `LoginFormsProvider`

    - #### createInfoPage

          public javax.ws.rs.core.Response createInfoPage()

      Specified by:
        `createInfoPage` in interface `LoginFormsProvider`

    - #### createUpdateProfilePage

          public javax.ws.rs.core.Response createUpdateProfilePage()

      Specified by:
        `createUpdateProfilePage` in interface `LoginFormsProvider`

    - #### createIdpLinkConfirmLinkPage

          public javax.ws.rs.core.Response createIdpLinkConfirmLinkPage()

      Specified by:
        `createIdpLinkConfirmLinkPage` in interface `LoginFormsProvider`

    - #### createLoginExpiredPage

          public javax.ws.rs.core.Response createLoginExpiredPage()

      Specified by:
        `createLoginExpiredPage` in interface `LoginFormsProvider`

    - #### createIdpLinkEmailPage

          public javax.ws.rs.core.Response createIdpLinkEmailPage()

      Specified by:
        `createIdpLinkEmailPage` in interface `LoginFormsProvider`

    - #### createErrorPage

          public javax.ws.rs.core.Response createErrorPage(javax.ws.rs.core.Response.Status status)

      Specified by:
        `createErrorPage` in interface `LoginFormsProvider`

    - #### createWebAuthnErrorPage

          public javax.ws.rs.core.Response createWebAuthnErrorPage()

      Specified by:
        `createWebAuthnErrorPage` in interface `LoginFormsProvider`

    - #### createOAuthGrant

          public javax.ws.rs.core.Response createOAuthGrant()

      Specified by:
        `createOAuthGrant` in interface `LoginFormsProvider`

    - #### createSelectAuthenticator

          public javax.ws.rs.core.Response createSelectAuthenticator()

      Specified by:
        `createSelectAuthenticator` in interface `LoginFormsProvider`

    - #### createOAuth2DeviceVerifyUserCodePage

          public javax.ws.rs.core.Response createOAuth2DeviceVerifyUserCodePage()

      Specified by:
        `createOAuth2DeviceVerifyUserCodePage` in interface `LoginFormsProvider`

    - #### createCode

          public javax.ws.rs.core.Response createCode()

      Specified by:
        `createCode` in interface `LoginFormsProvider`

    - #### createX509ConfirmPage

          public javax.ws.rs.core.Response createX509ConfirmPage()

      Specified by:
        `createX509ConfirmPage` in interface `LoginFormsProvider`

    - #### createSamlPostForm

          public javax.ws.rs.core.Response createSamlPostForm()

      Specified by:
        `createSamlPostForm` in interface `LoginFormsProvider`

    - #### 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 interface `LoginFormsProvider`
      Parameters:
        `message` - key of message
        `parameters` - 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 interface `LoginFormsProvider`
      Parameters:
        `messages` - to be set

    - #### addError

          public LoginFormsProvider addError(FormMessage errorMessage)

      Specified by:
        `addError` in interface `LoginFormsProvider`

    - #### addSuccess

          public LoginFormsProvider addSuccess(FormMessage errorMessage)

      Description copied from interface: `LoginFormsProvider`
      Add a success message to the form
      Specified by:
        `addSuccess` in interface `LoginFormsProvider`
      Returns:

    - #### setSuccess

          public FreeMarkerLoginFormsProvider setSuccess(String message,
                                                         Object... parameters)

      Specified by:
        `setSuccess` in interface `LoginFormsProvider`

    - #### setInfo

          public FreeMarkerLoginFormsProvider setInfo(String message,
                                                      Object... parameters)

      Specified by:
        `setInfo` in interface `LoginFormsProvider`

    - #### setAuthenticationSession

          public LoginFormsProvider setAuthenticationSession(AuthenticationSessionModel authenticationSession)

      Specified by:
        `setAuthenticationSession` in interface `LoginFormsProvider`

    - #### setUser

          public FreeMarkerLoginFormsProvider setUser(UserModel user)

      Specified by:
        `setUser` in interface `LoginFormsProvider`

    - #### setFormData

          public FreeMarkerLoginFormsProvider setFormData(javax.ws.rs.core.MultivaluedMap<String,String> formData)

      Specified by:
        `setFormData` in interface `LoginFormsProvider`

    - #### setClientSessionCode

          public LoginFormsProvider setClientSessionCode(String accessCode)

      Specified by:
        `setClientSessionCode` in interface `LoginFormsProvider`

    - #### setAccessRequest

          public LoginFormsProvider setAccessRequest(List<ClientScopeModel> clientScopesRequested)

      Specified by:
        `setAccessRequest` in interface `LoginFormsProvider`

    - #### setAttribute

          public LoginFormsProvider setAttribute(String name,
                                                 Object value)

      Specified by:
        `setAttribute` in interface `LoginFormsProvider`

    - #### setStatus

          public LoginFormsProvider setStatus(javax.ws.rs.core.Response.Status status)

      Specified by:
        `setStatus` in interface `LoginFormsProvider`

    - #### setMediaType

          public LoginFormsProvider setMediaType(javax.ws.rs.core.MediaType type)

      Specified by:
        `setMediaType` in interface `LoginFormsProvider`

    - #### setActionUri

          public LoginFormsProvider setActionUri(URI actionUri)

      Specified by:
        `setActionUri` in interface `LoginFormsProvider`

    - #### setExecution

          public LoginFormsProvider setExecution(String execution)

      Specified by:
        `setExecution` in interface `LoginFormsProvider`

    - #### setResponseHeader

          public LoginFormsProvider setResponseHeader(String headerName,
                                                      String headerValue)

      Specified by:
        `setResponseHeader` in interface `LoginFormsProvider`

    - #### setAuthContext

          public LoginFormsProvider setAuthContext(AuthenticationFlowContext context)

      Specified by:
        `setAuthContext` in interface `LoginFormsProvider`

    - #### close

          public void close()

      Specified by:
        `close` in interface `Provider`

Copyright © 2021 JBoss by Red Hat. All rights reserved.