use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit-oak by apache.
the class PrivilegeManagementTest method testRegisterPrivilege.
@Test
public void testRegisterPrivilege() throws Exception {
try {
Workspace testWsp = testSession.getWorkspace();
((JackrabbitWorkspace) testWsp).getPrivilegeManager().registerPrivilege(getNewPrivilegeName(testWsp), false, new String[0]);
fail("Privilege registration should be denied.");
} catch (AccessDeniedException e) {
// success
}
}
use of org.apache.jackrabbit.api.JackrabbitWorkspace in project jackrabbit by apache.
the class RepositoryServiceImpl method getPrivilegeDefinitions.
@Override
public PrivilegeDefinition[] getPrivilegeDefinitions(SessionInfo sessionInfo) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
Session session = sInfo.getSession();
Workspace wsp = session.getWorkspace();
Collection<Privilege> privs;
if (wsp instanceof JackrabbitWorkspace) {
privs = Arrays.asList(((JackrabbitWorkspace) wsp).getPrivilegeManager().getRegisteredPrivileges());
} else {
Privilege jcrAll = session.getAccessControlManager().privilegeFromName(Privilege.JCR_ALL);
privs = new HashSet<Privilege>();
privs.add(jcrAll);
for (Privilege p : jcrAll.getAggregatePrivileges()) {
privs.add(p);
}
}
PrivilegeDefinition[] pDefs = new PrivilegeDefinition[privs.size()];
NamePathResolver npResolver = sInfo.getNamePathResolver();
int i = 0;
for (Privilege p : privs) {
Set<Name> aggrnames = null;
if (p.isAggregate()) {
aggrnames = new HashSet<Name>();
for (Privilege dap : p.getDeclaredAggregatePrivileges()) {
aggrnames.add(npResolver.getQName(dap.getName()));
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(npResolver.getQName(p.getName()), p.isAbstract(), aggrnames);
pDefs[i++] = def;
}
return pDefs;
}
Aggregations