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