Search in sources :

Example 1 with AccountBean

use of org.keycloak.forms.account.freemarker.model.AccountBean in project keycloak by keycloak.

the class FreeMarkerAccountProvider method createResponse.

@Override
public Response createResponse(AccountPages page) {
    Map<String, Object> attributes = new HashMap<>();
    if (this.attributes != null) {
        attributes.putAll(this.attributes);
    }
    Theme theme;
    try {
        theme = getTheme();
    } catch (IOException e) {
        logger.error("Failed to create theme", e);
        return Response.serverError().build();
    }
    Locale locale = session.getContext().resolveLocale(user);
    Properties messagesBundle = handleThemeResources(theme, locale, attributes);
    URI baseUri = uriInfo.getBaseUri();
    UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
    for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
        baseUriBuilder.queryParam(e.getKey(), e.getValue().toArray());
    }
    URI baseQueryUri = baseUriBuilder.build();
    if (stateChecker != null) {
        attributes.put("stateChecker", stateChecker);
    }
    handleMessages(locale, messagesBundle, attributes);
    if (referrer != null) {
        attributes.put("referrer", new ReferrerBean(referrer));
    }
    if (realm != null) {
        attributes.put("realm", new RealmBean(realm));
    }
    attributes.put("url", new UrlBean(realm, theme, baseUri, baseQueryUri, uriInfo.getRequestUri(), stateChecker));
    if (realm.isInternationalizationEnabled()) {
        UriBuilder b = UriBuilder.fromUri(baseQueryUri).path(uriInfo.getPath());
        attributes.put("locale", new LocaleBean(realm, locale, b, messagesBundle));
    }
    attributes.put("features", new FeaturesBean(identityProviderEnabled, eventsEnabled, passwordUpdateSupported, authorizationSupported));
    attributes.put("account", new AccountBean(user, profileFormData));
    switch(page) {
        case TOTP:
            attributes.put("totp", new TotpBean(session, realm, user, uriInfo.getRequestUriBuilder()));
            break;
        case FEDERATED_IDENTITY:
            attributes.put("federatedIdentity", new AccountFederatedIdentityBean(session, realm, user, uriInfo.getBaseUri(), stateChecker));
            break;
        case LOG:
            attributes.put("log", new LogBean(events));
            break;
        case SESSIONS:
            attributes.put("sessions", new SessionsBean(realm, sessions));
            break;
        case APPLICATIONS:
            attributes.put("applications", new ApplicationsBean(session, realm, user));
            attributes.put("advancedMsg", new AdvancedMessageFormatterMethod(locale, messagesBundle));
            break;
        case PASSWORD:
            attributes.put("password", new PasswordBean(passwordSet));
            break;
        case RESOURCES:
            if (!realm.isUserManagedAccessAllowed()) {
                return Response.status(Status.FORBIDDEN).build();
            }
            attributes.put("authorization", new AuthorizationBean(session, user, uriInfo));
        case RESOURCE_DETAIL:
            if (!realm.isUserManagedAccessAllowed()) {
                return Response.status(Status.FORBIDDEN).build();
            }
            attributes.put("authorization", new AuthorizationBean(session, user, uriInfo));
    }
    return processTemplate(theme, page, attributes, locale);
}
Also used : Locale(java.util.Locale) ApplicationsBean(org.keycloak.forms.account.freemarker.model.ApplicationsBean) AccountFederatedIdentityBean(org.keycloak.forms.account.freemarker.model.AccountFederatedIdentityBean) PasswordBean(org.keycloak.forms.account.freemarker.model.PasswordBean) HashMap(java.util.HashMap) Properties(java.util.Properties) FeaturesBean(org.keycloak.forms.account.freemarker.model.FeaturesBean) URI(java.net.URI) LocaleBean(org.keycloak.theme.beans.LocaleBean) UrlBean(org.keycloak.forms.account.freemarker.model.UrlBean) TotpBean(org.keycloak.forms.account.freemarker.model.TotpBean) RealmBean(org.keycloak.forms.account.freemarker.model.RealmBean) ArrayList(java.util.ArrayList) List(java.util.List) UriBuilder(javax.ws.rs.core.UriBuilder) AccountBean(org.keycloak.forms.account.freemarker.model.AccountBean) AdvancedMessageFormatterMethod(org.keycloak.theme.beans.AdvancedMessageFormatterMethod) SessionsBean(org.keycloak.forms.account.freemarker.model.SessionsBean) IOException(java.io.IOException) AuthorizationBean(org.keycloak.forms.account.freemarker.model.AuthorizationBean) Theme(org.keycloak.theme.Theme) LogBean(org.keycloak.forms.account.freemarker.model.LogBean) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) ReferrerBean(org.keycloak.forms.account.freemarker.model.ReferrerBean)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Properties (java.util.Properties)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 AccountBean (org.keycloak.forms.account.freemarker.model.AccountBean)1 AccountFederatedIdentityBean (org.keycloak.forms.account.freemarker.model.AccountFederatedIdentityBean)1 ApplicationsBean (org.keycloak.forms.account.freemarker.model.ApplicationsBean)1 AuthorizationBean (org.keycloak.forms.account.freemarker.model.AuthorizationBean)1 FeaturesBean (org.keycloak.forms.account.freemarker.model.FeaturesBean)1 LogBean (org.keycloak.forms.account.freemarker.model.LogBean)1 PasswordBean (org.keycloak.forms.account.freemarker.model.PasswordBean)1 RealmBean (org.keycloak.forms.account.freemarker.model.RealmBean)1 ReferrerBean (org.keycloak.forms.account.freemarker.model.ReferrerBean)1 SessionsBean (org.keycloak.forms.account.freemarker.model.SessionsBean)1