Search in sources :

Example 1 with AuthenticationContextBean

use of org.keycloak.forms.login.freemarker.model.AuthenticationContextBean in project keycloak by keycloak.

the class FreeMarkerLoginFormsProvider method createCommonAttributes.

/**
 * Create common attributes used in all templates.
 *
 * @param theme actual Theme used (provided by <code>getTheme()</code>)
 * @param locale actual locale
 * @param messagesBundle actual message bundle (provided by <code>handleThemeResources()</code>)
 * @param baseUriBuilder actual base uri builder (provided by <code>prepareBaseUriBuilder()</code>)
 * @param page in case if common page is rendered, is null if called from <code>createForm()</code>
 */
protected void createCommonAttributes(Theme theme, Locale locale, Properties messagesBundle, UriBuilder baseUriBuilder, LoginFormsPages page) {
    URI baseUri = baseUriBuilder.build();
    if (accessCode != null) {
        baseUriBuilder.queryParam(LoginActionsService.SESSION_CODE, accessCode);
    }
    URI baseUriWithCodeAndClientId = baseUriBuilder.build();
    if (client != null) {
        attributes.put("client", new ClientBean(session, client));
    }
    if (realm != null) {
        attributes.put("realm", new RealmBean(realm));
        List<IdentityProviderModel> identityProviders = LoginFormsUtil.filterIdentityProviders(realm.getIdentityProvidersStream(), session, context);
        attributes.put("social", new IdentityProviderBean(realm, session, identityProviders, baseUriWithCodeAndClientId));
        attributes.put("url", new UrlBean(realm, theme, baseUri, this.actionUri));
        attributes.put("requiredActionUrl", new RequiredActionUrlFormatterMethod(realm, baseUri));
        attributes.put("auth", new AuthenticationContextBean(context, page));
        attributes.put(Constants.EXECUTION, execution);
        if (realm.isInternationalizationEnabled()) {
            UriBuilder b;
            if (page != null) {
                switch(page) {
                    case LOGIN:
                    case LOGIN_USERNAME:
                    case X509_CONFIRM:
                        b = UriBuilder.fromUri(Urls.realmLoginPage(baseUri, realm.getName()));
                        break;
                    case REGISTER:
                        b = UriBuilder.fromUri(Urls.realmRegisterPage(baseUri, realm.getName()));
                        break;
                    default:
                        b = UriBuilder.fromUri(baseUri).path(uriInfo.getPath());
                        break;
                }
            } else {
                b = UriBuilder.fromUri(baseUri).path(uriInfo.getPath());
            }
            if (execution != null) {
                b.queryParam(Constants.EXECUTION, execution);
            }
            if (authenticationSession != null && authenticationSession.getAuthNote(Constants.KEY) != null) {
                b.queryParam(Constants.KEY, authenticationSession.getAuthNote(Constants.KEY));
            }
            attributes.put("locale", new LocaleBean(realm, locale, b, messagesBundle));
        }
    }
    if (realm != null && user != null && session != null) {
        attributes.put("authenticatorConfigured", new AuthenticatorConfiguredMethod(realm, user, session));
    }
    if (authenticationSession != null && authenticationSession.getClientNote(Constants.KC_ACTION_EXECUTING) != null) {
        attributes.put("isAppInitiatedAction", true);
    }
}
Also used : RequiredActionUrlFormatterMethod(org.keycloak.forms.login.freemarker.model.RequiredActionUrlFormatterMethod) IdentityProviderBean(org.keycloak.forms.login.freemarker.model.IdentityProviderBean) ClientBean(org.keycloak.forms.login.freemarker.model.ClientBean) UrlBean(org.keycloak.forms.login.freemarker.model.UrlBean) AuthenticationContextBean(org.keycloak.forms.login.freemarker.model.AuthenticationContextBean) RealmBean(org.keycloak.forms.login.freemarker.model.RealmBean) IdentityProviderModel(org.keycloak.models.IdentityProviderModel) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) LocaleBean(org.keycloak.theme.beans.LocaleBean)

Aggregations

URI (java.net.URI)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 AuthenticationContextBean (org.keycloak.forms.login.freemarker.model.AuthenticationContextBean)1 ClientBean (org.keycloak.forms.login.freemarker.model.ClientBean)1 IdentityProviderBean (org.keycloak.forms.login.freemarker.model.IdentityProviderBean)1 RealmBean (org.keycloak.forms.login.freemarker.model.RealmBean)1 RequiredActionUrlFormatterMethod (org.keycloak.forms.login.freemarker.model.RequiredActionUrlFormatterMethod)1 UrlBean (org.keycloak.forms.login.freemarker.model.UrlBean)1 IdentityProviderModel (org.keycloak.models.IdentityProviderModel)1 LocaleBean (org.keycloak.theme.beans.LocaleBean)1