Search in sources :

Example 1 with PrincipalGroupFactory

use of com.sun.enterprise.security.PrincipalGroupFactory in project Payara by payara.

the class DigestLoginModule method commit.

public final boolean commit() throws LoginException {
    if (!_succeeded) {
        _commitSucceeded = false;
        return false;
    }
    PrincipalGroupFactory factory = Globals.getDefaultHabitat().getService(PrincipalGroupFactory.class);
    _userPrincipal = factory.getPrincipalInstance(digestCredentials.getUserName(), digestCredentials.getRealmName());
    java.util.Set principalSet = this.subject.getPrincipals();
    if (!principalSet.contains(_userPrincipal)) {
        principalSet.add(_userPrincipal);
    }
    java.util.Enumeration groupsList = getGroups(digestCredentials.getUserName());
    while (groupsList.hasMoreElements()) {
        java.lang.String value = (java.lang.String) groupsList.nextElement();
        Group g = factory.getGroupInstance(value, digestCredentials.getRealmName());
        if (!principalSet.contains(g)) {
            principalSet.add(g);
        }
    // cleaning the slate
    }
    return true;
}
Also used : Group(org.glassfish.security.common.Group) Enumeration(java.util.Enumeration) Set(java.util.Set) PrincipalGroupFactory(com.sun.enterprise.security.PrincipalGroupFactory)

Example 2 with PrincipalGroupFactory

use of com.sun.enterprise.security.PrincipalGroupFactory in project Payara by payara.

the class BaseCertificateLoginModule method commit.

public final boolean commit() throws LoginException {
    if (!success) {
        return false;
    }
    Set<Principal> principalSet = subject.getPrincipals();
    for (int i = 0; i < groups.length; i++) {
        if (groups[i] != null) {
            Group g = Globals.getDefaultHabitat().<PrincipalGroupFactory>getService(PrincipalGroupFactory.class).getGroupInstance(groups[i], CertificateRealm.AUTH_TYPE);
            principalSet.add(g);
        }
        groups[i] = null;
    }
    groups = null;
    commitsuccess = true;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "JAAS authentication committed.");
    }
    return true;
}
Also used : Group(org.glassfish.security.common.Group) PrincipalGroupFactory(com.sun.enterprise.security.PrincipalGroupFactory) X500Principal(javax.security.auth.x500.X500Principal) Principal(java.security.Principal)

Example 3 with PrincipalGroupFactory

use of com.sun.enterprise.security.PrincipalGroupFactory in project Payara by payara.

the class BasePasswordLoginModule method commit.

/**
 * Commit the authentication.
 *
 * <P>Commit is called after all necessary login modules have succeeded.
 * It adds (if not present) a PrincipalImpl principal and a
 * LocalCredentials public credential to the Subject.
 *
 * @throws LoginException If commit fails.
 */
public boolean commit() throws LoginException {
    if (_succeeded == false) {
        return false;
    }
    // Add a Principal (authenticated identity) to the Subject
    // Assume the user we authenticated is the PrincipalImpl [RI]
    String realm_name = _currentRealm.getName();
    PrincipalGroupFactory factory = Globals.getDefaultHabitat().getService(PrincipalGroupFactory.class);
    if (factory != null)
        _userPrincipal = factory.getPrincipalInstance(getUsername(), realm_name);
    else
        _userPrincipal = new PrincipalImpl(getUsername());
    Set<Principal> principalSet = _subject.getPrincipals();
    if (!principalSet.contains(_userPrincipal)) {
        principalSet.add(_userPrincipal);
    }
    /* populate the group in the subject and clean out the slate at the same
         * time
         */
    for (int i = 0; i < _groupsList.length; i++) {
        if (_groupsList[i] != null) {
            Group g;
            if (factory != null)
                g = factory.getGroupInstance(_groupsList[i], realm_name);
            else
                g = new Group(_groupsList[i]);
            if (!principalSet.contains(g)) {
                principalSet.add(g);
            }
            // cleaning the slate
            _groupsList[i] = null;
        }
    }
    // In any case, clean out state.
    _groupsList = null;
    setUsername(null);
    setPassword(null);
    setPasswordChar(null);
    _commitSucceeded = true;
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "JAAS authentication committed.");
    }
    return true;
}
Also used : Group(org.glassfish.security.common.Group) PrincipalGroupFactory(com.sun.enterprise.security.PrincipalGroupFactory) PrincipalImpl(org.glassfish.security.common.PrincipalImpl) Principal(java.security.Principal)

Aggregations

PrincipalGroupFactory (com.sun.enterprise.security.PrincipalGroupFactory)3 Group (org.glassfish.security.common.Group)3 Principal (java.security.Principal)2 Enumeration (java.util.Enumeration)1 Set (java.util.Set)1 X500Principal (javax.security.auth.x500.X500Principal)1 PrincipalImpl (org.glassfish.security.common.PrincipalImpl)1