use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class LockManagerImpl method getLocks.
/**
* {@inheritDoc}
*/
public Lock[] getLocks(SessionImpl session) throws RepositoryException {
acquire();
LockInfo[] infos = getLockInfos(session);
try {
Lock[] locks = new Lock[infos.length];
for (int i = 0; i < infos.length; i++) {
NodeImpl holder = (NodeImpl) session.getItemManager().getItem(infos[i].getId());
locks[i] = new LockImpl(infos[i], holder);
}
return locks;
} finally {
release();
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class LockManagerImpl method addLockToken.
/**
* {@inheritDoc}
*/
public void addLockToken(SessionImpl session, String lt) throws LockException, RepositoryException {
try {
acquire();
NodeId id = LockInfo.parseLockToken(lt);
NodeImpl node = (NodeImpl) sysSession.getItemManager().getItem(id);
Path path = node.getPrimaryPath();
PathMap.Element<LockInfo> element = lockMap.map(path, true);
if (element != null) {
LockInfo info = element.get();
if (info != null && !info.isLockHolder(session)) {
if (info.getLockHolder() == null) {
info.setLockHolder(session);
if (info instanceof InternalLockInfo) {
session.addListener((InternalLockInfo) info);
}
} else {
String msg = "Cannot add lock token: lock already held by other session.";
log.warn(msg);
info.throwLockException(msg, session);
}
}
}
// inform SessionLockManager
getSessionLockManager(session).lockTokenAdded(lt);
} catch (IllegalArgumentException e) {
String msg = "Bad lock token: " + e.getMessage();
log.warn(msg);
throw new LockException(msg);
} finally {
release();
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserImporter method start.
// ---------------------------------------------< ProtectedNodeImporter >---
/**
* @see ProtectedNodeImporter#start(org.apache.jackrabbit.core.NodeImpl)
*/
public boolean start(NodeImpl protectedParent) throws RepositoryException {
String repMembers = resolver.getJCRName(UserConstants.NT_REP_MEMBERS);
if (repMembers.equals(protectedParent.getPrimaryNodeType().getName())) {
NodeImpl groupNode = protectedParent;
while (groupNode.getDepth() != 0 && repMembers.equals(groupNode.getPrimaryNodeType().getName())) {
groupNode = (NodeImpl) groupNode.getParent();
}
Authorizable auth = userManager.getAuthorizable(groupNode);
if (auth == null) {
log.debug("Cannot handle protected node " + protectedParent + ". It nor one of its parents represent a valid Authorizable.");
return false;
} else {
currentMembership = new Membership(auth.getID());
return true;
}
} else {
return false;
}
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserManagerImpl method createAdmin.
/**
* Create the administrator user. If the node to be created collides
* with an existing node (ItemExistsException) the existing node gets removed
* and the admin user node is (re)created.
* <p>
* Collision with an existing node may occur under the following circumstances:
*
* <ul>
* <li>The <code>usersPath</code> has been modified in the user manager
* configuration after a successful repository start that already created
* the administrator user.</li>
* <li>The NodeId created by {@link #buildNodeId(String)} by coincidence
* collides with another NodeId created during the regular node creation
* process.</li>
* </ul>
*
* @return The admin user.
* @throws RepositoryException If an error occurs.
*/
private User createAdmin() throws RepositoryException {
User admin;
try {
admin = createUser(adminId, adminId);
if (!isAutoSave()) {
session.save();
}
log.info("... created admin user with id \'" + adminId + "\' and default pw.");
} catch (ItemExistsException e) {
NodeImpl conflictingNode = session.getNodeById(buildNodeId(adminId));
String conflictPath = conflictingNode.getPath();
log.error("Detected conflicting node " + conflictPath + " of node type " + conflictingNode.getPrimaryNodeType().getName() + ".");
// TODO move conflicting node of type rep:User instead of removing and recreating.
conflictingNode.remove();
log.info("Removed conflicting node at " + conflictPath);
admin = createUser(adminId, adminId);
if (!isAutoSave()) {
session.save();
}
log.info("Resolved conflict and (re)created admin user with id \'" + adminId + "\' and default pw.");
}
return admin;
}
use of org.apache.jackrabbit.core.NodeImpl in project jackrabbit by apache.
the class UserManagerImpl method internalGetAuthorizable.
/**
* @param id The user or group ID.
* @return The authorizable with the given <code>id</code> or <code>null</code>.
* @throws RepositoryException If an error occurs.
*/
private Authorizable internalGetAuthorizable(String id) throws RepositoryException {
NodeId nodeId = buildNodeId(id);
NodeImpl n = null;
try {
n = session.getNodeById(nodeId);
} catch (ItemNotFoundException e) {
boolean compatibleJR16 = config.getConfigValue(PARAM_COMPATIBLE_JR16, false);
if (compatibleJR16) {
// backwards-compatibility with JR < 2.0 user/group structure that doesn't
// allow to determine existence of an authorizable from the id directly.
// search for it the node belonging to that id
n = (NodeImpl) authResolver.findNode(P_USERID, id, NT_REP_USER);
if (n == null) {
// no user -> look for group.
// NOTE: JR < 2.0 always returned groupIDs that didn't contain any
// illegal JCR chars. Since Group.getID() 'unescapes' the node
// name additional escaping is required.
Name nodeName = session.getQName(Text.escapeIllegalJcrChars(id));
n = (NodeImpl) authResolver.findNode(nodeName, NT_REP_GROUP);
}
}
// else: no matching node found -> ignore exception.
}
return getAuthorizable(n);
}
Aggregations