Search in sources :

Example 66 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 67 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 68 with CheckForNull

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

the class SegmentBufferWriterPoolTest method testFlushBlocks.

@Test
public void testFlushBlocks() throws ExecutionException, InterruptedException {
    Future<RecordId> res = execute(new WriteOperation() {

        @Nonnull
        @CheckForNull
        @Override
        public RecordId execute(@Nonnull SegmentBufferWriter writer) {
            try {
                // This should deadlock as flush waits for this write
                // operation to finish, which in this case contains the
                // call to flush itself.
                executors[1].submit(new Callable<Void>() {

                    @Override
                    public Void call() throws Exception {
                        pool.flush(store);
                        return null;
                    }
                }).get(100, MILLISECONDS);
                // No deadlock -> null indicates test failure
                return null;
            } catch (InterruptedException | ExecutionException ignore) {
                // No deadlock -> null indicates test failure
                return null;
            } catch (TimeoutException ignore) {
                // Deadlock -> rootId indicates test pass
                return rootId;
            }
        }
    }, 0);
    assertEquals(rootId, res.get());
}
Also used : WriteOperation(org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation) Nonnull(javax.annotation.Nonnull) CheckForNull(javax.annotation.CheckForNull) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 69 with CheckForNull

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

the class SessionImpl method getItemInternal.

@CheckForNull
private ItemImpl<?> getItemInternal(@Nonnull String oakPath) throws RepositoryException {
    checkAlive();
    ItemDelegate item = sd.getItem(oakPath);
    if (item instanceof NodeDelegate) {
        return NodeImpl.createNode((NodeDelegate) item, sessionContext);
    } else if (item instanceof PropertyDelegate) {
        return new PropertyImpl((PropertyDelegate) item, sessionContext);
    } else {
        return null;
    }
}
Also used : NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) ItemDelegate(org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate) CheckForNull(javax.annotation.CheckForNull)

Example 70 with CheckForNull

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

the class BlobStoreFixtureProvider method create.

@CheckForNull
public static BlobStoreFixture create(Options options) throws Exception {
    BlobStoreOptions bsopts = options.getOptionBean(BlobStoreOptions.class);
    if (bsopts == null) {
        return null;
    }
    Type bsType = bsopts.getBlobStoreType();
    if (bsType == Type.NONE) {
        return null;
    }
    Closer closer = Closer.create();
    DataStore delegate;
    if (bsType == Type.S3) {
        SharedS3DataStore s3ds = new SharedS3DataStore();
        Properties props = loadAndTransformProps(bsopts.getS3ConfigPath());
        s3ds.setProperties(props);
        File homeDir = Files.createTempDir();
        closer.register(asCloseable(homeDir));
        s3ds.init(homeDir.getAbsolutePath());
        delegate = s3ds;
    } else if (bsType == Type.AZURE) {
        AzureDataStore azureds = new AzureDataStore();
        String cfgPath = bsopts.getAzureConfigPath();
        Properties props = loadAndTransformProps(cfgPath);
        azureds.setProperties(props);
        File homeDir = Files.createTempDir();
        azureds.init(homeDir.getAbsolutePath());
        closer.register(asCloseable(homeDir));
        delegate = azureds;
    } else if (bsType == Type.FAKE) {
        FileDataStore fakeDs = new DummyDataStore();
        fakeDs.setPath(bsopts.getFakeDataStorePath());
        fakeDs.init(null);
        delegate = fakeDs;
    } else {
        FileDataStore fds = new OakFileDataStore();
        delegate = fds;
        if (bsopts.getFDSPath() != null) {
            fds.setPath(bsopts.getFDSPath());
        } else {
            String cfgPath = bsopts.getFDSConfigPath();
            Properties props = loadAndTransformProps(cfgPath);
            populate(delegate, asMap(props), true);
        }
        delegate.init(null);
    }
    DataStoreBlobStore blobStore = new DataStoreBlobStore(delegate);
    return new DataStoreFixture(blobStore, closer, !options.getCommonOpts().isReadWrite());
}
Also used : Closer(com.google.common.io.Closer) OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) SharedS3DataStore(org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore) AzureDataStore(org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureDataStore) Properties(java.util.Properties) Type(org.apache.jackrabbit.oak.run.cli.BlobStoreOptions.Type) AzureDataStore(org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureDataStore) DataStore(org.apache.jackrabbit.core.data.DataStore) SharedS3DataStore(org.apache.jackrabbit.oak.blob.cloud.aws.s3.SharedS3DataStore) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) File(java.io.File) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) OakFileDataStore(org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) 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