use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl in project jackrabbit by apache.
the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.
private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
DavPropertyNameSet nameSet = new DavPropertyNameSet();
nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
HttpPropfind request = null;
try {
request = new HttpPropfind(uri, nameSet, DEPTH_0);
HttpResponse response = executeRequest(sessionInfo, request);
request.checkSuccess(response);
MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
if (mresponses.length < 1) {
throw new PathNotFoundException("Unable to retrieve privileges definitions.");
}
DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
if (p == null) {
return new PrivilegeDefinition[0];
} else {
// build PrivilegeDefinition(s) from the supported-privileges dav property
Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
for (Name privilegeName : spMap.keySet()) {
SupportedPrivilege sp = spMap.get(privilegeName);
Set<Name> aggrnames = null;
SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
if (aggregates != null && aggregates.length > 0) {
aggrnames = new HashSet<Name>();
for (SupportedPrivilege aggregate : aggregates) {
Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
aggrnames.add(aggregateName);
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
pDefs.add(def);
}
return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
}
} catch (IOException e) {
throw new RepositoryException(e);
} catch (DavException e) {
throw ExceptionConverter.generate(e);
} finally {
if (request != null) {
request.releaseConnection();
}
}
}
use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl in project jackrabbit by apache.
the class PrivilegeRegistry method registerDefinition.
// -----------------------------------< methods used by PrivilegeManager >---
/**
* Validates and registers a new custom privilege definition with the
* specified characteristics. Upon successful registration the new custom
* definition is persisted in the corresponding file system resource.
* <p>
* The validation includes the following steps:
* <ul>
* <li>assert uniqueness of the specified privilegeName</li>
* <li>make sure the name doesn't use a reserved namespace</li>
* <li>assert that all names referenced in the specified name set refer
* to existing privilege definitions.</li>
* </ul>
*
* @param privilegeName
* @param isAbstract
* @param declaredAggregateNames
* @throws RepositoryException If the privilege could not be registered due
* to constraint violations or if persisting the custom privilege fails.
*/
void registerDefinition(Name privilegeName, boolean isAbstract, Set<Name> declaredAggregateNames) throws RepositoryException {
PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, isAbstract, declaredAggregateNames);
Map<Name, PrivilegeDefinition> stubs = Collections.singletonMap(privilegeName, def);
registerCustomDefinitions(stubs);
// inform clustering about the new privilege.
if (eventChannel != null) {
eventChannel.registeredPrivileges(stubs.values());
}
}
use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl in project jackrabbit by apache.
the class ClusterRecordTest method testPrivilegeRegistration.
/**
* Test producing and consuming a privilege registration.
* @throws Exception
*/
public void testPrivilegeRegistration() throws Exception {
PrivilegeDefinition pdf = new PrivilegeDefinitionImpl(NameFactoryImpl.getInstance().create("", "test"), false, null);
PrivilegeEvent event = new PrivilegeEvent(Collections.singletonList(pdf));
master.registeredPrivileges(event.getDefinitions());
SimpleEventListener listener = new SimpleEventListener();
slave.setListener((PrivilegeEventListener) listener);
slave.sync();
assertEquals(1, listener.getClusterEvents().size());
assertEquals(listener.getClusterEvents().get(0), event);
}
use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl in project jackrabbit by apache.
the class RepositoryServiceImpl method getSupportedPrivileges.
public PrivilegeDefinition[] getSupportedPrivileges(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
String path = (nodeId == null) ? null : pathForId(nodeId, sInfo);
Privilege[] privs = sInfo.getSession().getAccessControlManager().getSupportedPrivileges(path);
PrivilegeDefinition[] pDefs = new PrivilegeDefinition[privs.length];
NamePathResolver npResolver = sInfo.getNamePathResolver();
for (int i = 0; i < privs.length; i++) {
Set<Name> aggrnames = null;
if (privs[i].isAggregate()) {
aggrnames = new HashSet<Name>();
for (Privilege dap : privs[i].getDeclaredAggregatePrivileges()) {
aggrnames.add(npResolver.getQName(dap.getName()));
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(npResolver.getQName(privs[i].getName()), privs[i].isAbstract(), aggrnames);
pDefs[i] = def;
}
return pDefs;
}
use of org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl in project jackrabbit by apache.
the class CustomPrivilegeTest method testCustomEquivalentDefinitions.
public void testCustomEquivalentDefinitions() throws RepositoryException, FileSystemException, IOException {
// setup the custom privilege file with cyclic references
FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
if (!resource.exists()) {
resource.makeParentDirs();
}
NameFactory nf = NameFactoryImpl.getInstance();
Name test = nf.create(Name.NS_DEFAULT_URI, "test");
Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
Name test6 = nf.create(Name.NS_DEFAULT_URI, "test6");
OutputStream out = resource.getOutputStream();
try {
List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
defs.add(new PrivilegeDefinitionImpl(test, false, createNameSet(test2, test3)));
defs.add(new PrivilegeDefinitionImpl(test2, true, Collections.singleton(test4)));
defs.add(new PrivilegeDefinitionImpl(test3, true, Collections.singleton(test5)));
defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.<Name>emptySet()));
defs.add(new PrivilegeDefinitionImpl(test5, true, Collections.<Name>emptySet()));
// the equivalent definition to 'test'
defs.add(new PrivilegeDefinitionImpl(test6, false, createNameSet(test2, test5)));
PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
fail("Equivalent definitions must be detected upon registry startup.");
} catch (RepositoryException e) {
// success
} finally {
out.close();
fs.deleteFolder("/privileges");
}
}
Aggregations