Search in sources :

Example 16 with PrincipalImpl

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

the class SubjectUtilTest method createSub.

public static Subject createSub(String username, String[] groups) {
    Set<Principal> pset = new HashSet<Principal>();
    if (username != null) {
        Principal u = new PrincipalImpl(username);
        pset.add(u);
    }
    if (groups != null) {
        for (String g : groups) {
            if (g != null) {
                Principal p = new org.glassfish.security.common.Group(g);
                pset.add(p);
            }
        }
    }
    Set prvSet = new HashSet();
    Set<Object> pubSet = new HashSet<Object>();
    Subject sub = new Subject(false, pset, pubSet, prvSet);
    return sub;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Principal(java.security.Principal) PrincipalImpl(org.glassfish.security.common.PrincipalImpl) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Example 17 with PrincipalImpl

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

the class ConnectorStarter method getAccessController.

public JMXAuthenticator getAccessController() {
    // needed by the system.
    return new JMXAuthenticator() {

        /**
         * We actually wait for the first authentication request to delegate/
         * @param credentials
         * @return
         */
        public Subject authenticate(Object credentials) {
            // lazy init...
            // todo : lloyd, if this becomes a performance bottleneck, we should cache
            // on first access.
            JMXAuthenticator controller = mHabitat.getService(JMXAuthenticator.class);
            Subject adminSubject = controller.authenticate(credentials);
            if (adminSubject != null) {
                // extract the principal name and create a JMXPrincipal and add to the subject PAYARA-1251
                Set<PrincipalImpl> principals = adminSubject.getPrincipals(PrincipalImpl.class);
                for (PrincipalImpl principal : principals) {
                    if (!(principal instanceof Group) && !(principal instanceof Role)) {
                        adminSubject.getPrincipals().add(new JMXPrincipal(principal.getName()));
                    }
                }
            }
            return adminSubject;
        }
    };
}
Also used : Role(org.glassfish.security.common.Role) Group(org.glassfish.security.common.Group) JMXAuthenticator(javax.management.remote.JMXAuthenticator) JMXPrincipal(javax.management.remote.JMXPrincipal) 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