Search in sources :

Example 71 with PropertyState

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();
}
Also used : Group(java.security.acl.Group) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 72 with PropertyState

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();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 73 with PropertyState

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)));
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) SyncedIdentity(org.apache.jackrabbit.oak.spi.security.authentication.external.SyncedIdentity) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 74 with PropertyState

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);
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 75 with PropertyState

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);
            }
        }
    }
}
Also used : NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

PropertyState (org.apache.jackrabbit.oak.api.PropertyState)404 Test (org.junit.Test)189 Tree (org.apache.jackrabbit.oak.api.Tree)138 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)49 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)45 Nonnull (javax.annotation.Nonnull)31 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)29 RemoteTree (org.apache.jackrabbit.oak.remote.RemoteTree)28 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)28 Blob (org.apache.jackrabbit.oak.api.Blob)21 ArrayList (java.util.ArrayList)20 LongPropertyState (org.apache.jackrabbit.oak.plugins.memory.LongPropertyState)17 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)16 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)13 CheckForNull (javax.annotation.CheckForNull)12 RepositoryException (javax.jcr.RepositoryException)10 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)10 Map (java.util.Map)9 Value (javax.jcr.Value)9