[keycloak-user] How to get UserSessionModel from RequiredActionContext
Knurr, Michael
Michael.Knurr at adesso.ch
Sat Sep 23 04:46:50 EDT 2017
I just migrated an implementation for a RequiredActionProvider from 1.9 to 3.2. The processAction method in RequiredActionProvider has only one parameter of type RequiredActionContext. In the past (up to Release 2.4) it was possible to identify the users current session by calling
@Override
public void processAction(RequiredActionContext ctx) {
// user session current login
UserSessionModel currentUserSession = ctx.getUserSession();
...
}
Unfortunately it seems that with Release 2.5 this method has been dropped. Instead, the RequiredActionContext now provides an AuthenticationSessionModel. The AuthenticationSessionModel interface again has a method getUserSession() which is exactly what I need but it is commented out.
How can I identify the UserSessionModel for the current login action? One way would be to iterate over all user sessions, but there has to be an easier solution:
List<UserSessionModel> userSessions = ctx.getSession().sessions().getUserSessions(ctx.getRealm(), ctx.getUser());
I cannot find an easier solution. Can someone please help me out?
Brgds
Mike
More information about the keycloak-user
mailing list