use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class AggregatingDescriptorsTest method testInitialDescriptors.
@Test
public void testInitialDescriptors() throws Exception {
final ValueFactory valueFactory = new SimpleValueFactory();
final MyTracker<Descriptors> tracker = createTracker();
final GenericDescriptors input = new GenericDescriptors();
input.put("a", valueFactory.createValue("b"), true, false);
input.put("b", valueFactory.createValue("c"), true, true);
tracker.addService(input);
AggregatingDescriptors aggregator = new AggregatingDescriptors(tracker);
assertMatches(aggregator, 2, input);
}
use of javax.jcr.ValueFactory in project jackrabbit-oak by apache.
the class AggregatingDescriptorsTest method testLaterAddedDescriptors.
@Test
public void testLaterAddedDescriptors() throws Exception {
final ValueFactory valueFactory = new SimpleValueFactory();
final MyTracker<Descriptors> tracker = createTracker();
AggregatingDescriptors aggregator = new AggregatingDescriptors(tracker);
assertMatches(aggregator, 0);
final GenericDescriptors input1 = new GenericDescriptors();
input1.put("a", valueFactory.createValue("b"), true, false);
input1.put("b", valueFactory.createValue("c"), true, true);
tracker.addService(input1);
assertMatches(aggregator, 2, input1);
final GenericDescriptors input2 = new GenericDescriptors();
input2.put("b", valueFactory.createValue("c2"), true, true);
input2.put("c", valueFactory.createValue("d"), true, true);
tracker.addService(input2);
assertMatches(aggregator, 3, input2, input1);
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class ACLEditor method setPolicy.
/**
* @see AccessControlEditor#setPolicy(String,AccessControlPolicy)
*/
public void setPolicy(String nodePath, AccessControlPolicy policy) throws RepositoryException {
checkProtectsNode(nodePath);
checkValidPolicy(nodePath, policy);
NodeImpl aclNode = getAclNode(nodePath);
if (aclNode != null) {
// remove all existing aces
for (NodeIterator aceNodes = aclNode.getNodes(); aceNodes.hasNext(); ) {
NodeImpl aceNode = (NodeImpl) aceNodes.nextNode();
removeItem(aceNode);
}
} else {
// create the acl node
aclNode = (nodePath == null) ? createRepoAclNode() : createAclNode(nodePath);
}
AccessControlEntry[] entries = ((ACLTemplate) policy).getAccessControlEntries();
for (AccessControlEntry entry : entries) {
AccessControlEntryImpl ace = (AccessControlEntryImpl) entry;
Name nodeName = getUniqueNodeName(aclNode, ace.isAllow() ? "allow" : "deny");
Name ntName = (ace.isAllow()) ? NT_REP_GRANT_ACE : NT_REP_DENY_ACE;
ValueFactory vf = session.getValueFactory();
// create the ACE node
NodeImpl aceNode = addNode(aclNode, nodeName, ntName);
// write the rep:principalName property
String principalName = ace.getPrincipal().getName();
setProperty(aceNode, P_PRINCIPAL_NAME, vf.createValue(principalName));
// ... and the rep:privileges property
Privilege[] pvlgs = ace.getPrivileges();
Value[] names = getPrivilegeNames(pvlgs, vf);
setProperty(aceNode, P_PRIVILEGES, names);
// store the restrictions:
Set<Name> restrNames = ace.getRestrictions().keySet();
for (Name restrName : restrNames) {
Value value = ace.getRestriction(restrName);
setProperty(aceNode, restrName, value);
}
}
// mark the parent modified.
markModified(((NodeImpl) aclNode.getParent()));
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class TokenProvider method createToken.
/**
* Create a separate token node underneath a dedicated token store within
* the user home node. That token node contains the hashed token, the
* expiration time and additional mandatory attributes that will be verified
* during login.
*
* @param userId The identifier of the user for which a new token should
* be created.
* @param attributes The attributes associated with the new token.
* @return A new {@code TokenInfo} or {@code null} if the token could not
* be created.
*/
private TokenInfo createToken(User user, Map<String, ?> attributes) throws RepositoryException {
String error = "Failed to create login token. ";
NodeImpl tokenParent = getTokenParent(user);
if (tokenParent != null) {
try {
ValueFactory vf = session.getValueFactory();
long creationTime = new Date().getTime();
Calendar creation = GregorianCalendar.getInstance();
creation.setTimeInMillis(creationTime);
Name tokenName = session.getQName(Text.replace(ISO8601.format(creation), ":", "."));
NodeImpl tokenNode = super.addNode(tokenParent, tokenName, session.getQName(TOKEN_NT_NAME), NodeId.randomId());
String key = generateKey(8);
String token = new StringBuilder(tokenNode.getId().toString()).append(DELIM).append(key).toString();
String keyHash = PasswordUtility.buildPasswordHash(getKeyValue(key, user.getID()));
setProperty(tokenNode, session.getQName(TOKEN_ATTRIBUTE_KEY), vf.createValue(keyHash));
setProperty(tokenNode, session.getQName(TOKEN_ATTRIBUTE_EXPIRY), createExpirationValue(creationTime, session));
for (String name : attributes.keySet()) {
if (!RESERVED_ATTRIBUTES.contains(name)) {
String attr = attributes.get(name).toString();
setProperty(tokenNode, session.getQName(name), vf.createValue(attr));
}
}
session.save();
return new TokenInfoImpl(tokenNode, token, user.getID());
} catch (NoSuchAlgorithmException e) {
// error while generating login token
log.error(error, e);
} catch (UnsupportedEncodingException e) {
// error while generating login token
log.error(error, e);
} catch (AccessDeniedException e) {
log.warn(error, e);
}
} else {
log.warn("Unable to get/create token store for user {}", user.getID());
}
return null;
}
use of javax.jcr.ValueFactory in project jackrabbit by apache.
the class DefaultItemResource method internalSetProperty.
/**
* Internal method that performs the setting or adding of properties
*
* @param property
* @throws DavException
* @see #setProperty(DavProperty)
* @see #alterProperties(List)
*/
private void internalSetProperty(DavProperty<?> property) throws DavException {
if (!exists()) {
throw new DavException(DavServletResponse.SC_NOT_FOUND);
}
try {
Property prop = (Property) item;
int defaultType = prop.getType();
ValueFactory vfact = getRepositorySession().getValueFactory();
ValuesProperty vp = new ValuesProperty(property, defaultType, vfact);
if (property.getName().equals(JCR_VALUE)) {
prop.setValue(vp.getJcrValue(vp.getValueType(), vfact));
} else if (property.getName().equals(JCR_VALUES)) {
prop.setValue(vp.getJcrValues());
} else {
throw new DavException(DavServletResponse.SC_CONFLICT);
}
} catch (RepositoryException e) {
throw new JcrDavException(e);
}
}
Aggregations