Javascript 将用户区域设置包括到KeyClope ID令牌中
我希望keydape(1.4.0)将用户选择的区域设置包括到ID令牌中 我已经创建了一个用户属性映射器,该映射器应该将locale属性映射到令牌,但它不起作用 有人知道怎么做吗? 提前谢谢Javascript 将用户区域设置包括到KeyClope ID令牌中,javascript,locale,keycloak,Javascript,Locale,Keycloak,我希望keydape(1.4.0)将用户选择的区域设置包括到ID令牌中 我已经创建了一个用户属性映射器,该映射器应该将locale属性映射到令牌,但它不起作用 有人知道怎么做吗? 提前谢谢 编辑:我从这门课上学到了我所知道的关于Put Keyclope Locale的知识:我想你已经有了这样的知识: final Principal userPrincipal = httpRequest.getUserPrincipal(); if (userPrincipal instanceof Keycl
编辑:我从这门课上学到了我所知道的关于Put Keyclope Locale的知识:我想你已经有了这样的知识:
final Principal userPrincipal = httpRequest.getUserPrincipal();
if (userPrincipal instanceof KeycloakPrincipal) {
KeycloakPrincipal<KeycloakSecurityContext> kp = (KeycloakPrincipal<KeycloakSecurityContext>) userPrincipal;
IDToken token = kp.getKeycloakSecurityContext().getIdToken();
Map<String, Object> otherClaims = token.getOtherClaims();
if (otherClaims.containsKey("YOUR_CLAIM_KEY")) {
yourClaim = String.valueOf(otherClaims.get("YOUR_CLAIM_KEY"));
}
} else {
throw new RuntimeException(...);
}
final Principal userPrincipal = httpRequest.getUserPrincipal();
if (userPrincipal instanceof KeycloakPrincipal) {
KeycloakPrincipal<KeycloakSecurityContext> kp = (KeycloakPrincipal<KeycloakSecurityContext>) userPrincipal;
IDToken token = kp.getKeycloakSecurityContext().getIdToken();
Map<String, Object> otherClaims = token.getOtherClaims();
if (otherClaims.containsKey("YOUR_CLAIM_KEY")) {
yourClaim = String.valueOf(otherClaims.get("YOUR_CLAIM_KEY"));
}
} else {
throw new RuntimeException(...);
}
final-Principal-userPrincipal=httpRequest.getUserPrincipal();
if(userPrincipal instanceof keydropecipal){
keydepaprincipal kp=(keydeprincipal)userPrincipal;
IDToken token=kp.getKeyDopperSecurityContext().getIdToken();
Map otherClaims=token.getOtherClaims();
如果(otherClaims.containsKey(“您的索赔密钥”)){
yourClaim=String.valueOf(otherClaims.get(“YOUR_CLAIM_KEY”);
}
}否则{
抛出新的RuntimeException(…);
}
希望这有助于并适合您的用例。我将其用于添加自定义主题的自定义属性。我想您已经有了这样的内容:
final Principal userPrincipal = httpRequest.getUserPrincipal();
if (userPrincipal instanceof KeycloakPrincipal) {
KeycloakPrincipal<KeycloakSecurityContext> kp = (KeycloakPrincipal<KeycloakSecurityContext>) userPrincipal;
IDToken token = kp.getKeycloakSecurityContext().getIdToken();
Map<String, Object> otherClaims = token.getOtherClaims();
if (otherClaims.containsKey("YOUR_CLAIM_KEY")) {
yourClaim = String.valueOf(otherClaims.get("YOUR_CLAIM_KEY"));
}
} else {
throw new RuntimeException(...);
}
final Principal userPrincipal = httpRequest.getUserPrincipal();
if (userPrincipal instanceof KeycloakPrincipal) {
KeycloakPrincipal<KeycloakSecurityContext> kp = (KeycloakPrincipal<KeycloakSecurityContext>) userPrincipal;
IDToken token = kp.getKeycloakSecurityContext().getIdToken();
Map<String, Object> otherClaims = token.getOtherClaims();
if (otherClaims.containsKey("YOUR_CLAIM_KEY")) {
yourClaim = String.valueOf(otherClaims.get("YOUR_CLAIM_KEY"));
}
} else {
throw new RuntimeException(...);
}
final-Principal-userPrincipal=httpRequest.getUserPrincipal();
if(userPrincipal instanceof keydropecipal){
keydepaprincipal kp=(keydeprincipal)userPrincipal;
IDToken token=kp.getKeyDopperSecurityContext().getIdToken();
Map otherClaims=token.getOtherClaims();
如果(otherClaims.containsKey(“您的索赔密钥”)){
yourClaim=String.valueOf(otherClaims.get(“YOUR_CLAIM_KEY”);
}
}否则{
抛出新的RuntimeException(…);
}
希望这有助于并适合您的用例。我将其用于添加了自定义主题的自定义属性。我自己解决了这个问题。我最终使用了KeyClope JS适配器中的loadUserProfile()函数。它将所有用户属性(包括区域设置)加载到keydave.profile对象中,因此我不必配置任何映射器。我自己设法解决了这个问题。我最终使用了KeyClope JS适配器中的loadUserProfile()函数。它将所有用户属性(包括区域设置)加载到keydave.profile对象中,因此我不必配置任何映射器。我已经尝试过这种方法,但问题是区域设置无法以这种方式访问,因此我必须使用用户配置文件。我按照您的建议进行了操作,但我只获得了一个空IDToken。不过,将数据添加到访问令牌是可行的,我可以从那里获取数据。这是SpringSecurity4.0和KeyClope 1.7,这很奇怪。即使没有自定义变量,您也应该获得标准的IdToken且不为null。我已经尝试过这个方法,但问题是语言环境无法以这种方式访问,因此我必须使用用户配置文件。我按照您的建议做了,但我只获得了null IdToken。不过,将数据添加到访问令牌是可行的,我可以从那里获取数据。这是SpringSecurity4.0和KeyClope 1.7,这很奇怪。即使没有自定义变量,您也应该获得标准的IdToken,并且不为null。很好,它现在可以工作了。我使用了自定义属性,显然配置文件属性的处理方式不同:)很好,它现在可以工作了。我使用了自定义属性,显然配置文件属性的处理方式不同:)