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