use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.
the class PrivilegeUpgradeTest method verifyPrivileges.
@Test
public void verifyPrivileges() throws RepositoryException {
Set<String> nonAggregatePrivileges = newHashSet(REP_READ_NODES, REP_READ_PROPERTIES, REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES, REP_REMOVE_PROPERTIES, JCR_ADD_CHILD_NODES, JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE, JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL, JCR_NODE_TYPE_MANAGEMENT, JCR_VERSION_MANAGEMENT, JCR_LOCK_MANAGEMENT, JCR_LIFECYCLE_MANAGEMENT, JCR_RETENTION_MANAGEMENT, JCR_WORKSPACE_MANAGEMENT, JCR_NODE_TYPE_DEFINITION_MANAGEMENT, JCR_NAMESPACE_MANAGEMENT, REP_PRIVILEGE_MANAGEMENT, REP_USER_MANAGEMENT, REP_INDEX_DEFINITION_MANAGEMENT, "test:privilege", "test:privilege2");
Map<String, Set<String>> aggregatePrivileges = Maps.newHashMap();
aggregatePrivileges.put(JCR_READ, ImmutableSet.of(REP_READ_NODES, REP_READ_PROPERTIES));
aggregatePrivileges.put(JCR_MODIFY_PROPERTIES, ImmutableSet.of(REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES, REP_REMOVE_PROPERTIES));
aggregatePrivileges.put(JCR_WRITE, ImmutableSet.of(JCR_MODIFY_PROPERTIES, REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES, REP_REMOVE_PROPERTIES, JCR_ADD_CHILD_NODES, JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE));
aggregatePrivileges.put(REP_WRITE, ImmutableSet.of(JCR_WRITE, JCR_MODIFY_PROPERTIES, REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES, REP_REMOVE_PROPERTIES, JCR_ADD_CHILD_NODES, JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE, JCR_NODE_TYPE_MANAGEMENT));
aggregatePrivileges.put(JCR_ALL, ImmutableSet.of(REP_READ_NODES, REP_READ_PROPERTIES, REP_ADD_PROPERTIES, REP_ALTER_PROPERTIES, REP_REMOVE_PROPERTIES, JCR_ADD_CHILD_NODES, JCR_REMOVE_CHILD_NODES, JCR_REMOVE_NODE, JCR_READ_ACCESS_CONTROL, JCR_MODIFY_ACCESS_CONTROL, JCR_NODE_TYPE_MANAGEMENT, JCR_VERSION_MANAGEMENT, JCR_LOCK_MANAGEMENT, JCR_LIFECYCLE_MANAGEMENT, JCR_RETENTION_MANAGEMENT, JCR_WORKSPACE_MANAGEMENT, JCR_NODE_TYPE_DEFINITION_MANAGEMENT, JCR_NAMESPACE_MANAGEMENT, REP_PRIVILEGE_MANAGEMENT, REP_USER_MANAGEMENT, REP_INDEX_DEFINITION_MANAGEMENT, JCR_READ, JCR_MODIFY_PROPERTIES, JCR_WRITE, REP_WRITE, "test:privilege", "test:privilege2", "test:aggregate", "test:aggregate2"));
aggregatePrivileges.put("test:aggregate", ImmutableSet.of(JCR_READ, REP_READ_NODES, REP_READ_PROPERTIES, "test:privilege"));
aggregatePrivileges.put("test:aggregate2", ImmutableSet.of(JCR_READ, REP_READ_NODES, REP_READ_PROPERTIES, "test:privilege", "test:privilege2", "test:aggregate"));
JackrabbitSession session = createAdminSession();
try {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
PrivilegeManager manager = workspace.getPrivilegeManager();
Privilege[] privileges = manager.getRegisteredPrivileges();
for (Privilege privilege : privileges) {
if (privilege.isAggregate()) {
Set<String> expected = aggregatePrivileges.remove(privilege.getName());
if (expected != null) {
String[] actual = getNames(privilege.getAggregatePrivileges());
assertTrue("Miss match in aggregate privilege " + privilege.getName() + " expected " + expected + " actual " + Arrays.toString(actual), newHashSet(expected).equals(newHashSet(actual)));
}
} else {
nonAggregatePrivileges.remove(privilege.getName());
}
}
assertTrue("Missing non aggregate privileges: " + nonAggregatePrivileges, nonAggregatePrivileges.isEmpty());
assertTrue("Missing aggregate privileges: " + aggregatePrivileges.keySet(), aggregatePrivileges.isEmpty());
} finally {
session.logout();
}
}
use of org.apache.jackrabbit.api.security.authorization.PrivilegeManager in project jackrabbit-oak by apache.
the class PrivilegeUpgradeTest method createSourceContent.
@Override
protected void createSourceContent(Session session) throws Exception {
JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
registry.registerNamespace("test", "http://www.example.org/");
PrivilegeManager privilegeManager = workspace.getPrivilegeManager();
privilegeManager.registerPrivilege("test:privilege", false, null);
privilegeManager.registerPrivilege("test:aggregate", false, new String[] { "jcr:read", "test:privilege" });
privilegeManager.registerPrivilege("test:privilege2", true, null);
privilegeManager.registerPrivilege("test:aggregate2", true, new String[] { "test:aggregate", "test:privilege2" });
}
Aggregations