use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.
the class PrivilegeManagerImpl method registerPrivilege.
@Override
public Privilege registerPrivilege(String privilegeName, boolean isAbstract, String[] declaredAggregateNames) throws RepositoryException {
if (root.hasPendingChanges()) {
throw new InvalidItemStateException("Attempt to register a new privilege while there are pending changes.");
}
if (privilegeName == null || privilegeName.isEmpty()) {
throw new RepositoryException("Invalid privilege name " + privilegeName);
}
PrivilegeDefinition definition = new ImmutablePrivilegeDefinition(getOakName(privilegeName), isAbstract, getOakNames(declaredAggregateNames));
PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(getWriteRoot());
writer.writeDefinition(definition);
// refresh the current root to make sure the definition is visible
root.refresh();
return getPrivilege(definition);
}
use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.
the class PrivilegeDefinitionReader method readDefinitions.
/**
* Read all registered privilege definitions from the content.
*
* @return All privilege definitions stored in the content.
*/
@Nonnull
Map<String, PrivilegeDefinition> readDefinitions() {
Map<String, PrivilegeDefinition> definitions = new HashMap();
for (Tree child : privilegesTree.getChildren()) {
if (isPrivilegeDefinition(child)) {
PrivilegeDefinition def = PrivilegeUtil.readDefinition(child);
definitions.put(def.getName(), def);
}
}
return definitions;
}
use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.
the class PrivilegeImplTest method testNotEquals.
@Test
public void testNotEquals() throws Exception {
assertNotEquals(privilege, aggrPrivilege);
assertNotEquals(allPrivilege, privilege);
final PrivilegeDefinition def = new PrivilegeDefinitionReader(root).readDefinition(privilege.getName());
assertNotNull(def);
assertNotEquals(privilege, new Privilege() {
@Override
public String getName() {
return def.getName();
}
@Override
public boolean isAbstract() {
return def.isAbstract();
}
@Override
public boolean isAggregate() {
return !def.getDeclaredAggregateNames().isEmpty();
}
@Override
public Privilege[] getDeclaredAggregatePrivileges() {
throw new UnsupportedOperationException();
}
@Override
public Privilege[] getAggregatePrivileges() {
throw new UnsupportedOperationException();
}
});
}
use of org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition in project jackrabbit-oak by apache.
the class L5_PrivilegeContentTest method testPrivilegeDefinition.
@Test
public void testPrivilegeDefinition() throws RepositoryException {
Tree repWriteTree = PrivilegeUtil.getPrivilegesTree(root).getChild(PrivilegeConstants.REP_WRITE);
PrivilegeDefinition def = PrivilegeUtil.readDefinition(repWriteTree);
// EXERCISE
String expectedName = null;
assertEquals(expectedName, def.getName());
// EXERCISE
boolean isAbstract = false;
assertEquals(isAbstract, def.isAbstract());
// EXERCISE
Set<String> expectedAggregates = null;
assertEquals(expectedAggregates, def.getDeclaredAggregateNames());
// EXERCISE: compare the internal privilege definition (and it's tree representation) with the privilege itself.
Privilege repWritePrivilege = getPrivilegeManager(root).getPrivilege(PrivilegeConstants.REP_WRITE);
}
Aggregations