keycloak-service
公開メンバ関数 | 限定公開メンバ関数 | 限定公開変数類 | 静的限定公開変数類 | 全メンバ一覧
org.keycloak.locale.DefaultLocaleSelectorProvider クラス
org.keycloak.locale.DefaultLocaleSelectorProvider の継承関係図
Inheritance graph
org.keycloak.locale.DefaultLocaleSelectorProvider 連携図
Collaboration graph

公開メンバ関数

 DefaultLocaleSelectorProvider (KeycloakSession session)
 
Locale resolveLocale (RealmModel realm, UserModel user)
 
void close ()
 

限定公開メンバ関数

Locale getLocale (RealmModel realm, UserModel user, HttpHeaders requestHeaders, UriInfo uriInfo)
 
Locale getUserLocale (RealmModel realm, UserModel user, HttpHeaders requestHeaders, UriInfo uriInfo)
 
LocaleSelection getKcLocaleQueryParamSelection (RealmModel realm, UriInfo uriInfo)
 
LocaleSelection getLocaleCookieSelection (RealmModel realm, HttpHeaders httpHeaders)
 
LocaleSelection getUserProfileSelection (RealmModel realm, UserModel user)
 
LocaleSelection getUiLocalesQueryParamSelection (RealmModel realm, UriInfo uriInfo)
 
LocaleSelection getAcceptLanguageHeaderLocale (RealmModel realm, HttpHeaders httpHeaders)
 
void updateLocaleCookie (RealmModel realm, String locale, UriInfo uriInfo)
 
LocaleSelection findLocale (RealmModel realm, String... localeStrings)
 
void updateUsersLocale (UserModel user, String locale)
 

限定公開変数類

final KeycloakSession session
 

静的限定公開変数類

static final String LOCALE_COOKIE = "KEYCLOAK_LOCALE"
 
static final String KC_LOCALE_PARAM = "kc_locale"
 

詳解

構築子と解体子

◆ DefaultLocaleSelectorProvider()

org.keycloak.locale.DefaultLocaleSelectorProvider.DefaultLocaleSelectorProvider ( KeycloakSession  session)
inline
37  {
38  this.session = session;
39  }
final KeycloakSession session
Definition: DefaultLocaleSelectorProvider.java:35

関数詳解

◆ close()

void org.keycloak.locale.DefaultLocaleSelectorProvider.close ( )
inline
49  {
50 
51  }

◆ findLocale()

LocaleSelection org.keycloak.locale.DefaultLocaleSelectorProvider.findLocale ( RealmModel  realm,
String...  localeStrings 
)
inlineprotected
150  {
151  return new LocaleNegotiator(realm.getSupportedLocales()).invoke(localeStrings);
152  }

◆ getAcceptLanguageHeaderLocale()

LocaleSelection org.keycloak.locale.DefaultLocaleSelectorProvider.getAcceptLanguageHeaderLocale ( RealmModel  realm,
HttpHeaders  httpHeaders 
)
inlineprotected
131  {
132  if (httpHeaders == null || httpHeaders.getAcceptableLanguages() == null || httpHeaders.getAcceptableLanguages().isEmpty()) {
133  return null;
134  }
135  for (Locale l : httpHeaders.getAcceptableLanguages()) {
136  String localeString = l.toLanguageTag();
137  LocaleSelection localeSelection = findLocale(realm, localeString);
138  if (localeSelection != null) {
139  return localeSelection;
140  }
141  }
142  return null;
143  }
LocaleSelection findLocale(RealmModel realm, String... localeStrings)
Definition: DefaultLocaleSelectorProvider.java:150

◆ getKcLocaleQueryParamSelection()

LocaleSelection org.keycloak.locale.DefaultLocaleSelectorProvider.getKcLocaleQueryParamSelection ( RealmModel  realm,
UriInfo  uriInfo 
)
inlineprotected
99  {
100  if (uriInfo == null || !uriInfo.getQueryParameters().containsKey(KC_LOCALE_PARAM)) {
101  return null;
102  }
103  String localeString = uriInfo.getQueryParameters().getFirst(KC_LOCALE_PARAM);
104  return findLocale(realm, localeString);
105  }
static final String KC_LOCALE_PARAM
Definition: DefaultLocaleSelectorProvider.java:33
LocaleSelection findLocale(RealmModel realm, String... localeStrings)
Definition: DefaultLocaleSelectorProvider.java:150

