fixed null pointer exception when principal is null

This commit is contained in:
Pulkit Gupta 2016-10-20 13:36:25 +05:30
parent f2f508ac2e
commit 115f95d90e

View file

@ -153,14 +153,14 @@ public class CatalinaSamlSessionStore implements SamlSessionStore {
} }
GenericPrincipal principal = (GenericPrincipal) session.getPrincipal(); GenericPrincipal principal = (GenericPrincipal) session.getPrincipal();
if (samlSession.getPrincipal().getName().equals(principal.getName()))
// in clustered environment in JBossWeb, principal is not serialized or saved // in clustered environment in JBossWeb, principal is not serialized or saved
if (principal == null) { if (principal == null) {
principal = principalFactory.createPrincipal(request.getContext().getRealm(), samlSession.getPrincipal(), samlSession.getRoles()); principal = principalFactory.createPrincipal(request.getContext().getRealm(), samlSession.getPrincipal(), samlSession.getRoles());
session.setPrincipal(principal); session.setPrincipal(principal);
session.setAuthType("KEYCLOAK-SAML"); session.setAuthType("KEYCLOAK-SAML");
} else { }
else if (samlSession.getPrincipal().getName().equals(principal.getName())){
if (!principal.getUserPrincipal().getName().equals(samlSession.getPrincipal().getName())) { if (!principal.getUserPrincipal().getName().equals(samlSession.getPrincipal().getName())) {
throw new RuntimeException("Unknown State"); throw new RuntimeException("Unknown State");
} }