微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

密钥泄漏:获取当前SSO会话的UserSessionModel

如何解决密钥泄漏:获取当前SSO会话的UserSessionModel

Keycloak 11.0.2

  1. 是否可以通过自定义身份验证器将UserSessionModel分配给当前SSO会话?

我可以参加List<UserSessionModel>

List<UserSessionModel> userSessions = context.getSession().sessions().getUserSessions(context.getRealm(),context.getUser());

但是我不知道我可以使用AutheticationFlowContext来对哪个过滤属性进行过滤,并采用当前SSO会话的UserSessionModel。

现在,我正在过滤从身份验证请求Cookie UserSessionModel.id(其最后一部分)中提取KEYCLOAK_SESSION。也许有直接方法以某种方式使用UserSessionModel.id来使用AuthenticationFlowContext

  1. 我必须使用UserSessionModel.getNote()来检索先前在同一SSO的另一个身份验证流中设置的UserSessionNotes。

直接方法不适合我采用另一个身份验证流程(但在同一SSO中)设置的UserSessionNotes

@Override
public void authenticate(AuthenticationFlowContext context) {
    Map<String,String> sessionNotes = context.getAuthenticationSession().getUserSessionNotes();
    // sessionNotes does not reflect notes set in another Authentication flows of the same SSO
    ...

}

因此,如果有人知道另一种不用UserSessionNotes服用UserSessionModel方法,那也是解决方案。

解决方法

我已经在Keycloak论坛https://keycloak.discourse.group/t/getting-usersessionnotes-returns-null-while-data-persist/5172上收到了答案

在身份验证器中获取当前SSO的UserSessionModel

@Override
public void authenticate(AuthenticationFlowContext context) {
    UserSessionModel userSessionModel;
    AuthenticationManager.AuthResult authResult = AuthenticationManager.authenticateIdentityCookie(context.getSession(),context.getRealm(),true);
    if (authResult != null) {
        // That is it:
        userSessionModel = authResult.getSession();
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。