Search in sources :

Example 61 with CheckForNull

use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.

the class MemoryDocumentStore method internalCreateOrUpdate.

@CheckForNull
private <T extends Document> T internalCreateOrUpdate(Collection<T> collection, UpdateOp update, boolean checkConditions) {
    ConcurrentSkipListMap<String, T> map = getMap(collection);
    T oldDoc;
    Lock lock = rwLock.writeLock();
    lock.lock();
    try {
        // get the node if it's there
        oldDoc = map.get(update.getId());
        T doc = collection.newDocument(this);
        if (oldDoc == null) {
            if (!update.isNew()) {
                throw new DocumentStoreException("Document does not exist: " + update.getId());
            }
        } else {
            oldDoc.deepCopy(doc);
        }
        if (checkConditions && !checkConditions(doc, update.getConditions())) {
            return null;
        }
        // update the document
        UpdateUtils.applyChanges(doc, update);
        doc.seal();
        map.put(update.getId(), doc);
        return oldDoc;
    } finally {
        lock.unlock();
    }
}
Also used : DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) CheckForNull(javax.annotation.CheckForNull)

Example 62 with CheckForNull

use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.

the class AccessControlImporter method getACL.

@CheckForNull
private JackrabbitAccessControlList getACL(Tree tree) throws RepositoryException {
    String nodeName = tree.getName();
    JackrabbitAccessControlList acList = null;
    if (!tree.isRoot()) {
        Tree parent = tree.getParent();
        if (AccessControlConstants.REP_POLICY.equals(nodeName) && ntMgr.isNodeType(tree, AccessControlConstants.NT_REP_ACL)) {
            String path = parent.getPath();
            acList = getACL(path);
        } else if (AccessControlConstants.REP_REPO_POLICY.equals(nodeName) && ntMgr.isNodeType(tree, AccessControlConstants.NT_REP_ACL) && parent.isRoot()) {
            acList = getACL((String) null);
        }
    }
    if (acList != null) {
        // clear all existing entries
        for (AccessControlEntry ace : acList.getAccessControlEntries()) {
            acList.removeAccessControlEntry(ace);
        }
    }
    return acList;
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) CheckForNull(javax.annotation.CheckForNull)

Example 63 with CheckForNull

use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.

the class LoginModuleImpl method getUserAuthentication.

@CheckForNull
private Authentication getUserAuthentication(@Nullable String loginName) {
    SecurityProvider securityProvider = getSecurityProvider();
    Root root = getRoot();
    if (securityProvider != null && root != null) {
        UserConfiguration uc = securityProvider.getConfiguration(UserConfiguration.class);
        UserAuthenticationFactory factory = uc.getParameters().getConfigValue(UserConstants.PARAM_USER_AUTHENTICATION_FACTORY, null, UserAuthenticationFactory.class);
        if (factory != null) {
            return factory.getAuthentication(uc, root, loginName);
        } else {
            log.error("No user authentication factory configured in user configuration.");
        }
    }
    return null;
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) UserAuthenticationFactory(org.apache.jackrabbit.oak.spi.security.user.UserAuthenticationFactory) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) CheckForNull(javax.annotation.CheckForNull)

Example 64 with CheckForNull

use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.

the class AccessControlManagerImpl method createACL.

@CheckForNull
private JackrabbitAccessControlList createACL(@Nullable String oakPath, @Nonnull Tree accessControlledTree, boolean isEffectivePolicy, @CheckForNull Predicate<ACE> predicate) throws RepositoryException {
    JackrabbitAccessControlList acl = null;
    String aclName = Util.getAclName(oakPath);
    if (accessControlledTree.exists() && Util.isAccessControlled(oakPath, accessControlledTree, ntMgr)) {
        Tree aclTree = accessControlledTree.getChild(aclName);
        if (aclTree.exists()) {
            List<ACE> entries = new ArrayList<ACE>();
            for (Tree child : aclTree.getChildren()) {
                if (Util.isACE(child, ntMgr)) {
                    ACE ace = createACE(oakPath, child, restrictionProvider);
                    if (predicate == null || predicate.apply(ace)) {
                        entries.add(ace);
                    }
                }
            }
            if (isEffectivePolicy) {
                acl = new ImmutableACL(oakPath, entries, restrictionProvider, getNamePathMapper());
            } else {
                acl = new NodeACL(oakPath, entries);
            }
        }
    }
    return acl;
}
Also used : ACE(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE) ArrayList(java.util.ArrayList) Tree(org.apache.jackrabbit.oak.api.Tree) ImmutableACL(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ImmutableACL) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) CheckForNull(javax.annotation.CheckForNull)

Example 65 with CheckForNull

use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.

the class TokenProviderImpl method getTokenParent.

@CheckForNull
private Tree getTokenParent(@Nonnull User user) {
    Tree tokenParent = null;
    String parentPath = null;
    try {
        String userPath = user.getPath();
        parentPath = userPath + '/' + TOKENS_NODE_NAME;
        Tree userNode = root.getTree(userPath);
        tokenParent = TreeUtil.getOrAddChild(userNode, TOKENS_NODE_NAME, TOKENS_NT_NAME);
        root.commit();
    } catch (RepositoryException e) {
        // error while creating token node.
        log.debug("Error while creating token node {}", e.getMessage());
    } catch (CommitFailedException e) {
        // conflict while creating token store for this user -> refresh and
        // try to get the tree from the updated root.
        log.debug("Conflict while creating token store -> retrying {}", e.getMessage());
        root.refresh();
        Tree parentTree = root.getTree(parentPath);
        if (parentTree.exists()) {
            tokenParent = parentTree;
        } else {
            tokenParent = null;
        }
    }
    return tokenParent;
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) RepositoryException(javax.jcr.RepositoryException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) CheckForNull(javax.annotation.CheckForNull)

Aggregations

CheckForNull (javax.annotation.CheckForNull)158 IOException (java.io.IOException)21 Tree (org.apache.jackrabbit.oak.api.Tree)16 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)12 ArrayList (java.util.ArrayList)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 Stopwatch (com.google.common.base.Stopwatch)8 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)8 Date (java.util.Date)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 Period (org.sonar.server.computation.task.projectanalysis.period.Period)7 File (java.io.File)6 SQLException (java.sql.SQLException)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 ExecutionException (java.util.concurrent.ExecutionException)5 ValidationModel (org.apache.sling.validation.model.ValidationModel)5 InputStream (java.io.InputStream)4 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Root (org.apache.jackrabbit.oak.api.Root)4 Utils.resolveCommitRevision (org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision)4