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());
}
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());
}
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));
}
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.
}
}
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;
}
Aggregations