use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.
the class EntryTest method testGetRestrictionsForMultiValued2.
/**
* @since OAK 1.0: support for multi-value restrictions
*/
@Test
public void testGetRestrictionsForMultiValued2() throws Exception {
// single value restriction stored in multi-value property
Restriction singleNameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, new Value[] { nameValue });
ACE ace = createEntry(ImmutableSet.of(singleNameRestr));
Value[] vs = ace.getRestrictions(AccessControlConstants.REP_NT_NAMES);
assertEquals(1, vs.length);
assertEquals(nameValue, vs[0]);
}
use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.
the class ACL method addEntry.
// ----------------------------------------< JackrabbitAccessControlList >---
@Override
public boolean addEntry(Principal principal, Privilege[] privileges, boolean isAllow, Map<String, Value> restrictions, Map<String, Value[]> mvRestrictions) throws RepositoryException {
if (privileges == null || privileges.length == 0) {
throw new AccessControlException("Privileges may not be null nor an empty array");
}
for (Privilege p : privileges) {
Privilege pv = getPrivilegeManager().getPrivilege(p.getName());
if (pv.isAbstract()) {
throw new AccessControlException("Privilege " + p + " is abstract.");
}
}
if (!checkValidPrincipal(principal)) {
return false;
}
for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(getOakPath())) {
String jcrName = getNamePathMapper().getJcrName(def.getName());
if (def.isMandatory() && (restrictions == null || !restrictions.containsKey(jcrName))) {
throw new AccessControlException("Mandatory restriction " + jcrName + " is missing.");
}
}
Set<Restriction> rs;
if (restrictions == null && mvRestrictions == null) {
rs = Collections.emptySet();
} else {
rs = new HashSet<Restriction>();
if (restrictions != null) {
for (String jcrName : restrictions.keySet()) {
String oakName = getNamePathMapper().getOakName(jcrName);
rs.add(getRestrictionProvider().createRestriction(getOakPath(), oakName, restrictions.get(oakName)));
}
}
if (mvRestrictions != null) {
for (String jcrName : mvRestrictions.keySet()) {
String oakName = getNamePathMapper().getOakName(jcrName);
rs.add(getRestrictionProvider().createRestriction(getOakPath(), oakName, mvRestrictions.get(oakName)));
}
}
}
ACE entry = createACE(principal, getPrivilegeBits(privileges), isAllow, rs);
if (entries.contains(entry)) {
log.debug("Entry is already contained in policy -> no modification.");
return false;
} else {
return internalAddEntry(entry);
}
}
use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.
the class ACETest method testGetRestrictionsForMultiValued2.
/**
* @since OAK 1.0: support for multi-value restrictions
*/
@Test
public void testGetRestrictionsForMultiValued2() throws Exception {
// single value restriction stored in multi-value property
Restriction singleNameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, new Value[] { nameValue });
ACE ace = createEntry(singleNameRestr);
Value[] vs = ace.getRestrictions(AccessControlConstants.REP_NT_NAMES);
assertEquals(1, vs.length);
assertEquals(nameValue, vs[0]);
}
use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.
the class ACETest method testGetRestrictionForMultiValued.
/**
* @since OAK 1.0: support for multi-value restrictions
*/
@Test(expected = ValueFormatException.class)
public void testGetRestrictionForMultiValued() throws Exception {
// multivalued restriction
Restriction nameRestr = createRestriction(AccessControlConstants.REP_NT_NAMES, nameValues);
ACE ace = createEntry(nameRestr);
ace.getRestriction(AccessControlConstants.REP_NT_NAMES);
}
use of org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction in project jackrabbit-oak by apache.
the class ACETest method testGetNonExistingRestriction.
@Test
public void testGetNonExistingRestriction() throws Exception {
// single valued restriction
Restriction globRestr = createRestriction(AccessControlConstants.REP_GLOB, globValue);
ACE ace = createEntry(globRestr);
assertNull(ace.getRestriction(AccessControlConstants.REP_NT_NAMES));
}
Aggregations