Search in sources :

Example 1 with EntityTypeNotSupportedException

use of org.xwiki.security.authorization.EntityTypeNotSupportedException in project xwiki-platform by xwiki.

the class DefaultSecurityEntryReader method read.

/**
 * Load the rules from wiki documents.
 *
 * @param entity Any entity reference that is either a WIKI or a SPACE, or an entity containing a DOCUMENT entity.
 * @return the access rules that could be loaded into the cache.
 * @throws org.xwiki.security.authorization.AuthorizationException if an issue arise while reading these rules
 *         from the wiki.
 */
@Override
public SecurityRuleEntry read(SecurityReference entity) throws AuthorizationException {
    if (entity == null) {
        return null;
    }
    if (entity.getOriginalReference() == null) {
        // More generally, any reference without a valid original reference should not be considered.
        return new InternalSecurityRuleEntry(entity, Collections.<SecurityRule>emptyList());
    }
    DocumentReference documentReference;
    DocumentReference classReference;
    WikiReference wikiReference;
    switch(entity.getType()) {
        case WIKI:
            wikiReference = new WikiReference(entity);
            SpaceReference wikiSpace = new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference);
            documentReference = new DocumentReference(XWikiConstants.WIKI_DOC, wikiSpace);
            classReference = new DocumentReference(XWikiConstants.GLOBAL_CLASSNAME, wikiSpace);
            break;
        case SPACE:
            wikiReference = new WikiReference(entity.extractReference(EntityType.WIKI));
            documentReference = new DocumentReference(XWikiConstants.SPACE_DOC, new SpaceReference(entity));
            classReference = new DocumentReference(XWikiConstants.GLOBAL_CLASSNAME, new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference));
            break;
        case DOCUMENT:
            wikiReference = new WikiReference(entity.extractReference(EntityType.WIKI));
            documentReference = new DocumentReference(entity);
            classReference = new DocumentReference(XWikiConstants.LOCAL_CLASSNAME, new SpaceReference(XWikiConstants.XWIKI_SPACE, wikiReference));
            break;
        default:
            throw new EntityTypeNotSupportedException(entity.getType(), this);
    }
    return new InternalSecurityRuleEntry(entity, getSecurityRules(documentReference, classReference, wikiReference));
}
Also used : EntityTypeNotSupportedException(org.xwiki.security.authorization.EntityTypeNotSupportedException) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 EntityTypeNotSupportedException (org.xwiki.security.authorization.EntityTypeNotSupportedException)1