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;
}
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;
}
}
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());
}
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;
}
}
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());
}
Aggregations