I am running a JEE application on Wildfly 10 / JBoss EAP 7.0.8 in which a user is authenticated via a JAAS login module. My security-domain is defined as follows:
<security-domain name="webapp" cache-type="default">
<authentication>
<login-module code="org.sso.keycloak.KeycloakLoginModule" flag="optional" module="deployment.ear">
<module-option name="keycloak-config-file" value="${keycloak.config}"/>
</login-module>
<login-module code="security.jboss.ServerLoginModule" flag="requisite" module="deployment.ear">
<module-option name="password-stacking" value="useFirstPass"/>
<module-option name="unauthenticatedIdentity" value="nobody"/>
</login-module>
</authentication>
</security-domain>
My login module then calculates the roles for the given user and returns it via the getRoleSets() method which is part of the LoginModule.
The authentication process works properly, however I now have a requirement where I need to change an authenticated user's role once they have already been authentication.
If I try to call request.login() a second time for an already authenticated user, it throws an exception that the user is already logged in.
Retrieving the Principal from the request object does not give me access to his roles or groups. Nor have I been able to find a way to retrieve the information from the SecurityContext.
How can I modify/add roles for a user which has already been authenticated?