Search in sources :

Example 1 with LocaleUpdaterProvider

use of org.keycloak.locale.LocaleUpdaterProvider in project keycloak by keycloak.

the class UpdateUserLocaleAction method evaluateTriggers.

@Override
public void evaluateTriggers(RequiredActionContext context) {
    String userRequestedLocale = context.getAuthenticationSession().getAuthNote(LocaleSelectorProvider.USER_REQUEST_LOCALE);
    if (userRequestedLocale != null) {
        LocaleUpdaterProvider updater = context.getSession().getProvider(LocaleUpdaterProvider.class);
        updater.updateUsersLocale(context.getUser(), userRequestedLocale);
    } else {
        String userLocale = context.getUser().getFirstAttribute(UserModel.LOCALE);
        if (userLocale != null) {
            LocaleUpdaterProvider updater = context.getSession().getProvider(LocaleUpdaterProvider.class);
            updater.updateLocaleCookie(userLocale);
        } else {
            LocaleUpdaterProvider updater = context.getSession().getProvider(LocaleUpdaterProvider.class);
            updater.expireLocaleCookie();
        }
    }
}
Also used : LocaleUpdaterProvider(org.keycloak.locale.LocaleUpdaterProvider)

Example 2 with LocaleUpdaterProvider

use of org.keycloak.locale.LocaleUpdaterProvider in project keycloak by keycloak.

the class AccountFormService method forwardToPage.

private Response forwardToPage(String path, AccountPages page) {
    if (auth != null) {
        try {
            auth.require(AccountRoles.MANAGE_ACCOUNT);
        } catch (ForbiddenException e) {
            return session.getProvider(LoginFormsProvider.class).setError(Messages.NO_ACCESS).createErrorPage(Response.Status.FORBIDDEN);
        }
        setReferrerOnPage();
        UserSessionModel userSession = auth.getSession();
        String tabId = session.getContext().getUri().getQueryParameters().getFirst(org.keycloak.models.Constants.TAB_ID);
        if (tabId != null) {
            AuthenticationSessionModel authSession = new AuthenticationSessionManager(session).getAuthenticationSessionByIdAndClient(realm, userSession.getId(), client, tabId);
            if (authSession != null) {
                String forwardedError = authSession.getAuthNote(ACCOUNT_MGMT_FORWARDED_ERROR_NOTE);
                if (forwardedError != null) {
                    try {
                        FormMessage errorMessage = JsonSerialization.readValue(forwardedError, FormMessage.class);
                        account.setError(Response.Status.INTERNAL_SERVER_ERROR, errorMessage.getMessage(), errorMessage.getParameters());
                        authSession.removeAuthNote(ACCOUNT_MGMT_FORWARDED_ERROR_NOTE);
                    } catch (IOException ioe) {
                        throw new RuntimeException(ioe);
                    }
                }
            }
        }
        String locale = session.getContext().getUri().getQueryParameters().getFirst(LocaleSelectorProvider.KC_LOCALE_PARAM);
        if (locale != null) {
            LocaleUpdaterProvider updater = session.getProvider(LocaleUpdaterProvider.class);
            updater.updateUsersLocale(auth.getUser(), locale);
        }
        return account.createResponse(page);
    } else {
        return login(path);
    }
}
Also used : AuthenticationSessionManager(org.keycloak.services.managers.AuthenticationSessionManager) ForbiddenException(org.keycloak.services.ForbiddenException) LoginFormsProvider(org.keycloak.forms.login.LoginFormsProvider) UserSessionModel(org.keycloak.models.UserSessionModel) AuthenticationSessionModel(org.keycloak.sessions.AuthenticationSessionModel) LocaleUpdaterProvider(org.keycloak.locale.LocaleUpdaterProvider) IOException(java.io.IOException) FormMessage(org.keycloak.models.utils.FormMessage)

Example 3 with LocaleUpdaterProvider

use of org.keycloak.locale.LocaleUpdaterProvider in project keycloak by keycloak.

the class LoginActionsService method processLocaleParam.

protected void processLocaleParam(AuthenticationSessionModel authSession) {
    if (authSession != null && realm.isInternationalizationEnabled()) {
        String locale = session.getContext().getUri().getQueryParameters().getFirst(LocaleSelectorProvider.KC_LOCALE_PARAM);
        if (locale != null) {
            authSession.setAuthNote(LocaleSelectorProvider.USER_REQUEST_LOCALE, locale);
            LocaleUpdaterProvider localeUpdater = session.getProvider(LocaleUpdaterProvider.class);
            localeUpdater.updateLocaleCookie(locale);
        }
    }
}
Also used : LocaleUpdaterProvider(org.keycloak.locale.LocaleUpdaterProvider)

Aggregations

LocaleUpdaterProvider (org.keycloak.locale.LocaleUpdaterProvider)3 IOException (java.io.IOException)1 LoginFormsProvider (org.keycloak.forms.login.LoginFormsProvider)1 UserSessionModel (org.keycloak.models.UserSessionModel)1 FormMessage (org.keycloak.models.utils.FormMessage)1 ForbiddenException (org.keycloak.services.ForbiddenException)1 AuthenticationSessionManager (org.keycloak.services.managers.AuthenticationSessionManager)1 AuthenticationSessionModel (org.keycloak.sessions.AuthenticationSessionModel)1