public class DefaultLockHelper extends Object implements ILockHelper
ILockHelper
. If user suzy
in tenant acme
locks a file with
UUID abc
then this implementation will store the lock token xyz
as
/pentaho/acme/home/suzy/.lockTokens/abc/xyz
. It is assumed that /pentaho/acme/home/suzy
is never
versioned! Putting lock token storage beneath the user's home folder provides access control.
This implementation stores a lock owner, lock date, and lock message in the ownerInfo payload. See JCR 2.0 section 17.3. If implemented as custom properties, then a versioned node would require a checkout and checkin to lock a file. There is one caveat: implementations of JCR are free to ignore the ownerInfo payload. In that case, the implementation sets the value. If that happens, we simply return that value as the lock owner and date and message are null.
Constructor and Description |
---|
DefaultLockHelper(ITenantedPrincipleNameResolver userNameUtils) |
Modifier and Type | Method and Description |
---|---|
protected void |
addLockToken(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock)
Stores a lock token associated with the session's user.
|
void |
addLockTokenToSessionIfNecessary(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
Serializable fileId)
Adds the lock token associated with the file with the given file id if the file is locked.
|
boolean |
canUnlock(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock)
Returns
true if user represented by session can potentially unlock the given lock. |
Date |
getLockDate(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock) |
String |
getLockMessage(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock) |
String |
getLockOwner(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock) |
protected String |
getLockToken(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock)
Returns all lock tokens belonging to the session's user.
|
protected javax.jcr.Node |
getOrCreateLockTokensNode(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock) |
void |
lockFile(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
Serializable fileId,
String message)
Locks a file.
|
void |
removeLockToken(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
javax.jcr.lock.Lock lock)
Removes a lock token so that it can never be associated with anyone's session again.
|
void |
removeLockTokenFromSessionIfNecessary(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
Serializable fileId)
Removes the lock token associated with the file with the given file id
|
void |
unlockFile(javax.jcr.Session session,
PentahoJcrConstants pentahoJcrConstants,
Serializable fileId)
Unlocks a file.
|
public DefaultLockHelper(ITenantedPrincipleNameResolver userNameUtils)
protected void addLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
protected String getLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
Session.addLockToken(token)
.
Callers should call {#link canUnlock(Session, PentahoJcrConstants, Lock)
if the token is being
retrieved for the purpose of an unlock.
javax.jcr.RepositoryException
public void removeLockToken(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
removeLockToken
in interface ILockHelper
session
- sessionpentahoJcrConstants
- constantslock
- lockjavax.jcr.RepositoryException
- if anything goes wrongprotected javax.jcr.Node getOrCreateLockTokensNode(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
javax.jcr.RepositoryException
public boolean canUnlock(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
true
if user represented by session can potentially unlock the given lock. This can be a
function of access control or some other mechanism.canUnlock
in interface ILockHelper
session
- sessionpentahoJcrConstants
- constantslock
- lockjavax.jcr.RepositoryException
- if anything goes wrongpublic void addLockTokenToSessionIfNecessary(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId) throws javax.jcr.RepositoryException
addLockTokenToSessionIfNecessary
in interface ILockHelper
session
- sessionpentahoJcrConstants
- constantsfileId
- file idjavax.jcr.RepositoryException
- if anything goes wrongpublic void removeLockTokenFromSessionIfNecessary(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId) throws javax.jcr.RepositoryException
removeLockTokenFromSessionIfNecessary
in interface ILockHelper
session
- sessionpentahoJcrConstants
- constantsfileId
- file idjavax.jcr.RepositoryException
- if anything goes wrongpublic void unlockFile(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId) throws javax.jcr.RepositoryException
unlockFile
in interface ILockHelper
session
- sessionpentahoJcrConstants
- constantsfileId
- file idjavax.jcr.RepositoryException
- if anything goes wrongpublic void lockFile(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, Serializable fileId, String message) throws javax.jcr.RepositoryException
lockFile
in interface ILockHelper
session
- sessionpentahoJcrConstants
- constantsfileId
- file idmessage
- lock messagejavax.jcr.RepositoryException
- if anything goes wrongpublic Date getLockDate(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
getLockDate
in interface ILockHelper
javax.jcr.RepositoryException
public String getLockMessage(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
getLockMessage
in interface ILockHelper
javax.jcr.RepositoryException
public String getLockOwner(javax.jcr.Session session, PentahoJcrConstants pentahoJcrConstants, javax.jcr.lock.Lock lock) throws javax.jcr.RepositoryException
getLockOwner
in interface ILockHelper
javax.jcr.RepositoryException
Copyright © 2017 Hitachi Vantara. All rights reserved.