mirror of
https://github.com/keycloak/keycloak.git
synced 2026-02-11 17:59:09 -06:00
add localization support to realm
This commit is contained in:
@@ -72,9 +72,19 @@
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
<createTable tableName="REALM_SUPPORTED_LOCALES">
|
||||
<column name="REALM_ID" type="VARCHAR(36)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="VALUE" type="VARCHAR(255)"/>
|
||||
</createTable>
|
||||
<addColumn tableName="CLIENT">
|
||||
<column name="FRONTCHANNEL_LOGOUT" type="BOOLEAN" defaultValueBoolean="false"/>
|
||||
</addColumn>
|
||||
<addColumn tableName="REALM">
|
||||
<column name="LOCALIZATION_ENABLED" type="BOOLEAN" defaultValueBoolean="false"/>
|
||||
<column name="DEFAULT_LOCALE" type="VARCHAR(255)" />
|
||||
</addColumn>
|
||||
<addPrimaryKey columnNames="ID" constraintName="CONSTRAINT_CT" tableName="CLAIM_TYPE"/>
|
||||
<addPrimaryKey columnNames="ID" constraintName="CONSTRAINT_PCM" tableName="PROTOCOL_MAPPER"/>
|
||||
<addPrimaryKey columnNames="INTERNAL_ID" constraintName="CONSTRAINT_2B" tableName="IDENTITY_PROVIDER"/>
|
||||
@@ -86,6 +96,7 @@
|
||||
<addForeignKeyConstraint baseColumnNames="USER_ID" baseTableName="FEDERATED_IDENTITY" constraintName="FK404288B92EF007A6" deferrable="false" initiallyDeferred="false" onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="ID" referencedTableName="USER_ENTITY"/>
|
||||
<addForeignKeyConstraint baseColumnNames="IDENTITY_PROVIDER_ID" baseTableName="IDENTITY_PROVIDER_CONFIG" constraintName="FKDC4897CF864C4E43" deferrable="false" initiallyDeferred="false" onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="INTERNAL_ID" referencedTableName="IDENTITY_PROVIDER"/>
|
||||
<addForeignKeyConstraint baseColumnNames="INTERNAL_ID" baseTableName="CLIENT_ALLOWED_IDENTITY_PROVIDER" constraintName="FK_7CELWNIBJI49AVXSRTUF6XJ12" referencedColumnNames="INTERNAL_ID" referencedTableName="IDENTITY_PROVIDER"/>
|
||||
<addForeignKeyConstraint baseColumnNames="REALM_ID" baseTableName="REALM_SUPPORTED_LOCALES" constraintName="FK_SUPPORTED_LOCALES_REALM" referencedColumnNames="ID" referencedTableName="REALM"/>
|
||||
<addUniqueConstraint columnNames="INTERNAL_ID,CLIENT_ID" constraintName="UK_7CAELWNIBJI49AVXSRTUF6XJ12" tableName="CLIENT_ALLOWED_IDENTITY_PROVIDER"/>
|
||||
<addForeignKeyConstraint baseColumnNames="MAPPING_ID" baseTableName="CLIENT_PROTOCOL_MAPPER" constraintName="FK_CPCM" referencedColumnNames="ID" referencedTableName="PROTOCOL_MAPPER"/>
|
||||
<addUniqueConstraint columnNames="CLIENT_ID,MAPPING_ID" constraintName="UK_CPCM" tableName="CLIENT_PROTOCOL_MAPPER"/>
|
||||
|
||||
@@ -236,5 +236,11 @@ public interface RealmModel extends RoleContainerModel {
|
||||
void updateProtocolMapper(ProtocolMapperModel mapping);
|
||||
public ProtocolMapperModel getProtocolMapperById(String id);
|
||||
|
||||
|
||||
//i18n
|
||||
boolean isLocalizationEnabled();
|
||||
void setLocalizationEnabled(boolean enabled);
|
||||
Set<String> getSupportedLocales();
|
||||
void setSupportedLocales(Set<String> locales);
|
||||
String getDefaultLocale();
|
||||
void setDefaultLocale(String locale);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,10 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||
|
||||
private String adminAppId;
|
||||
|
||||
private boolean localizationEnabled;
|
||||
private List<String> supportedLocales = new ArrayList<String>();
|
||||
private String defaultLocale;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -408,6 +412,30 @@ public class RealmEntity extends AbstractIdentifiableEntity {
|
||||
public void setClaimMappings(List<ProtocolMapperEntity> claimMappings) {
|
||||
this.claimMappings = claimMappings;
|
||||
}
|
||||
|
||||
public boolean isLocalizationEnabled() {
|
||||
return localizationEnabled;
|
||||
}
|
||||
|
||||
public void setLocalizationEnabled(boolean localizationEnabled) {
|
||||
this.localizationEnabled = localizationEnabled;
|
||||
}
|
||||
|
||||
public List<String> getSupportedLocales() {
|
||||
return supportedLocales;
|
||||
}
|
||||
|
||||
public void setSupportedLocales(List<String> supportedLocales) {
|
||||
this.supportedLocales = supportedLocales;
|
||||
}
|
||||
|
||||
public String getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
public void setDefaultLocale(String defaultLocale) {
|
||||
this.defaultLocale = defaultLocale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -932,4 +932,39 @@ public class RealmAdapter implements RealmModel {
|
||||
public int hashCode() {
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocalizationEnabled() {
|
||||
if (updated != null) return updated.isLocalizationEnabled();
|
||||
return cached.isLocalizationEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocalizationEnabled(boolean enabled) {
|
||||
getDelegateForUpdate();
|
||||
updated.setLocalizationEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedLocales() {
|
||||
if (updated != null) return updated.getSupportedLocales();
|
||||
return cached.getSupportedLocales();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSupportedLocales(Set<String> locales) {
|
||||
getDelegateForUpdate();
|
||||
updated.setSupportedLocales(locales);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultLocale() {
|
||||
if (updated != null) return updated.getDefaultLocale();
|
||||
return cached.getDefaultLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultLocale(String locale) {
|
||||
updated.setDefaultLocale(locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,9 @@ public class CachedRealm {
|
||||
private Map<String, String> realmRoles = new HashMap<String, String>();
|
||||
private Map<String, String> applications = new HashMap<String, String>();
|
||||
private Map<String, String> clients = new HashMap<String, String>();
|
||||
private boolean localizationEnabled;
|
||||
private Set<String> supportedLocales = new HashSet<String>();
|
||||
private String defaultLocale;
|
||||
|
||||
public CachedRealm() {
|
||||
}
|
||||
@@ -166,6 +169,10 @@ public class CachedRealm {
|
||||
cache.addCachedOAuthClient(cachedApp);
|
||||
}
|
||||
|
||||
localizationEnabled = model.isLocalizationEnabled();
|
||||
supportedLocales.addAll(model.getSupportedLocales());
|
||||
defaultLocale = model.getDefaultLocale();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -356,4 +363,16 @@ public class CachedRealm {
|
||||
public Set<ProtocolMapperModel> getClaimMappings() {
|
||||
return claimMappings;
|
||||
}
|
||||
|
||||
public boolean isLocalizationEnabled() {
|
||||
return localizationEnabled;
|
||||
}
|
||||
|
||||
public Set<String> getSupportedLocales() {
|
||||
return supportedLocales;
|
||||
}
|
||||
|
||||
public String getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1342,4 +1342,37 @@ public class RealmAdapter implements RealmModel {
|
||||
mapping.setSourceAttribute(entity.getSourceAttribute());
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocalizationEnabled() {
|
||||
return realm.isLocalizationEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocalizationEnabled(boolean enabled) {
|
||||
realm.setLocalizationEnabled(enabled);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedLocales() {
|
||||
return realm.getSupportedLocales();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSupportedLocales(Set<String> locales) {
|
||||
realm.setSupportedLocales(locales);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultLocale() {
|
||||
return realm.getDefaultLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultLocale(String locale) {
|
||||
realm.setDefaultLocale(locale);
|
||||
em.flush();
|
||||
}
|
||||
}
|
||||
@@ -139,6 +139,18 @@ public class RealmEntity {
|
||||
@OneToMany(cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "realm")
|
||||
protected List<IdentityProviderEntity> identityProviders = new ArrayList<IdentityProviderEntity>();
|
||||
|
||||
@Column(name="LOCALIZATION_ENABLED")
|
||||
protected boolean localizationEnabled;
|
||||
|
||||
@ElementCollection
|
||||
@Column(name="VALUE")
|
||||
@CollectionTable(name="REALM_SUPPORTED_LOCALES", joinColumns={ @JoinColumn(name="REALM_ID") })
|
||||
protected Set<String> supportedLocales = new HashSet<String>();
|
||||
|
||||
@Column(name="DEFAULT_LOCALE")
|
||||
protected String defaultLocale;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -454,5 +466,29 @@ public class RealmEntity {
|
||||
public void setProtocolClaimMappings(Collection<ProtocolMapperEntity> protocolClaimMappings) {
|
||||
this.protocolClaimMappings = protocolClaimMappings;
|
||||
}
|
||||
|
||||
public boolean isLocalizationEnabled() {
|
||||
return localizationEnabled;
|
||||
}
|
||||
|
||||
public void setLocalizationEnabled(boolean localizationEnabled) {
|
||||
this.localizationEnabled = localizationEnabled;
|
||||
}
|
||||
|
||||
public Set<String> getSupportedLocales() {
|
||||
return supportedLocales;
|
||||
}
|
||||
|
||||
public void setSupportedLocales(Set<String> supportedLocales) {
|
||||
this.supportedLocales = supportedLocales;
|
||||
}
|
||||
|
||||
public String getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
public void setDefaultLocale(String defaultLocale) {
|
||||
this.defaultLocale = defaultLocale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1192,5 +1192,40 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||
return getId().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocalizationEnabled() {
|
||||
return realm.isLocalizationEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocalizationEnabled(boolean enabled) {
|
||||
realm.setLocalizationEnabled(enabled);
|
||||
updateRealm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedLocales() {
|
||||
return new HashSet<String>(realm.getSupportedLocales());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSupportedLocales(Set<String> locales) {
|
||||
if (locales != null) {
|
||||
realm.setEventsListeners(new ArrayList<String>(locales));
|
||||
} else {
|
||||
realm.setEventsListeners(Collections.EMPTY_LIST);
|
||||
}
|
||||
updateRealm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultLocale() {
|
||||
return realm.getDefaultLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultLocale(String locale) {
|
||||
realm.setDefaultLocale(locale);
|
||||
updateRealm();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user