Search in sources :

Example 1 with BooleanValue

use of org.apache.jackrabbit.value.BooleanValue in project jackrabbit by apache.

the class EntryTest method testGetGlob.

public void testGetGlob() throws RepositoryException, NotExecutableException {
    Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);
    JackrabbitAccessControlEntry pe = createEntry(testPrincipal, privs, true);
    assertEquals(restrictions.get(glob), pe.getRestriction(glob));
    assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
    Map<String, Value> restr = new HashMap<String, Value>();
    restr.put(nodePath, restrictions.get(nodePath));
    pe = createEntry(testPrincipal, privs, true, restr);
    assertNull(pe.getRestriction(glob));
    restr = new HashMap<String, Value>();
    restr.put(nodePath, restrictions.get(nodePath));
    restr.put(glob, new StringValue(""));
    pe = createEntry(testPrincipal, privs, true, restr);
    assertEquals("", pe.getRestriction(glob).getString());
    restr = new HashMap<String, Value>();
    restr.put(nodePath, restrictions.get(nodePath));
    restr.put(glob, new BooleanValue(true));
    assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) HashMap(java.util.HashMap) BooleanValue(org.apache.jackrabbit.value.BooleanValue) BooleanValue(org.apache.jackrabbit.value.BooleanValue) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) Privilege(javax.jcr.security.Privilege) StringValue(org.apache.jackrabbit.value.StringValue)

Example 2 with BooleanValue

use of org.apache.jackrabbit.value.BooleanValue in project jackrabbit by apache.

the class EntryTest method testTypeConversion.

public void testTypeConversion() throws RepositoryException, NotExecutableException {
    // ACLTemplate impl tries to convert the property types if the don't
    // match the required ones.
    Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);
    Map<String, Value> restr = new HashMap<String, Value>();
    restr.put(nodePath, new StringValue("/a/b/c/d"));
    JackrabbitAccessControlEntry pe = createEntry(testPrincipal, privs, true, restr);
    assertEquals("/a/b/c/d", pe.getRestriction(nodePath).getString());
    assertEquals(PropertyType.PATH, pe.getRestriction(nodePath).getType());
    restr = new HashMap<String, Value>();
    restr.put(nodePath, restrictions.get(nodePath));
    restr.put(glob, new BooleanValue(true));
    pe = createEntry(testPrincipal, privs, true, restr);
    assertEquals(true, pe.getRestriction(glob).getBoolean());
    assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) HashMap(java.util.HashMap) BooleanValue(org.apache.jackrabbit.value.BooleanValue) BooleanValue(org.apache.jackrabbit.value.BooleanValue) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) Privilege(javax.jcr.security.Privilege) StringValue(org.apache.jackrabbit.value.StringValue)

Example 3 with BooleanValue

use of org.apache.jackrabbit.value.BooleanValue in project jackrabbit by apache.

the class EntryTest method testRestrictions.

public void testRestrictions() throws RepositoryException {
    // test if restrictions with expanded name are properly resolved
    Map<String, Value> restrictions = new HashMap<String, Value>();
    restrictions.put(ACLTemplate.P_GLOB.toString(), superuser.getValueFactory().createValue("*/test"));
    restrictions.put(ACLTemplate.P_NODE_PATH.toString(), superuser.getValueFactory().createValue("/a/b/c"));
    Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) };
    ACLTemplate.Entry ace = (ACLTemplate.Entry) createEntry(testPrincipal, privs, true, restrictions);
    Value v = ace.getRestriction(ACLTemplate.P_GLOB.toString());
    Value v2 = ace.getRestriction(glob);
    assertEquals(v, v2);
    v = ace.getRestriction(ACLTemplate.P_NODE_PATH.toString());
    v2 = ace.getRestriction(nodePath);
    assertEquals(v, v2);
    Map<String, Boolean> toMatch = new HashMap<String, Boolean>();
    toMatch.put("/a/b/c", false);
    toMatch.put("/a/b/ctest", false);
    toMatch.put("/a/b/c/test", true);
    toMatch.put("/a/b/c/something/test", true);
    toMatch.put("/a/b/cde/test", true);
    for (String str : toMatch.keySet()) {
        assertEquals("Path to match : " + str, toMatch.get(str).booleanValue(), ace.matches(str));
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) HashMap(java.util.HashMap) BooleanValue(org.apache.jackrabbit.value.BooleanValue) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) Privilege(javax.jcr.security.Privilege)

Aggregations

HashMap (java.util.HashMap)3 Value (javax.jcr.Value)3 Privilege (javax.jcr.security.Privilege)3 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)3 BooleanValue (org.apache.jackrabbit.value.BooleanValue)3 StringValue (org.apache.jackrabbit.value.StringValue)3