Search in sources :

Example 51 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 52 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)

Example 53 with CheckForNull

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

the class TokenProviderImpl 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 credentials The current credentials.
     * @return A new {@code TokenInfo} or {@code null} if the token could not
     *         be created.
     */
@CheckForNull
@Override
public TokenInfo createToken(@Nonnull Credentials credentials) {
    Credentials creds = extractCredentials(credentials);
    String uid = (creds != null) ? credentialsSupport.getUserId(creds) : null;
    TokenInfo tokenInfo = null;
    if (uid != null) {
        Map<String, ?> attributes = credentialsSupport.getAttributes(creds);
        tokenInfo = createToken(uid, attributes);
        if (tokenInfo != null) {
            // also set the new token to the credentials.
            if (!credentialsSupport.setAttributes(creds, ImmutableMap.of(TOKEN_ATTRIBUTE, tokenInfo.getToken()))) {
                log.debug("Cannot set token attribute to " + creds);
            }
        }
    }
    return tokenInfo;
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) Credentials(javax.jcr.Credentials) CheckForNull(javax.annotation.CheckForNull)

Example 54 with CheckForNull

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

the class TokenProviderImpl method getUser.

@CheckForNull
private User getUser(@Nonnull Tree tokenTree) throws RepositoryException {
    String userPath = Text.getRelativeParent(tokenTree.getPath(), 2);
    Authorizable authorizable = userManager.getAuthorizableByPath(userPath);
    if (authorizable != null && !authorizable.isGroup() && !((User) authorizable).isDisabled()) {
        return (User) authorizable;
    } else {
        return null;
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CheckForNull(javax.annotation.CheckForNull)

Example 55 with CheckForNull

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

the class DefaultSyncContext method createSyncedIdentity.

/**
     * Creates a synced identity from the given authorizable.
     * @param auth the authorizable
     * @return the id
     * @throws RepositoryException if an error occurs
     */
@CheckForNull
public static DefaultSyncedIdentity createSyncedIdentity(@Nullable Authorizable auth) throws RepositoryException {
    if (auth == null) {
        return null;
    }
    ExternalIdentityRef ref = getIdentityRef(auth);
    Value[] lmValues = auth.getProperty(REP_LAST_SYNCED);
    long lastModified = -1;
    if (lmValues != null && lmValues.length > 0) {
        lastModified = lmValues[0].getLong();
    }
    return new DefaultSyncedIdentity(auth.getID(), ref, auth.isGroup(), lastModified);
}
Also used : ExternalIdentityRef(org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalIdentityRef) Value(javax.jcr.Value) CheckForNull(javax.annotation.CheckForNull)

Aggregations

CheckForNull (javax.annotation.CheckForNull)149 IOException (java.io.IOException)18 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 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 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4