Search in sources :

Example 1 with StringValue

use of org.apache.jackrabbit.value.StringValue in project jackrabbit-oak by apache.

the class PermissionTest method addEntry.

private void addEntry(String path, boolean grant, String restriction, String... privilegeNames) throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, path);
    if (restriction.length() > 0) {
        Map<String, Value> rs = new HashMap<String, Value>();
        rs.put("rep:glob", new StringValue(restriction));
        acl.addEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, privilegeNames), grant, rs);
    } else {
        acl.addEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, privilegeNames), grant);
    }
    acMgr.setPolicy(path, acl);
    root.commit();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) HashMap(java.util.HashMap) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) StringValue(org.apache.jackrabbit.value.StringValue) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 2 with StringValue

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

the class ImpersonationImpl method updateImpersonatorNames.

private void updateImpersonatorNames(Set<String> principalNames) throws RepositoryException {
    NodeImpl userNode = user.getNode();
    try {
        String[] pNames = principalNames.toArray(new String[principalNames.size()]);
        if (pNames.length == 0) {
            PropertyImpl prop = userNode.getProperty(P_IMPERSONATORS);
            userManager.removeProtectedItem(prop, userNode);
        } else {
            Value[] values = new Value[pNames.length];
            for (int i = 0; i < pNames.length; i++) {
                values[i] = new StringValue(pNames[i]);
            }
            userManager.setProtectedProperty(userNode, P_IMPERSONATORS, values);
        }
    } catch (RepositoryException e) {
        // revert pending changes
        userNode.refresh(false);
        throw e;
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) PropertyImpl(org.apache.jackrabbit.core.PropertyImpl) RepositoryException(javax.jcr.RepositoryException) StringValue(org.apache.jackrabbit.value.StringValue)

Example 3 with StringValue

use of org.apache.jackrabbit.value.StringValue in project jackrabbit-oak by apache.

the class CustomRestrictionProviderTest method addEntry.

private void addEntry(String path, boolean grant, String restriction, String... privilegeNames) throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, path);
    if (restriction.length() > 0) {
        Map<String, Value> rs = new HashMap<String, Value>();
        rs.put(PropertyRestrictionProvider.RESTRICTION_NAME, new StringValue(restriction));
        acl.addEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, privilegeNames), grant, rs);
    } else {
        acl.addEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, privilegeNames), grant);
    }
    acMgr.setPolicy(path, acl);
    root.commit();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) HashMap(java.util.HashMap) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) StringValue(org.apache.jackrabbit.value.StringValue) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 4 with StringValue

use of org.apache.jackrabbit.value.StringValue in project jackrabbit-oak by apache.

the class AuthorizablePropertyTest method testSetSpecialPropertiesDirectly.

@Test
public void testSetSpecialPropertiesDirectly() throws NotExecutableException, RepositoryException {
    Node n = getNode(user, superuser);
    try {
        String pName = user.getPrincipal().getName();
        n.setProperty(UserConstants.REP_PRINCIPAL_NAME, new StringValue("any-value"));
        // should have failed => change value back.
        n.setProperty(UserConstants.REP_PRINCIPAL_NAME, new StringValue(pName));
        fail("Attempt to change protected property rep:principalName should fail.");
    } catch (ConstraintViolationException e) {
    // ok.
    }
    try {
        String imperson = "anyimpersonator";
        n.setProperty(UserConstants.REP_IMPERSONATORS, new Value[] { new StringValue(imperson) }, PropertyType.STRING);
        fail("Attempt to change protected property rep:impersonators should fail.");
    } catch (ConstraintViolationException e) {
    // ok.
    }
}
Also used : Node(javax.jcr.Node) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) StringValue(org.apache.jackrabbit.value.StringValue) Test(org.junit.Test)

Example 5 with StringValue

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

the class RestrictionTest method addEntry.

private void addEntry(String path, boolean grant, String restriction, String... privilegeNames) throws Exception {
    if (restriction.length() > 0) {
        Map<String, Value> rs = new HashMap<String, Value>();
        rs.put("rep:glob", new StringValue(restriction));
        modifyPrivileges(path, testUser.getPrincipal(), AccessControlUtils.privilegesFromNames(acMgr, privilegeNames), grant, rs);
    } else {
        modifyPrivileges(path, testUser.getPrincipal(), AccessControlUtils.privilegesFromNames(acMgr, privilegeNames), grant, Collections.<String, Value>emptyMap());
    }
}
Also used : HashMap(java.util.HashMap) Value(javax.jcr.Value) StringValue(org.apache.jackrabbit.value.StringValue) StringValue(org.apache.jackrabbit.value.StringValue)

Aggregations

StringValue (org.apache.jackrabbit.value.StringValue)12 Value (javax.jcr.Value)6 HashMap (java.util.HashMap)5 Node (javax.jcr.Node)2 RepositoryException (javax.jcr.RepositoryException)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 AccessControlManager (javax.jcr.security.AccessControlManager)2 Privilege (javax.jcr.security.Privilege)2 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)2 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)2 NodeImpl (org.apache.jackrabbit.core.NodeImpl)2 BooleanValue (org.apache.jackrabbit.value.BooleanValue)2 Test (org.junit.Test)2 Session (javax.jcr.Session)1 Query (javax.jcr.query.Query)1 QueryManager (javax.jcr.query.QueryManager)1 QueryResult (javax.jcr.query.QueryResult)1 User (org.apache.jackrabbit.api.security.user.User)1 PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1