add i18n for messages in account pages

This commit is contained in:
Michael Gerber
2015-02-28 19:49:13 +01:00
parent 8b60c9633d
commit 9849d94a90
6 changed files with 74 additions and 27 deletions

View File

@@ -24,11 +24,11 @@ public interface AccountProvider extends Provider {
Response createResponse(AccountPages page);
AccountProvider setError(String message);
AccountProvider setError(String message, Object ... parameters);
AccountProvider setSuccess(String message);
AccountProvider setSuccess(String message, Object ... parameters);
AccountProvider setWarning(String message);
AccountProvider setWarning(String message, Object ... parameters);
AccountProvider setUser(UserModel user);

View File

@@ -15,6 +15,7 @@ import org.keycloak.services.resources.flows.Urls;
import javax.ws.rs.core.*;
import java.io.IOException;
import java.net.URI;
import java.text.MessageFormat;
import java.util.*;
/**
@@ -45,6 +46,7 @@ public class FreeMarkerAccountProvider implements AccountProvider {
private UriInfo uriInfo;
private String message;
private Object[] parameters;
private MessageType messageType;
public FreeMarkerAccountProvider(KeycloakSession session, FreeMarkerUtil freeMarker) {
@@ -107,7 +109,13 @@ public class FreeMarkerAccountProvider implements AccountProvider {
}
if (message != null) {
attributes.put("message", new MessageBean(messages.containsKey(message) ? messages.getProperty(message) : message, messageType));
String formattedMessage;
if(messages.containsKey(message)){
formattedMessage = new MessageFormat(messages.getProperty(message),locale).format(parameters);
}else{
formattedMessage = message;
}
attributes.put("message", new MessageBean(formattedMessage, messageType));
}
if (referrer != null) {
@@ -160,22 +168,25 @@ public class FreeMarkerAccountProvider implements AccountProvider {
}
@Override
public AccountProvider setError(String message) {
public AccountProvider setError(String message, Object ... parameters) {
this.message = message;
this.parameters = parameters;
this.messageType = MessageType.ERROR;
return this;
}
@Override
public AccountProvider setSuccess(String message) {
public AccountProvider setSuccess(String message, Object ... parameters) {
this.message = message;
this.parameters = parameters;
this.messageType = MessageType.SUCCESS;
return this;
}
@Override
public AccountProvider setWarning(String message) {
public AccountProvider setWarning(String message, Object ... parameters) {
this.message = message;
this.parameters = parameters;
this.messageType = MessageType.WARNING;
return this;
}

View File

@@ -37,7 +37,13 @@ federatedIdentityRemovingLastProvider=You can't remove last federated identity a
identityProviderRedirectError=Failed to redirect to identity provider
identityProviderRemoved=Identity provider removed successfully
accountDisabled=Account is disabled, contact admin\
accountDisabled=Account is disabled, contact admin
accountTemporarilyDisabled=Account is temporarily disabled, contact admin or try again later
logOutAllSessions=Log out all sessions
invalidPasswordMinLength=Invalid password: minimum length {0}
invalidPasswordMinDigits=Invalid password\: must contain at least {0} numerical digits
invalidPasswordMinLowerCaseChars=Invalid password: must contain at least {0} lower case characters
invalidPasswordMinUpperCaseChars=Invalid password: must contain at least {0} upper case characters
invalidPasswordMinSpecialChars=Invalid password: must contain at least {0} special characters

View File

@@ -118,7 +118,7 @@ accountUpdated=Your account has been updated
accountPasswordUpdated=Your password has been updated
identityProviderUnexpectedError=Unexpected error when authenticating with identity provider
identityProviderNotFound="Could not find an identity provider with the identifier [{0}]."
identityProviderNotFound=Could not find an identity provider with the identifier [{0}].
identityProviderNoToken=Could not obtain token from identity provider [{0}].
realmSupportsNoCredentials=Realm [{0}] does not support any credential type.
identityProviderNotUnique=Realm [{0}] supports multiple identity providers. Could not determine which identity provider should be used to authenticate with.
@@ -126,7 +126,7 @@ identityProviderNotUnique=Realm [{0}] supports multiple identity providers. Coul
noAccess=No access
invalidPasswordMinLength=Invalid password: minimum length {0}
invalidPasswordMinDigits=Invalid password: must contain at least {0} numerical digits
invalidPasswordMinDigits=Invalid password\: must contain at least {0} numerical digits
invalidPasswordMinLowerCaseChars=Invalid password: must contain at least {0} lower case characters
invalidPasswordMinUpperCaseChars=Invalid password: must contain at least {0} upper case characters
invalidPasswordMinSpecialChars=Invalid password: must contain at least {0} special characters

View File

@@ -116,7 +116,46 @@ emailInstruction=Enter your username or email address and we will send you instr
accountUpdated=Your account has been updated
accountPasswordUpdated=Your password has been updated
identityProviderNotFound="Could not find an identity provider with the identifier [{0}]."
noAccess=No access
invalidPasswordMinLength=Invalid password: minimum length {0}
invalidPasswordMinDigits=Invalid password\: must contain at least {0} numerical digits
invalidPasswordMinLowerCaseChars=Invalid password: must contain at least {0} lower case characters
invalidPasswordMinUpperCaseChars=Invalid password: must contain at least {0} upper case characters
invalidPasswordMinSpecialChars=Invalid password: must contain at least {0} special characters
failedToProcessResponse=Failed to process response
httpsRequired=HTTPS required
realmNotEnabled=Realm not enabled
invalidRequest=Invalid Request
unknownLoginRequester=Unknown login requester
loginRequesterNotEnabled=Login requester not enabled
bearerOnly=Bearer-only applications are not allowed to initiate browser login
directGrantsOnly=Direct-grants-only clients are not allowed to initiate browser login
invalidRedirectUri=Invalid redirect uri
unsupportedNameIdFormat=Unsupported NameIDFormat
invlidRequester=Invalid requester
registrationNotAllowed=Registration not allowed
permissionNotApproved=Permission not approved.
noRelayStateInResponse=No relay state in response from identity provider [{0}].
identityProviderAlreadyLinked=The identity returned by the identity provider [{0}] is already linked to another user.
userDisabled="User is disabled."
insufficientPermission=Insufficient permissions to link identities.
couldNotProceedWithAuthenticationRequest=Could not proceed with authentication request to identity provider.
couldNotObtainToken=Could not obtain token from identity provider [{0}].
unexpectedErrorRetrievingToken=Unexpected error when retrieving token from identity provider [{0}].
unexpectedErrorHandlingResponse=Unexpected error when handling response from identity provider [{0}].
identityProviderAuthenticationFailed=Authentication failed. Could not authenticate with identity provider [{0}].
couldNotSendAuthenticationRequest=Could not send authentication request to identity provider [{0}].
unexpectedErrorHandlingRequest=Unexpected error when handling authentication request to identity provider [{0}].
invalidAccessCode=Invalid access code.
sessionNotActive=Session not active.
unknownCode=Unknown code, please login again through your application.
invalidCode=Invalid code, please login again through your application.
identityProviderUnexpectedError=Unexpected error when authenticating with identity provider
identityProviderNotFound=Could not find an identity provider with the identifier [{0}].
identityProviderNoToken=Could not obtain token from identity provider [{0}].
realmSupportsNoCredentials=Realm [{0}] does not support any credential type.
identityProviderNotUnique=Realm [{0}] supports multiple identity providers. Could not determine which identity provider should be used to authenticate with.
noAccess=No access
identityProviderNotUnique=Realm [{0}] supports multiple identity providers. Could not determine which identity provider should be used to authenticate with.

View File

@@ -32,20 +32,7 @@ import org.keycloak.events.Event;
import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventStoreProvider;
import org.keycloak.events.EventType;
import org.keycloak.models.AccountRoles;
import org.keycloak.models.ApplicationModel;
import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientSessionModel;
import org.keycloak.models.Constants;
import org.keycloak.models.FederatedIdentityModel;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelReadOnlyException;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserCredentialValueModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.models.*;
import org.keycloak.models.utils.ModelToRepresentation;
import org.keycloak.models.utils.TimeBasedOTP;
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
@@ -611,6 +598,10 @@ public class AccountService {
} catch (ModelReadOnlyException mre) {
setReferrerOnPage();
return account.setError(Messages.READ_ONLY_PASSWORD).createResponse(AccountPages.PASSWORD);
}catch (ModelException me) {
logger.error("Failed to update password", me);
setReferrerOnPage();
return account.setError(me.getMessage(), me.getParameters()).createResponse(AccountPages.PASSWORD);
}catch (Exception ape) {
logger.error("Failed to update password", ape);
setReferrerOnPage();