Search in sources :

Example 36 with CheckForNull

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

the class DocumentNodeState method getChildNodeDoc.

//------------------------------< internal >--------------------------------
@CheckForNull
private AbstractDocumentNodeState getChildNodeDoc(String childNodeName) {
    AbstractDocumentNodeState secondaryState = getSecondaryNodeState();
    if (secondaryState != null) {
        NodeState result = secondaryState.getChildNode(childNodeName);
        //else return null
        if (result.exists()) {
            return (AbstractDocumentNodeState) result;
        }
        return null;
    }
    Matcher child = bundlingContext.matcher.next(childNodeName);
    if (child.isMatch()) {
        if (bundlingContext.hasChildNode(child.getMatchedPath())) {
            return createBundledState(childNodeName, child);
        } else {
            return null;
        }
    }
    return store.getNode(concat(getPath(), childNodeName), lastRevision);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) Matcher(org.apache.jackrabbit.oak.plugins.document.bundlor.Matcher) CheckForNull(javax.annotation.CheckForNull)

Example 37 with CheckForNull

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

the class DocumentNodeStoreBranch method acquireMergeLock.

/**
     * Acquires the merge lock either exclusive or shared.
     *
     * @param exclusive whether to acquire the merge lock exclusive.
     * @return the acquired merge lock or {@code null} if the operation timed
     * out.
     * @throws CommitFailedException if the current thread is interrupted while
     *                               acquiring the lock
     */
@CheckForNull
private Lock acquireMergeLock(boolean exclusive) throws CommitFailedException {
    final long start = perfLogger.start();
    Lock lock;
    if (exclusive) {
        lock = mergeLock.writeLock();
    } else {
        lock = mergeLock.readLock();
    }
    boolean acquired;
    try {
        acquired = lock.tryLock(maxLockTryTimeMS, MILLISECONDS);
    } catch (InterruptedException e) {
        throw new CommitFailedException(OAK, 1, "Unable to acquire merge lock", e);
    }
    String mode = exclusive ? "exclusive" : "shared";
    if (acquired) {
        perfLogger.end(start, 1, "Merge - Acquired lock ({})", mode);
    } else {
        LOG.info("Time out while acquiring merge lock ({})", mode);
        lock = null;
    }
    return lock;
}
Also used : CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) CheckForNull(javax.annotation.CheckForNull)

Example 38 with CheckForNull

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

the class EffectiveType method getDefaultType.

/**
     * Finds the default node type for a child node with the given name.
     *
     * @param nameWithIndex child node name, possibly with an SNS index
     * @return default type, or {@code null} if not found
     */
@CheckForNull
String getDefaultType(@Nonnull String nameWithIndex) {
    String name = dropIndexFromName(nameWithIndex);
    boolean sns = !name.equals(nameWithIndex);
    for (NodeState type : types) {
        NodeState named = type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).getChildNode(name);
        NodeState residual = type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
        for (ChildNodeEntry entry : concat(named.getChildNodeEntries(), residual.getChildNodeEntries())) {
            NodeState definition = entry.getNodeState();
            String defaultType = definition.getName(JCR_DEFAULTPRIMARYTYPE);
            if (defaultType != null && snsMatch(sns, definition)) {
                return defaultType;
            }
        }
    }
    return null;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) CheckForNull(javax.annotation.CheckForNull)

Example 39 with CheckForNull

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

the class AbstractLoginModule method getRoot.

/**
     * Tries to obtain a {@code Root} object from the callback handler using
     * a new RepositoryCallback and keeps the value as private field.
     * If the callback handler isn't able to handle the RepositoryCallback
     * this method returns {@code null}.
     *
     * @return The {@code Root} associated with this {@code LoginModule} or
     *         {@code null}.
     */
@CheckForNull
protected Root getRoot() {
    if (root == null && callbackHandler != null) {
        try {
            final RepositoryCallback rcb = new RepositoryCallback();
            callbackHandler.handle(new Callback[] { rcb });
            final ContentRepository repository = rcb.getContentRepository();
            if (repository != null) {
                systemSession = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {

                    @Override
                    public ContentSession run() throws LoginException, NoSuchWorkspaceException {
                        return repository.login(null, rcb.getWorkspaceName());
                    }
                });
                root = systemSession.getLatestRoot();
            } else {
                log.debug("Unable to retrieve the Root via RepositoryCallback; ContentRepository not available.");
            }
        } catch (UnsupportedCallbackException | PrivilegedActionException | IOException e) {
            log.debug(e.getMessage());
        }
    }
    return root;
}
Also used : RepositoryCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.RepositoryCallback) PrivilegedActionException(java.security.PrivilegedActionException) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) CheckForNull(javax.annotation.CheckForNull)

Example 40 with CheckForNull

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

the class AbstractLoginModule method getCredentials.

/**
     * Tries to retrieve valid (supported) Credentials:
     * <ol>
     * <li>using a {@link CredentialsCallback},</li>
     * <li>looking for a {@link #SHARED_KEY_CREDENTIALS} entry in the
     * shared state (see also {@link #getSharedCredentials()} and finally by</li>
     * <li>searching for valid credentials in the subject.</li>
     * </ol>
     *
     * @return Valid (supported) credentials or {@code null}.
     */
@CheckForNull
protected Credentials getCredentials() {
    Set<Class> supported = getSupportedCredentials();
    if (callbackHandler != null) {
        log.debug("Login: retrieving Credentials using callback.");
        try {
            CredentialsCallback callback = new CredentialsCallback();
            callbackHandler.handle(new Callback[] { callback });
            Credentials creds = callback.getCredentials();
            if (creds != null && supported.contains(creds.getClass())) {
                log.debug("Login: Credentials '{}' obtained from callback", creds);
                return creds;
            } else {
                log.debug("Login: No supported credentials obtained from callback; trying shared state.");
            }
        } catch (UnsupportedCallbackException e) {
            log.warn(e.getMessage());
        } catch (IOException e) {
            log.error(e.getMessage());
        }
    }
    Credentials creds = getSharedCredentials();
    if (creds != null && supported.contains(creds.getClass())) {
        log.debug("Login: Credentials obtained from shared state.");
        return creds;
    } else {
        log.debug("Login: No supported credentials found in shared state; looking for credentials in subject.");
        for (Class clz : getSupportedCredentials()) {
            Set<Credentials> cds = subject.getPublicCredentials(clz);
            if (!cds.isEmpty()) {
                log.debug("Login: Credentials found in subject.");
                return cds.iterator().next();
            }
        }
    }
    log.debug("No credentials found.");
    return null;
}
Also used : UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException) Credentials(javax.jcr.Credentials) CredentialsCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.CredentialsCallback) 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