Search in sources :

Example 6 with StringValue

use of org.apache.jackrabbit.value.StringValue 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 7 with StringValue

use of org.apache.jackrabbit.value.StringValue 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 8 with StringValue

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

the class UserImplTest method testUserCanModifyItsOwnProperties.

public void testUserCanModifyItsOwnProperties() throws RepositoryException, NotExecutableException {
    User u = (User) uMgr.getAuthorizable(uID);
    if (u == null) {
        fail("User " + uID + "hast not been removed and must be visible to the Session created with its credentials.");
    }
    if (!uSession.hasPermission(((UserImpl) u).getNode().getPath(), "set_property")) {
        throw new NotExecutableException("Users should be able to modify their properties -> Check repository config.");
    }
    // single valued properties
    u.setProperty("Email", new StringValue("tu@security.test"));
    save(uSession);
    assertNotNull(u.getProperty("Email"));
    assertEquals("tu@security.test", u.getProperty("Email")[0].getString());
    u.removeProperty("Email");
    save(uSession);
    assertNull(u.getProperty("Email"));
    // multivalued properties
    u.setProperty(propertyName1, new Value[] { uSession.getValueFactory().createValue("anyValue") });
    save(uSession);
    assertNotNull(u.getProperty(propertyName1));
    u.removeProperty(propertyName1);
    save(uSession);
    assertNull(u.getProperty(propertyName1));
}
Also used : User(org.apache.jackrabbit.api.security.user.User) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) StringValue(org.apache.jackrabbit.value.StringValue)

Example 9 with StringValue

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

the class AuthorizableImplTest method testSetSpecialPropertiesDirectly.

public void testSetSpecialPropertiesDirectly() throws NotExecutableException, RepositoryException {
    AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
    NodeImpl n = user.getNode();
    try {
        String pName = user.getPrincipalName();
        n.setProperty(UserConstants.P_PRINCIPAL_NAME, new StringValue("any-value"));
        // should have failed => change value back.
        n.setProperty(UserConstants.P_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.P_IMPERSONATORS, new Value[] { new StringValue(imperson) }, PropertyType.STRING);
        fail("Attempt to change protected property rep:impersonators should fail.");
    } catch (ConstraintViolationException e) {
    // ok.
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) StringValue(org.apache.jackrabbit.value.StringValue)

Example 10 with StringValue

use of org.apache.jackrabbit.value.StringValue in project magnolia-vanity-url by aperto.

the class VanityUrlService method queryForVanityUrlNodes.

/**
 * Query for a vanity url nodes.
 *
 * @param vanityUrl vanity url from request
 * @param siteName  site name from aggegation state
 * @return vanity url nodes or empty list, if nothing found
 */
public List<Node> queryForVanityUrlNodes(final String vanityUrl, final String siteName) {
    List<Node> nodes = Collections.emptyList();
    try {
        Session jcrSession = MgnlContext.getJCRSession(VanityUrlModule.WORKSPACE);
        QueryManager queryManager = jcrSession.getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(QUERY, JCR_SQL2);
        query.bindValue(PN_VANITY_URL, new StringValue(vanityUrl));
        query.bindValue(PN_SITE, new StringValue(siteName));
        QueryResult queryResult = query.execute();
        nodes = asList(asIterable(queryResult.getNodes()));
    } catch (RepositoryException e) {
        LOGGER.error("Error message.", e);
    }
    return nodes;
}
Also used : QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) QueryManager(javax.jcr.query.QueryManager) RepositoryException(javax.jcr.RepositoryException) StringValue(org.apache.jackrabbit.value.StringValue) Session(javax.jcr.Session)

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