◆ getLocale()

Locale org.keycloak.locale.DefaultLocaleSelectorProvider.getLocale ( RealmModel  realm,
UserModel  user,
HttpHeaders  requestHeaders,
UriInfo  uriInfo 
)
inlineprotected
53  {
54  if (!realm.isInternationalizationEnabled()) {
55  return Locale.ENGLISH;
56  } else {
57  Locale locale = getUserLocale(realm, user, requestHeaders, uriInfo);
58  return locale != null ? locale : Locale.forLanguageTag(realm.getDefaultLocale());
59  }
60  }
Locale getUserLocale(RealmModel realm, UserModel user, HttpHeaders requestHeaders, UriInfo uriInfo)
Definition: DefaultLocaleSelectorProvider.java:62

◆ getLocaleCookieSelection()

LocaleSelection org.keycloak.locale.DefaultLocaleSelectorProvider.getLocaleCookieSelection ( RealmModel  realm,
HttpHeaders  httpHeaders 
)
inlineprotected
107  {
108  if (httpHeaders == null || !httpHeaders.getCookies().containsKey(LOCALE_COOKIE)) {
109  return null;
110  }
111  String localeString = httpHeaders.getCookies().get(LOCALE_COOKIE).getValue();
112  return findLocale(realm, localeString);
113  }
LocaleSelection findLocale(RealmModel realm, String... localeStrings)
Definition: DefaultLocaleSelectorProvider.java:150
static final String LOCALE_COOKIE
Definition: DefaultLocaleSelectorProvider.java:32

◆ getUiLocalesQueryParamSelection()

LocaleSelection org.keycloak.locale.DefaultLocaleSelectorProvider.getUiLocalesQueryParamSelection ( RealmModel  realm,
UriInfo  uriInfo 
)
inlineprotected
123  {
124  if (uriInfo == null || !uriInfo.getQueryParameters().containsKey(OAuth2Constants.UI_LOCALES_PARAM)) {
125  return null;
126  }
127  String localeString = uriInfo.getQueryParameters().getFirst(OAuth2Constants.UI_LOCALES_PARAM);
128  return findLocale(realm, localeString.split(" "));
129  }
LocaleSelection findLocale(RealmModel realm, String... localeStrings)
Definition: DefaultLocaleSelectorProvider.java:150

◆ getUserLocale()

Locale org.keycloak.locale.DefaultLocaleSelectorProvider.getUserLocale ( RealmModel  realm,
UserModel  user,
HttpHeaders  requestHeaders,
UriInfo  uriInfo 
)
inlineprotected
62  {
63  final LocaleSelection kcLocaleQueryParamSelection = getKcLocaleQueryParamSelection(realm, uriInfo);
64  if (kcLocaleQueryParamSelection != null) {
65  updateLocaleCookie(realm, kcLocaleQueryParamSelection.getLocaleString(), uriInfo);
66  if (user != null) {
67  updateUsersLocale(user, kcLocaleQueryParamSelection.getLocaleString());
68  }
69  return kcLocaleQueryParamSelection.getLocale();
70  }
71 
72  final LocaleSelection localeCookieSelection = getLocaleCookieSelection(realm, requestHeaders);
73  if (localeCookieSelection != null) {
74  if (user != null) {
75  updateUsersLocale(user, localeCookieSelection.getLocaleString());
76  }
77  return localeCookieSelection.getLocale();
78  }
79 
80  final LocaleSelection userProfileSelection = getUserProfileSelection(realm, user);
81  if (userProfileSelection != null) {
82  updateLocaleCookie(realm, userProfileSelection.getLocaleString(), uriInfo);
83  return userProfileSelection.getLocale();
84  }
85 
86  final LocaleSelection uiLocalesQueryParamSelection = getUiLocalesQueryParamSelection(realm, uriInfo);
87  if (uiLocalesQueryParamSelection != null) {
88  return uiLocalesQueryParamSelection.getLocale();
89  }
90 
91  final LocaleSelection acceptLanguageHeaderSelection = getAcceptLanguageHeaderLocale(realm, requestHeaders);
92  if (acceptLanguageHeaderSelection != null) {
93  return acceptLanguageHeaderSelection.getLocale();
94  }
95 
96  return null;
97  }
void updateUsersLocale(UserModel user, String locale)
Definition: DefaultLocaleSelectorProvider.java:154
void updateLocaleCookie(RealmModel realm, String locale, UriInfo uriInfo)
Definition: DefaultLocaleSelectorProvider.java:145
LocaleSelection getUiLocalesQueryParamSelection(RealmModel realm, UriInfo uriInfo)
Definition: DefaultLocaleSelectorProvider.java:123
LocaleSelection getUserProfileSelection(RealmModel realm, UserModel user)
Definition: DefaultLocaleSelectorProvider.java:115
LocaleSelection getAcceptLanguageHeaderLocale(RealmModel realm, HttpHeaders httpHeaders)
Definition: DefaultLocaleSelectorProvider.java:131
LocaleSelection getLocaleCookieSelection(RealmModel realm, HttpHeaders httpHeaders)
Definition: DefaultLocaleSelectorProvider.java:107
LocaleSelection getKcLocaleQueryParamSelection(RealmModel realm, UriInfo uriInfo)
Definition: DefaultLocaleSelectorProvider.java:99

