Search in sources :

Example 36 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.

the class PrincipalManagerImpl method getGroupMembership.

/**
     * {@inheritDoc}
     */
public PrincipalIterator getGroupMembership(Principal principal) {
    checkIsValid();
    List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length + 1);
    for (PrincipalProvider pp : providers) {
        PrincipalIterator groups = pp.getGroupMembership(principal);
        if (groups.hasNext()) {
            entries.add(new CheckedIteratorEntry(groups, pp));
        }
    }
    // additional entry for the 'everyone' group
    if (!(principal instanceof EveryonePrincipal)) {
        Iterator<Principal> it = Collections.singletonList(getEveryone()).iterator();
        entries.add(new CheckedIteratorEntry(it, null));
    }
    return new CheckedPrincipalIterator(entries);
}
Also used : ArrayList(java.util.ArrayList) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) JackrabbitPrincipal(org.apache.jackrabbit.api.security.principal.JackrabbitPrincipal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Example 37 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.

the class PrincipalManagerImpl method findPrincipals.

/**
     * {@inheritDoc}
     */
public PrincipalIterator findPrincipals(String simpleFilter) {
    checkIsValid();
    List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length);
    for (PrincipalProvider pp : providers) {
        PrincipalIterator it = pp.findPrincipals(simpleFilter);
        if (it.hasNext()) {
            entries.add(new CheckedIteratorEntry(it, pp));
        }
    }
    return new CheckedPrincipalIterator(entries);
}
Also used : ArrayList(java.util.ArrayList) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator)

Example 38 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.

the class PrincipalManagerImpl method getPrincipals.

/**
     * {@inheritDoc}
     * @param searchType
     */
public PrincipalIterator getPrincipals(int searchType) {
    checkIsValid();
    List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length);
    for (PrincipalProvider pp : providers) {
        PrincipalIterator it = pp.getPrincipals(searchType);
        if (it.hasNext()) {
            entries.add(new CheckedIteratorEntry(it, pp));
        }
    }
    return new CheckedPrincipalIterator(entries);
}
Also used : ArrayList(java.util.ArrayList) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator)

Example 39 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project sling by apache.

the class AuthorizableResourceProvider method listChildren.

@Override
public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
    try {
        String path = parent.getPath();
        ResourceResolver resourceResolver = parent.getResourceResolver();
        // handle children of /system/userManager
        if (SYSTEM_USER_MANAGER_PATH.equals(path)) {
            List<Resource> resources = new ArrayList<Resource>();
            if (resourceResolver != null) {
                resources.add(getResource(ctx, SYSTEM_USER_MANAGER_USER_PATH, null, null));
                resources.add(getResource(ctx, SYSTEM_USER_MANAGER_GROUP_PATH, null, null));
            }
            return resources.iterator();
        }
        int searchType = -1;
        if (SYSTEM_USER_MANAGER_USER_PATH.equals(path)) {
            searchType = PrincipalManager.SEARCH_TYPE_NOT_GROUP;
        } else if (SYSTEM_USER_MANAGER_GROUP_PATH.equals(path)) {
            searchType = PrincipalManager.SEARCH_TYPE_GROUP;
        }
        if (searchType != -1) {
            PrincipalIterator principals = null;
            Session session = resourceResolver.adaptTo(Session.class);
            if (session != null) {
                PrincipalManager principalManager = AccessControlUtil.getPrincipalManager(session);
                principals = principalManager.getPrincipals(searchType);
            }
            if (principals != null) {
                return new ChildrenIterator(parent, principals);
            }
        }
    } catch (RepositoryException re) {
        throw new SlingException("Error listing children of resource: " + parent.getPath(), re);
    }
    return null;
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) SlingException(org.apache.sling.api.SlingException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 40 with PrincipalIterator

use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.

the class AbstractLoginModule method getPrincipals.

/**
     * @return a Collection of principals that contains the current user
     * principal and all groups it is member of.
     */
protected Set<Principal> getPrincipals() {
    // use linked HashSet instead of HashSet in order to maintain the order
    // of principals (as in the Subject).
    Set<Principal> principals = new LinkedHashSet<Principal>();
    principals.add(principal);
    PrincipalIterator groups = principalProvider.getGroupMembership(principal);
    while (groups.hasNext()) {
        principals.add(groups.nextPrincipal());
    }
    return principals;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal)

Aggregations

PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)61 Principal (java.security.Principal)40 Test (org.junit.Test)35 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)15 AbstractJCRTest (org.apache.jackrabbit.test.AbstractJCRTest)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)9 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 ArrayList (java.util.ArrayList)8 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)7 Group (java.security.acl.Group)5 RepositoryException (javax.jcr.RepositoryException)4 Group (org.apache.jackrabbit.api.security.user.Group)4 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)4 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)4 HashSet (java.util.HashSet)3 Impersonation (org.apache.jackrabbit.api.security.user.Impersonation)3 User (org.apache.jackrabbit.api.security.user.User)3 Session (javax.jcr.Session)2 Subject (javax.security.auth.Subject)2