}
}
private boolean authenticate(SecurityContext context, Subject subject) {
SecurityContextUtil util = context.getUtil();
SubjectInfo subjectInfo = context.getSubjectInfo();
if (subject == null) {
subject = new Subject();
}
Principal principal = util.getUserPrincipal();
Object credential = util.getCredential();
boolean authenticated = false;
if (principal == null) {
Identity unauthenticatedIdentity = getUnauthenticatedIdentity();
subjectInfo.addIdentity(unauthenticatedIdentity);
subject.getPrincipals().add(unauthenticatedIdentity.asPrincipal());
authenticated = true;
}
if (authenticated == false) {
AuthenticationManager authenticationManager = context.getAuthenticationManager();
authenticated = authenticationManager.isValid(principal, credential, subject);
}
if (authenticated == true) {
subjectInfo.setAuthenticatedSubject(subject);
}
return authenticated;
}