Search in sources :

Example 16 with SecurityReference

use of org.xwiki.security.SecurityReference in project xwiki-platform by xwiki.

the class DefaultSecurityCacheLoader method getRules.

/**
 * Retrieve rules for all hierarchy levels of the provided reference.
 * Rules may be read from the cache, or from the entities and fill the cache.
 *
 * @param entity The entity for which rules should be loaded and retrieve.
 * @return A collection of security rule entry, once for each level of the hierarchy.
 * @exception org.xwiki.security.authorization.AuthorizationException if an error occurs
 * @exception ParentEntryEvictedException if any parent entry is
 * evicted before the operation completes.
 * @throws ConflictingInsertionException When different threads
 * have inserted conflicting entries into the cache.
 */
private Deque<SecurityRuleEntry> getRules(SecurityReference entity) throws AuthorizationException, ParentEntryEvictedException, ConflictingInsertionException {
    Deque<SecurityRuleEntry> rules = new LinkedList<SecurityRuleEntry>();
    List<SecurityRuleEntry> emptyRuleEntryTail = new ArrayList<SecurityRuleEntry>();
    for (SecurityReference ref : entity.getReversedSecurityReferenceChain()) {
        SecurityRuleEntry entry = securityCache.get(ref);
        if (entry == null) {
            if (Right.getEnabledRights(ref.getType()).isEmpty()) {
                // Do not call the reader on entity that will give useless rules
                entry = new EmptySecurityRuleEntry(ref);
                emptyRuleEntryTail.add(entry);
            } else {
                entry = securityEntryReader.read(ref);
                if (!emptyRuleEntryTail.isEmpty()) {
                    // Add intermediate empty rules sets to the cache to hold this significant one
                    for (SecurityRuleEntry emptyRuleEntry : emptyRuleEntryTail) {
                        securityCache.add(emptyRuleEntry);
                    }
                    emptyRuleEntryTail.clear();
                }
                securityCache.add(entry);
            }
        }
        rules.push(entry);
    }
    return rules;
}
Also used : AbstractSecurityRuleEntry(org.xwiki.security.authorization.internal.AbstractSecurityRuleEntry) SecurityRuleEntry(org.xwiki.security.authorization.SecurityRuleEntry) ArrayList(java.util.ArrayList) GroupSecurityReference(org.xwiki.security.GroupSecurityReference) SecurityReference(org.xwiki.security.SecurityReference) UserSecurityReference(org.xwiki.security.UserSecurityReference) LinkedList(java.util.LinkedList)

Example 17 with SecurityReference

use of org.xwiki.security.SecurityReference in project xwiki-platform by xwiki.

the class AbstractAuthorizationSettler method settle.

@Override
public SecurityAccessEntry settle(UserSecurityReference user, Collection<GroupSecurityReference> groups, Deque<SecurityRuleEntry> ruleEntries) {
    XWikiSecurityAccess access = new XWikiSecurityAccess();
    SecurityReference reference = null;
    Policies policies = new Policies();
    for (SecurityRuleEntry entry : ruleEntries) {
        if (!entry.isEmpty()) {
            // Chose the highest possible level to store the resulting access
            if (reference == null) {
                reference = entry.getReference();
            }
            // Compute access of this level and merge it with previous access result
            merge(settle(user, groups, entry, policies), access, entry.getReference(), policies);
        }
        if (reference == null && entry.getReference().getType() == EntityType.WIKI) {
            reference = entry.getReference();
        }
    }
    // Apply defaults and return the resulting access entry
    return new InternalSecurityAccessEntry(user, reference, applyDefaults(user, reference, access));
}
Also used : SecurityRuleEntry(org.xwiki.security.authorization.SecurityRuleEntry) GroupSecurityReference(org.xwiki.security.GroupSecurityReference) SecurityReference(org.xwiki.security.SecurityReference) UserSecurityReference(org.xwiki.security.UserSecurityReference)

Aggregations

SecurityReference (org.xwiki.security.SecurityReference)17 UserSecurityReference (org.xwiki.security.UserSecurityReference)17 GroupSecurityReference (org.xwiki.security.GroupSecurityReference)16 SecurityRuleEntry (org.xwiki.security.authorization.SecurityRuleEntry)8 SecurityEntry (org.xwiki.security.authorization.SecurityEntry)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 SecurityAccessEntry (org.xwiki.security.authorization.SecurityAccessEntry)4 HashMap (java.util.HashMap)3 ConflictingInsertionException (org.xwiki.security.authorization.cache.ConflictingInsertionException)3 ParentEntryEvictedException (org.xwiki.security.authorization.cache.ParentEntryEvictedException)3 AbstractSecurityRuleEntry (org.xwiki.security.authorization.internal.AbstractSecurityRuleEntry)3 LinkedList (java.util.LinkedList)2 SecurityRule (org.xwiki.security.authorization.SecurityRule)2 SecurityShadowEntry (org.xwiki.security.authorization.cache.SecurityShadowEntry)2 ArrayDeque (java.util.ArrayDeque)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1