I have developed a Security Authentication Module (SAM) and implemented the validateRequest
method. I also have a simple webapp configured to use this SAM.
In my validateRequest
method, I check the clientSubject and set a CallerPrincipalCallback
with a hardcoded username and a GroupPrincipalCallback
with a hardcoded group name:
final CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, "anonymous");
final GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[] {"user"});
try {
this.handler.handle(new Callback[] {callerPrincipalCallback, groupPrincipalCallback});
} catch (IOException | UnsupportedCallbackException e) {
logger.error(e.getMessage());
}
I noticed that everytime I refresh a servlet in my webapp, the client subject is simply blank, logger.debug("Client: {}", clientSubject);
:
2015-05-05 11:21:02,200 DEBUG n.m.j.s.Saml2AuthModule [http-listener-1(2)] Client: Subject:
Is it possible to "save" a subject somehow so that the subject is attached to the session and I can simply skip logging in the same user every time?
EDIT I think I found a way by manually storing it in the HttpSession
: req.getSession().setAttribute("subject", user);
Not pretty, but it works.