SecurityManager securityManager = context.resolveSecurityManager();
if (securityManager == null) {
throw new IllegalStateException("SecurityManager instance should already be present in the " +
"SubjectContext argument.");
}
Session session = context.resolveSession();
if (session == null) {
log.trace("No session in the current subject context. One will be created to persist principals [{}] " +
"Doing this prevents unnecessary repeated RememberMe operations since an identity has been " +
"discovered.", principals);
//no session - start one:
SessionContext sessionContext = createSessionContext(context);
session = start(sessionContext);
context.setSession(session);
log.debug("Created session with id {} to retain discovered principals {}", session.getId(), principals);
}
bindPrincipalsToSession(principals, session);
}