use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class ExternalGroupPrincipalProvider method getGroupPrincipals.
private Set<Group> getGroupPrincipals(@Nonnull Tree userTree) {
if (userTree.exists() && UserUtil.isType(userTree, AuthorizableType.USER) && userTree.hasProperty(REP_EXTERNAL_PRINCIPAL_NAMES)) {
PropertyState ps = userTree.getProperty(REP_EXTERNAL_PRINCIPAL_NAMES);
if (ps != null) {
// we have an 'external' user that has been synchronized with the dynamic-membership option
Set<Group> groupPrincipals = Sets.newHashSet();
for (String principalName : ps.getValue(Type.STRINGS)) {
groupPrincipals.add(new ExternalGroupPrincipal(principalName));
}
// add existing group principals as defined with the _autoMembership_ option.
groupPrincipals.addAll(autoMembershipPrincipals.get(getIdpName(userTree)));
return groupPrincipals;
}
}
// group principals cannot be retrieved
return ImmutableSet.of();
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class AbstractExternalAuthTest method waitUntilExpired.
protected static void waitUntilExpired(@Nonnull User user, @Nonnull Root root, long expTime) throws RepositoryException {
Tree t = root.getTree(user.getPath());
PropertyState ps = t.getProperty(ExternalIdentityConstants.REP_LAST_SYNCED);
if (ps == null || ps.count() == 0) {
return;
}
long lastSynced = ps.getValue(Type.LONG);
long now = Calendar.getInstance().getTimeInMillis();
while (now - lastSynced <= expTime) {
now = Calendar.getInstance().getTimeInMillis();
}
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class RepExternalIdTest method assertRepExternalId.
private void assertRepExternalId(@Nonnull SyncResult result) throws Exception {
assertSame(SyncResult.Status.ADD, result.getStatus());
SyncedIdentity si = result.getIdentity();
assertNotNull(si);
Authorizable authorizable = userManager.getAuthorizable(si.getId());
assertNotNull(authorizable);
Tree userTree = r.getTree(authorizable.getPath());
assertTrue(userTree.hasProperty(DefaultSyncContext.REP_EXTERNAL_ID));
PropertyState ps = userTree.getProperty(DefaultSyncContext.REP_EXTERNAL_ID);
assertNotNull(ps);
assertFalse(ps.isArray());
assertSame(Type.STRING, ps.getType());
assertEquals(si.getExternalIdRef(), ExternalIdentityRef.fromString(ps.getValue(Type.STRING)));
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class TypeRegistration method validateAndCompileType.
/**
* Validates and pre-compiles the named node type.
*
* @param types builder for the /jcr:system/jcr:nodeTypes node
* @param name name of the node type to validate and compile
* @throws CommitFailedException if type validation fails
*/
private void validateAndCompileType(NodeBuilder types, String name) throws CommitFailedException {
NodeBuilder type = types.child(name);
// - jcr:nodeTypeName (NAME) protected mandatory
PropertyState nodeTypeName = type.getProperty(JCR_NODETYPENAME);
if (nodeTypeName == null || !name.equals(nodeTypeName.getValue(NAME))) {
throw new CommitFailedException(CONSTRAINT, 34, "Unexpected " + JCR_NODETYPENAME + " in type " + name);
}
// Prepare the type node pre-compilation of the rep:NodeType info
Iterable<String> empty = emptyList();
type.setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_NODE_TYPE, NAME);
type.removeProperty(REP_SUPERTYPES);
type.setProperty(REP_PRIMARY_SUBTYPES, empty, NAMES);
type.setProperty(REP_MANDATORY_PROPERTIES, empty, NAMES);
type.setProperty(REP_MANDATORY_CHILD_NODES, empty, NAMES);
type.setProperty(REP_PROTECTED_PROPERTIES, empty, NAMES);
type.setProperty(REP_PROTECTED_CHILD_NODES, empty, NAMES);
type.setProperty(REP_HAS_PROTECTED_RESIDUAL_PROPERTIES, false, BOOLEAN);
type.setProperty(REP_HAS_PROTECTED_RESIDUAL_CHILD_NODES, false, BOOLEAN);
type.setProperty(REP_NAMED_SINGLE_VALUED_PROPERTIES, empty, NAMES);
type.getChildNode(REP_NAMED_PROPERTY_DEFINITIONS).remove();
type.getChildNode(REP_RESIDUAL_PROPERTY_DEFINITIONS).remove();
type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).remove();
type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS).remove();
// = nt:childNodeDefinition protected sns
for (String childNodeName : type.getChildNodeNames()) {
NodeState definition = type.child(childNodeName).getNodeState();
if (childNodeName.startsWith(JCR_PROPERTYDEFINITION)) {
validateAndCompilePropertyDefinition(type, name, definition);
} else if (childNodeName.startsWith(JCR_CHILDNODEDEFINITION)) {
validateAndCompileChildNodeDefinition(types, type, name, definition);
}
}
}
use of org.apache.jackrabbit.oak.api.PropertyState in project jackrabbit-oak by apache.
the class TypeRegistration method validateAndCompileChildNodeDefinition.
private void validateAndCompileChildNodeDefinition(NodeBuilder types, NodeBuilder type, String typeName, NodeState definition) throws CommitFailedException {
// - jcr:name (NAME) protected
PropertyState name = definition.getProperty(JCR_NAME);
NodeBuilder definitions;
if (name != null) {
String childNodeName = name.getValue(NAME);
definitions = type.child(REP_NAMED_CHILD_NODE_DEFINITIONS);
definitions.setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_NAMED_CHILD_NODE_DEFINITIONS, NAME);
definitions = definitions.child(childNodeName);
// - jcr:mandatory (BOOLEAN) protected mandatory
if (definition.getBoolean(JCR_MANDATORY)) {
addNameToList(type, REP_MANDATORY_CHILD_NODES, childNodeName);
}
// - jcr:protected (BOOLEAN) protected mandatory
if (definition.getBoolean(JCR_PROTECTED)) {
addNameToList(type, REP_PROTECTED_CHILD_NODES, childNodeName);
}
} else {
definitions = type.child(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
// - jcr:protected (BOOLEAN) protected mandatory
if (definition.getBoolean(JCR_PROTECTED)) {
type.setProperty(REP_HAS_PROTECTED_RESIDUAL_CHILD_NODES, true);
}
}
definitions.setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_CHILD_NODE_DEFINITIONS, NAME);
// - jcr:requiredPrimaryTypes (NAME)
// = 'nt:base' protected mandatory multiple
PropertyState requiredTypes = definition.getProperty(JCR_REQUIREDPRIMARYTYPES);
if (requiredTypes != null) {
for (String key : requiredTypes.getValue(NAMES)) {
if (!types.hasChildNode(key)) {
throw new CommitFailedException("Constraint", 33, "Unknown required primary type " + key);
} else if (!definitions.hasChildNode(key)) {
definitions.setChildNode(key, definition).setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_CHILD_NODE_DEFINITION, NAME).setProperty(REP_DECLARING_NODE_TYPE, typeName, NAME);
}
}
}
}
Aggregations