Search in sources :

Example 1 with VerifyProfileBean

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

the class FreeMarkerLoginFormsProvider method createResponse.

@SuppressWarnings("incomplete-switch")
protected Response createResponse(LoginFormsPages page) {
    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);
    handleMessages(locale, messagesBundle);
    // 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
    UriBuilder uriBuilder = prepareBaseUriBuilder(page == LoginFormsPages.OAUTH_GRANT);
    createCommonAttributes(theme, locale, messagesBundle, uriBuilder, page);
    attributes.put("login", new LoginBean(formData));
    if (status != null) {
        attributes.put("statusCode", status.getStatusCode());
    }
    switch(page) {
        case LOGIN_CONFIG_TOTP:
            attributes.put("totp", new TotpBean(session, realm, user, uriInfo.getRequestUriBuilder()));
            break;
        case LOGIN_UPDATE_PROFILE:
            UpdateProfileContext userCtx = (UpdateProfileContext) attributes.get(LoginFormsProvider.UPDATE_PROFILE_CONTEXT_ATTR);
            attributes.put("user", new ProfileBean(userCtx, formData));
            break;
        case LOGIN_IDP_LINK_CONFIRM:
        case LOGIN_IDP_LINK_EMAIL:
            BrokeredIdentityContext brokerContext = (BrokeredIdentityContext) this.attributes.get(IDENTITY_PROVIDER_BROKER_CONTEXT);
            String idpAlias = brokerContext.getIdpConfig().getAlias();
            idpAlias = ObjectUtil.capitalize(idpAlias);
            String displayName = idpAlias;
            if (!ObjectUtil.isBlank(brokerContext.getIdpConfig().getDisplayName())) {
                displayName = brokerContext.getIdpConfig().getDisplayName();
            }
            attributes.put("brokerContext", brokerContext);
            attributes.put("idpAlias", idpAlias);
            attributes.put("idpDisplayName", displayName);
            break;
        case LOGIN_TOTP:
            attributes.put("otpLogin", new TotpLoginBean(session, realm, user, (String) this.attributes.get(OTPFormAuthenticator.SELECTED_OTP_CREDENTIAL_ID)));
            break;
        case REGISTER:
            if (isDynamicUserProfile()) {
                page = LoginFormsPages.REGISTER_USER_PROFILE;
            }
            RegisterBean rb = new RegisterBean(formData, session);
            // legacy bean for static template
            attributes.put("register", rb);
            // bean for dynamic template
            attributes.put("profile", rb);
            break;
        case OAUTH_GRANT:
            attributes.put("oauth", new OAuthGrantBean(accessCode, client, clientScopesRequested));
            break;
        case CODE:
            attributes.put(OAuth2Constants.CODE, new CodeBean(accessCode, messageType == MessageType.ERROR ? getFirstMessageUnformatted() : null));
            break;
        case X509_CONFIRM:
            attributes.put("x509", new X509ConfirmBean(formData));
            break;
        case SAML_POST_FORM:
            attributes.put("samlPost", new SAMLPostFormBean(formData));
            break;
        case UPDATE_USER_PROFILE:
            attributes.put("profile", new VerifyProfileBean(user, formData, session));
            break;
        case IDP_REVIEW_USER_PROFILE:
            UpdateProfileContext idpCtx = (UpdateProfileContext) attributes.get(LoginFormsProvider.UPDATE_PROFILE_CONTEXT_ATTR);
            attributes.put("profile", new IdpReviewProfileBean(idpCtx, formData, session));
            break;
        case FRONTCHANNEL_LOGOUT:
            attributes.put("logout", new FrontChannelLogoutBean(session));
            break;
    }
    return processTemplate(theme, Templates.getTemplate(page), locale);
}
Also used : Locale(java.util.Locale) ProfileBean(org.keycloak.forms.login.freemarker.model.ProfileBean) IdpReviewProfileBean(org.keycloak.forms.login.freemarker.model.IdpReviewProfileBean) VerifyProfileBean(org.keycloak.forms.login.freemarker.model.VerifyProfileBean) OAuthGrantBean(org.keycloak.forms.login.freemarker.model.OAuthGrantBean) CodeBean(org.keycloak.forms.login.freemarker.model.CodeBean) RegisterBean(org.keycloak.forms.login.freemarker.model.RegisterBean) IOException(java.io.IOException) FrontChannelLogoutBean(org.keycloak.forms.login.freemarker.model.FrontChannelLogoutBean) Properties(java.util.Properties) BrokeredIdentityContext(org.keycloak.broker.provider.BrokeredIdentityContext) VerifyProfileBean(org.keycloak.forms.login.freemarker.model.VerifyProfileBean) UpdateProfileContext(org.keycloak.authentication.requiredactions.util.UpdateProfileContext) UserUpdateProfileContext(org.keycloak.authentication.requiredactions.util.UserUpdateProfileContext) TotpBean(org.keycloak.forms.login.freemarker.model.TotpBean) TotpLoginBean(org.keycloak.forms.login.freemarker.model.TotpLoginBean) X509ConfirmBean(org.keycloak.forms.login.freemarker.model.X509ConfirmBean) LoginBean(org.keycloak.forms.login.freemarker.model.LoginBean) TotpLoginBean(org.keycloak.forms.login.freemarker.model.TotpLoginBean) SAMLPostFormBean(org.keycloak.forms.login.freemarker.model.SAMLPostFormBean) Theme(org.keycloak.theme.Theme) IdpReviewProfileBean(org.keycloak.forms.login.freemarker.model.IdpReviewProfileBean) UriBuilder(javax.ws.rs.core.UriBuilder)

Aggregations

IOException (java.io.IOException)1 Locale (java.util.Locale)1 Properties (java.util.Properties)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 UpdateProfileContext (org.keycloak.authentication.requiredactions.util.UpdateProfileContext)1 UserUpdateProfileContext (org.keycloak.authentication.requiredactions.util.UserUpdateProfileContext)1 BrokeredIdentityContext (org.keycloak.broker.provider.BrokeredIdentityContext)1 CodeBean (org.keycloak.forms.login.freemarker.model.CodeBean)1 FrontChannelLogoutBean (org.keycloak.forms.login.freemarker.model.FrontChannelLogoutBean)1 IdpReviewProfileBean (org.keycloak.forms.login.freemarker.model.IdpReviewProfileBean)1 LoginBean (org.keycloak.forms.login.freemarker.model.LoginBean)1 OAuthGrantBean (org.keycloak.forms.login.freemarker.model.OAuthGrantBean)1 ProfileBean (org.keycloak.forms.login.freemarker.model.ProfileBean)1 RegisterBean (org.keycloak.forms.login.freemarker.model.RegisterBean)1 SAMLPostFormBean (org.keycloak.forms.login.freemarker.model.SAMLPostFormBean)1 TotpBean (org.keycloak.forms.login.freemarker.model.TotpBean)1 TotpLoginBean (org.keycloak.forms.login.freemarker.model.TotpLoginBean)1 VerifyProfileBean (org.keycloak.forms.login.freemarker.model.VerifyProfileBean)1 X509ConfirmBean (org.keycloak.forms.login.freemarker.model.X509ConfirmBean)1 Theme (org.keycloak.theme.Theme)1