◆ getUserProfileSelection()

LocaleSelection org.keycloak.locale.DefaultLocaleSelectorProvider.getUserProfileSelection ( RealmModel  realm,
UserModel  user 
)
inlineprotected
115  {
116  if (user == null || !user.getAttributes().containsKey(UserModel.LOCALE)) {
117  return null;
118  }
119  String localeString = user.getFirstAttribute(UserModel.LOCALE);
120  return findLocale(realm, localeString);
121  }
LocaleSelection findLocale(RealmModel realm, String... localeStrings)
Definition: DefaultLocaleSelectorProvider.java:150

◆ resolveLocale()

Locale org.keycloak.locale.DefaultLocaleSelectorProvider.resolveLocale ( RealmModel  realm,
UserModel  user 
)
inline
42  {
43  final HttpHeaders requestHeaders = session.getContext().getRequestHeaders();
44  final UriInfo uri = session.getContext().getUri();
45  return getLocale(realm, user, requestHeaders, uri);
46  }
Locale getLocale(RealmModel realm, UserModel user, HttpHeaders requestHeaders, UriInfo uriInfo)
Definition: DefaultLocaleSelectorProvider.java:53
final KeycloakSession session
Definition: DefaultLocaleSelectorProvider.java:35

◆ updateLocaleCookie()

void org.keycloak.locale.DefaultLocaleSelectorProvider.updateLocaleCookie ( RealmModel  realm,
String  locale,
UriInfo  uriInfo 
)
inlineprotected
145  {
146  boolean secure = realm.getSslRequired().isRequired(uriInfo.getRequestUri().getHost());
147  CookieHelper.addCookie(LOCALE_COOKIE, locale, AuthenticationManager.getRealmCookiePath(realm, uriInfo), null, null, -1, secure, true);
148  }
static final String LOCALE_COOKIE
Definition: DefaultLocaleSelectorProvider.java:32

◆ updateUsersLocale()

void org.keycloak.locale.DefaultLocaleSelectorProvider.updateUsersLocale ( UserModel  user,
String  locale 
)
inlineprotected
154  {
155  if (!locale.equals(user.getFirstAttribute("locale"))) {
156  user.setSingleAttribute(UserModel.LOCALE, locale);
157  }
158  }

メンバ詳解

◆ KC_LOCALE_PARAM

final String org.keycloak.locale.DefaultLocaleSelectorProvider.KC_LOCALE_PARAM = "kc_locale"
staticprotected

◆ LOCALE_COOKIE

final String org.keycloak.locale.DefaultLocaleSelectorProvider.LOCALE_COOKIE = "KEYCLOAK_LOCALE"
staticprotected

◆ session

final KeycloakSession org.keycloak.locale.DefaultLocaleSelectorProvider.session
protected

このクラス詳解は次のファイルから抽出されました: