Search in sources :

Example 1 with Identity

use of org.jboss.security.identity.Identity 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)

Example 2 with Identity

use of org.jboss.security.identity.Identity in project wildfly by wildfly.

the class DefaultApplicationClientCallbackHandler method handle.

@Override
public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    final SecurityContext context = doPrivileged(SECURITY_CONTEXT);
    for (final Callback current : callbacks) {
        if (current instanceof NameCallback) {
            final NameCallback ncb = (NameCallback) current;
            if (context != null) {
                final Set<Identity> identities = getSubjectInfo(context).getIdentities();
                if (identities.isEmpty()) {
                    ncb.setName(DOLLAR_LOCAL);
                } else {
                    final Identity identity = identities.iterator().next();
                    ncb.setName(identity.getName());
                }
            } else {
                ncb.setName(DOLLAR_LOCAL);
            }
        } else if (current instanceof PasswordCallback) {
            if (context != null) {
                final PasswordCallback pcb = (PasswordCallback) current;
                final Set<Identity> identities = getSubjectInfo(context).getIdentities();
                if (identities.isEmpty()) {
                    throw new UnsupportedCallbackException(current);
                } else {
                    final Identity identity = identities.iterator().next();
                    if (identity instanceof CredentialIdentity) {
                        pcb.setPassword((char[]) ((CredentialIdentity) identity).getCredential());
                    } else {
                        throw new UnsupportedCallbackException(current);
                    }
                }
            }
        } else if (current instanceof RealmCallback) {
            final RealmCallback realmCallback = (RealmCallback) current;
            if (realmCallback.getText() == null) {
                realmCallback.setText(realmCallback.getDefaultText());
            }
        }
    }
}
Also used : CredentialIdentity(org.jboss.security.identity.extensions.CredentialIdentity) RealmCallback(javax.security.sasl.RealmCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) Set(java.util.Set) SecurityContext(org.jboss.security.SecurityContext) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) Identity(org.jboss.security.identity.Identity) CredentialIdentity(org.jboss.security.identity.extensions.CredentialIdentity) RealmCallback(javax.security.sasl.RealmCallback)

Aggregations

Identity (org.jboss.security.identity.Identity)2 Principal (java.security.Principal)1 Set (java.util.Set)1 Subject (javax.security.auth.Subject)1 Callback (javax.security.auth.callback.Callback)1 NameCallback (javax.security.auth.callback.NameCallback)1 PasswordCallback (javax.security.auth.callback.PasswordCallback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 RealmCallback (javax.security.sasl.RealmCallback)1 AuthenticationManager (org.jboss.security.AuthenticationManager)1 RunAsIdentity (org.jboss.security.RunAsIdentity)1 SecurityContext (org.jboss.security.SecurityContext)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 CredentialIdentity (org.jboss.security.identity.extensions.CredentialIdentity)1 SimpleIdentity (org.jboss.security.identity.plugins.SimpleIdentity)1 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)1