Search in sources :

Example 1 with SubjectInfo

use of org.jboss.security.SubjectInfo in project wildfly by wildfly.

the class SimpleSecurityManager method authenticate.

private boolean authenticate(SecurityContext context, Subject subject) {
    SecurityContextUtil util = context.getUtil();
    SubjectInfo subjectInfo = getSubjectInfo(context);
    if (subject == null) {
        subject = new Subject();
    }
    Principal principal = util.getUserPrincipal();
    Principal auditPrincipal = principal;
    Object credential = util.getCredential();
    Identity unauthenticatedIdentity = null;
    boolean authenticated = false;
    if (principal == null) {
        unauthenticatedIdentity = getUnauthenticatedIdentity();
        subjectInfo.addIdentity(unauthenticatedIdentity);
        auditPrincipal = unauthenticatedIdentity.asPrincipal();
        subject.getPrincipals().add(auditPrincipal);
        authenticated = true;
    } else {
        subject.getPrincipals().add(principal);
    }
    if (authenticated == false) {
        AuthenticationManager authenticationManager = context.getAuthenticationManager();
        authenticated = authenticationManager.isValid(principal, credential, subject);
    }
    if (authenticated == true) {
        subjectInfo.setAuthenticatedSubject(subject);
    }
    AuditManager auditManager = context.getAuditManager();
    if (auditManager != null) {
        audit(authenticated ? AuditLevel.SUCCESS : AuditLevel.FAILURE, auditManager, auditPrincipal);
    }
    return authenticated;
}
Also used : AuthenticationManager(org.jboss.security.AuthenticationManager) SecurityContextUtil(org.jboss.security.SecurityContextUtil) SubjectInfo(org.jboss.security.SubjectInfo) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) Identity(org.jboss.security.identity.Identity) SimpleIdentity(org.jboss.security.identity.plugins.SimpleIdentity) RunAsIdentity(org.jboss.security.RunAsIdentity) Subject(javax.security.auth.Subject) Principal(java.security.Principal) SimplePrincipal(org.jboss.security.SimplePrincipal) AuditManager(org.jboss.security.audit.AuditManager)

Aggregations

Principal (java.security.Principal)1 Subject (javax.security.auth.Subject)1 AuthenticationManager (org.jboss.security.AuthenticationManager)1 RunAsIdentity (org.jboss.security.RunAsIdentity)1 SecurityContextUtil (org.jboss.security.SecurityContextUtil)1 SimplePrincipal (org.jboss.security.SimplePrincipal)1 SubjectInfo (org.jboss.security.SubjectInfo)1 AuditManager (org.jboss.security.audit.AuditManager)1 Identity (org.jboss.security.identity.Identity)1 SimpleIdentity (org.jboss.security.identity.plugins.SimpleIdentity)1 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)1