Search in sources :

Example 11 with PrincipalImpl

use of org.glassfish.security.common.PrincipalImpl 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)

Example 12 with PrincipalImpl

use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.

the class SubjectUtil method getGroupnamesFromSubject.

/**
 * Utility method to find the group names from a subject. The method assumes the group name is
 * represented by {@link org.glassfish.security.common.Group Group } inside the Subject's principal set.
 * @param subject the subject from which to find the username
 * @return a list of strings representing the group names. The list may have more than one entry if the subject's principal set
 * contains more than one Group instances, or empty entry if the subject's principal set contains no Group instances.
 */
public static List<String> getGroupnamesFromSubject(Subject subject) {
    List<String> groupList = new ArrayList<String>();
    Set<Group> princSet = null;
    if (subject != null) {
        princSet = subject.getPrincipals(Group.class);
        for (PrincipalImpl g : princSet) {
            String gName = g.getName();
            groupList.add(gName);
        }
    }
    return groupList;
}
Also used : Group(org.glassfish.security.common.Group) ArrayList(java.util.ArrayList) PrincipalImpl(org.glassfish.security.common.PrincipalImpl)

Example 13 with PrincipalImpl

use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.

the class ImpersonationServiceImpl method impersonate.

@Override
public Subject impersonate(String user, String[] groups, Subject subject, boolean virtual) throws LoginException {
    // Use the supplied Subject or create a new Subject
    final Subject _subject = (subject != null) ? subject : new Subject();
    if (user == null || user.isEmpty()) {
        return _subject;
    }
    // is available in open source
    if (!virtual) {
        throw new UnsupportedOperationException("Use of non-virtual parameter is not supported");
    } else {
        // Build the Subject
        Set<Principal> principals = _subject.getPrincipals();
        principals.add(new PrincipalImpl(user));
        if (groups != null) {
            for (String group : groups) {
                principals.add(new Group(group));
            }
        }
    }
    // Return the impersonated Subject
    return _subject;
}
Also used : Group(org.glassfish.security.common.Group) Subject(javax.security.auth.Subject) Principal(java.security.Principal) PrincipalImpl(org.glassfish.security.common.PrincipalImpl)

Example 14 with PrincipalImpl

use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.

the class SimpleRoleProviderTest method adminSubject.

private Subject adminSubject() {
    Subject result = new Subject();
    result.getPrincipals().add(new PrincipalImpl("admin"));
    result.getPrincipals().add(new Group("asadmin"));
    return result;
}
Also used : Group(org.glassfish.security.common.Group) Subject(javax.security.auth.Subject) PrincipalImpl(org.glassfish.security.common.PrincipalImpl)

Example 15 with PrincipalImpl

use of org.glassfish.security.common.PrincipalImpl in project Payara by payara.

the class SimpleRoleProviderTest method nonAdminSubject.

private Subject nonAdminSubject() {
    Subject result = new Subject();
    result.getPrincipals().add(new PrincipalImpl("joe"));
    result.getPrincipals().add(new Group("myGroup"));
    return result;
}
Also used : Group(org.glassfish.security.common.Group) Subject(javax.security.auth.Subject) PrincipalImpl(org.glassfish.security.common.PrincipalImpl)

Aggregations

PrincipalImpl (org.glassfish.security.common.PrincipalImpl)17 Subject (javax.security.auth.Subject)8 Group (org.glassfish.security.common.Group)8 Principal (java.security.Principal)5 ArrayList (java.util.ArrayList)2 SecurityRoleMapping (com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping)1 SecurityRoleAssignment (com.sun.enterprise.deployment.runtime.common.wls.SecurityRoleAssignment)1 SunWebApp (com.sun.enterprise.deployment.runtime.web.SunWebApp)1 LoginConfiguration (com.sun.enterprise.deployment.web.LoginConfiguration)1 PrincipalGroupFactory (com.sun.enterprise.security.PrincipalGroupFactory)1 SecurityContext (com.sun.enterprise.security.SecurityContext)1 DistinguishedPrincipalCredential (com.sun.enterprise.security.auth.login.DistinguishedPrincipalCredential)1 PasswordCredential (com.sun.enterprise.security.auth.login.common.PasswordCredential)1 X509CertificateCredential (com.sun.enterprise.security.auth.login.common.X509CertificateCredential)1 AbstractSecurityContext (com.sun.enterprise.security.common.AbstractSecurityContext)1 CachedPermissionImpl (com.sun.enterprise.security.ee.CachedPermissionImpl)1 AppClientSSL (com.sun.enterprise.security.integration.AppClientSSL)1 AppServSecurityContext (com.sun.enterprise.security.integration.AppServSecurityContext)1 WebPrincipal (com.sun.enterprise.security.web.integration.WebPrincipal)1 URL (java.net.URL)1