mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
AVMLockingException now has I18N message for locked item error.
Added new variant of hasAccess() method to AVMLockingService to support the case where you already have the NodeRef of the webproject available (improves performance by removing the need to perform a lucene search to locate the webproject node). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6017 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -339,9 +339,9 @@
|
|||||||
<property name="searchService">
|
<property name="searchService">
|
||||||
<ref bean="searchService"/>
|
<ref bean="searchService"/>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="webProjectStore">
|
||||||
|
<value>workspace://SpacesStore</value>
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
# AVM related messages
|
# AVM related messages
|
||||||
|
|
||||||
expiredcontent.workflow.title=Expired Content In ''{0}''
|
expiredcontent.workflow.title=Expired Content In ''{0}''
|
||||||
|
avmlockservice.locked=You do not have access to the item at path {0} it is currently locked by another user.
|
@@ -823,12 +823,12 @@ public class AVMLockingAwareService implements AVMService
|
|||||||
String userName = fAuthenticationService.getCurrentUserName();
|
String userName = fAuthenticationService.getCurrentUserName();
|
||||||
if (!fLockingService.hasAccess(webProject, path, userName))
|
if (!fLockingService.hasAccess(webProject, path, userName))
|
||||||
{
|
{
|
||||||
throw new AVMLockingException(userName + " does not have access to " + path);
|
throw new AVMLockingException("avmlockservice.locked", new Object[]{path});
|
||||||
}
|
}
|
||||||
fLockingService.addWebProject(webProject);
|
fLockingService.addWebProject(webProject);
|
||||||
if (fLockingService.getLock(webProject, storePath[1]) == null)
|
if (fLockingService.getLock(webProject, storePath[1]) == null)
|
||||||
{
|
{
|
||||||
List<String> owners = new ArrayList<String>();
|
List<String> owners = new ArrayList<String>(1);
|
||||||
owners.add(userName);
|
owners.add(userName);
|
||||||
AVMLock lock = new AVMLock(webProject, storePath[0], storePath[1], AVMLockingService.Type.DISCRETIONARY, owners);
|
AVMLock lock = new AVMLock(webProject, storePath[0], storePath[1], AVMLockingService.Type.DISCRETIONARY, owners);
|
||||||
fLockingService.lockPath(lock);
|
fLockingService.lockPath(lock);
|
||||||
|
@@ -35,7 +35,6 @@ import org.alfresco.repo.attributes.Attribute;
|
|||||||
import org.alfresco.repo.attributes.ListAttributeValue;
|
import org.alfresco.repo.attributes.ListAttributeValue;
|
||||||
import org.alfresco.repo.attributes.MapAttributeValue;
|
import org.alfresco.repo.attributes.MapAttributeValue;
|
||||||
import org.alfresco.repo.attributes.StringAttributeValue;
|
import org.alfresco.repo.attributes.StringAttributeValue;
|
||||||
import org.alfresco.repo.node.db.DbNodeServiceImpl;
|
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
import org.alfresco.service.cmr.attributes.AttrQueryEquals;
|
import org.alfresco.service.cmr.attributes.AttrQueryEquals;
|
||||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||||
@@ -53,6 +52,7 @@ import org.alfresco.service.cmr.search.SearchService;
|
|||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityType;
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
import org.alfresco.util.MD5;
|
import org.alfresco.util.MD5;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
|
|
||||||
@@ -67,6 +67,13 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
public static final String USERS = "users";
|
public static final String USERS = "users";
|
||||||
public static final String STORES = "stores";
|
public static final String STORES = "stores";
|
||||||
|
|
||||||
|
private static final String ROLE_CONTENT_MANAGER = "ContentManager";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store name containing the web project nodes.
|
||||||
|
*/
|
||||||
|
private String webProjectStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SearchService for access to web project properties.
|
* SearchService for access to web project properties.
|
||||||
*/
|
*/
|
||||||
@@ -97,8 +104,13 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
private RetryingTransactionHelper fRetryingTransactionHelper;
|
private RetryingTransactionHelper fRetryingTransactionHelper;
|
||||||
|
|
||||||
public AVMLockingServiceImpl()
|
|
||||||
|
/**
|
||||||
|
* @param webProjectStore The webProjectStore to set
|
||||||
|
*/
|
||||||
|
public void setWebProjectStore(String webProjectStore)
|
||||||
{
|
{
|
||||||
|
this.webProjectStore = webProjectStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,7 +187,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
public AVMLock getLock(String webProject, String path)
|
public AVMLock getLock(String webProject, String path)
|
||||||
{
|
{
|
||||||
path = normalizePath(path);
|
path = normalizePath(path);
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>(3);
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(WEB_PROJECTS);
|
keys.add(WEB_PROJECTS);
|
||||||
keys.add(webProject);
|
keys.add(webProject);
|
||||||
@@ -211,7 +223,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public List<AVMLock> getUsersLocks(String user)
|
public List<AVMLock> getUsersLocks(String user)
|
||||||
{
|
{
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>(3);
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(USERS);
|
keys.add(USERS);
|
||||||
keys.add(user);
|
keys.add(user);
|
||||||
@@ -294,7 +306,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
{
|
{
|
||||||
path = normalizePath(path);
|
path = normalizePath(path);
|
||||||
String pathKey = MD5.Digest(path.getBytes());
|
String pathKey = MD5.Digest(path.getBytes());
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>(4);
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(WEB_PROJECTS);
|
keys.add(WEB_PROJECTS);
|
||||||
keys.add(webProject);
|
keys.add(webProject);
|
||||||
@@ -326,7 +338,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
}
|
}
|
||||||
userKeys.remove(2);
|
userKeys.remove(2);
|
||||||
}
|
}
|
||||||
List<String> storeKeys = new ArrayList<String>();
|
List<String> storeKeys = new ArrayList<String>(3);
|
||||||
storeKeys.add(LOCK_TABLE);
|
storeKeys.add(LOCK_TABLE);
|
||||||
storeKeys.add(STORES);
|
storeKeys.add(STORES);
|
||||||
String store = lock.getStore();
|
String store = lock.getStore();
|
||||||
@@ -349,7 +361,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public void addWebProject(String webProject)
|
public void addWebProject(String webProject)
|
||||||
{
|
{
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>(3);
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(WEB_PROJECTS);
|
keys.add(WEB_PROJECTS);
|
||||||
keys.add(webProject);
|
keys.add(webProject);
|
||||||
@@ -366,7 +378,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public List<AVMLock> getWebProjectLocks(String webProject)
|
public List<AVMLock> getWebProjectLocks(String webProject)
|
||||||
{
|
{
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>(3);
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(WEB_PROJECTS);
|
keys.add(WEB_PROJECTS);
|
||||||
keys.add(webProject);
|
keys.add(webProject);
|
||||||
@@ -387,7 +399,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public void removeWebProject(String webProject)
|
public void removeWebProject(String webProject)
|
||||||
{
|
{
|
||||||
List<String> userKeys = new ArrayList<String>();
|
List<String> userKeys = new ArrayList<String>(2);
|
||||||
userKeys.add(LOCK_TABLE);
|
userKeys.add(LOCK_TABLE);
|
||||||
userKeys.add(USERS);
|
userKeys.add(USERS);
|
||||||
List<String> users = fAttributeService.getKeys(userKeys);
|
List<String> users = fAttributeService.getKeys(userKeys);
|
||||||
@@ -430,7 +442,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
storeKeys.remove(2);
|
storeKeys.remove(2);
|
||||||
fAttributeService.setAttribute(storeKeys, store, storeLocks);
|
fAttributeService.setAttribute(storeKeys, store, storeLocks);
|
||||||
}
|
}
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>(2);
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(WEB_PROJECTS);
|
keys.add(WEB_PROJECTS);
|
||||||
fAttributeService.removeAttribute(keys, webProject);
|
fAttributeService.removeAttribute(keys, webProject);
|
||||||
@@ -441,7 +453,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public List<AVMLock> getStoreLocks(String store)
|
public List<AVMLock> getStoreLocks(String store)
|
||||||
{
|
{
|
||||||
List<AVMLock> locks = new ArrayList<AVMLock>();
|
List<AVMLock> locks = new ArrayList<AVMLock>(3);
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>();
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(STORES);
|
keys.add(STORES);
|
||||||
@@ -514,7 +526,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public void removeStoreLocks(String store)
|
public void removeStoreLocks(String store)
|
||||||
{
|
{
|
||||||
List<String> storeKeys = new ArrayList<String>();
|
List<String> storeKeys = new ArrayList<String>(3);
|
||||||
storeKeys.add(LOCK_TABLE);
|
storeKeys.add(LOCK_TABLE);
|
||||||
storeKeys.add(STORES);
|
storeKeys.add(STORES);
|
||||||
storeKeys.add(store);
|
storeKeys.add(store);
|
||||||
@@ -544,21 +556,47 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
StoreRef storeRef = new StoreRef(this.webProjectStore);
|
||||||
ResultSet results = fSearchService.query(storeRef, "lucene", "@wca\\:avmstore:\"" + webProject + "\" +TYPE:\"wca:webfolder\"");
|
ResultSet results = fSearchService.query(
|
||||||
System.out.println(results.getNodeRefs());
|
storeRef,
|
||||||
|
SearchService.LANGUAGE_LUCENE,
|
||||||
|
"@wca\\:avmstore:\"" + webProject + "\" +TYPE:\"wca:webfolder\"");
|
||||||
if (results.getNodeRefs().size() == 1)
|
if (results.getNodeRefs().size() == 1)
|
||||||
{
|
{
|
||||||
List<ChildAssociationRef> children = fNodeService.getChildAssocs(results.getNodeRefs().get(0));
|
return hasAccess(webProject, results.getNodeRefs().get(0), avmPath, user);
|
||||||
for (ChildAssociationRef child : children)
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.alfresco.service.cmr.avm.locking.AVMLockingService#hasAccess(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
public boolean hasAccess(NodeRef webProjectRef, String avmPath, String user)
|
||||||
|
{
|
||||||
|
if (fPersonService.getPerson(user) == null &&
|
||||||
|
!fAuthorityService.authorityExists(user))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (fAuthorityService.isAdminAuthority(user))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String webProject = (String)fNodeService.getProperty(webProjectRef, WCMAppModel.PROP_AVMSTORE);
|
||||||
|
return hasAccess(webProject, webProjectRef, avmPath, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasAccess(String webProject, NodeRef webProjectRef, String avmPath, String user)
|
||||||
|
{
|
||||||
|
List<ChildAssociationRef> children = fNodeService.getChildAssocs(
|
||||||
|
webProjectRef, WCMAppModel.ASSOC_WEBUSER, RegexQNamePattern.MATCH_ALL);
|
||||||
|
for (ChildAssociationRef child : children)
|
||||||
|
{
|
||||||
|
NodeRef childRef = child.getChildRef();
|
||||||
|
if (fNodeService.getProperty(childRef, WCMAppModel.PROP_WEBUSERNAME).equals(user) &&
|
||||||
|
fNodeService.getProperty(childRef, WCMAppModel.PROP_WEBUSERROLE).equals(ROLE_CONTENT_MANAGER))
|
||||||
{
|
{
|
||||||
NodeRef childRef = child.getChildRef();
|
return true;
|
||||||
if (fNodeService.getType(childRef).equals(WCMAppModel.TYPE_WEBUSER) &&
|
|
||||||
fNodeService.getProperty(childRef, WCMAppModel.PROP_WEBUSERNAME).equals(user) &&
|
|
||||||
fNodeService.getProperty(childRef, WCMAppModel.PROP_WEBUSERROLE).equals("ContentManager"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[] storePath = avmPath.split(":");
|
String[] storePath = avmPath.split(":");
|
||||||
@@ -619,7 +657,7 @@ public class AVMLockingServiceImpl implements AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public List<String> getWebProjects()
|
public List<String> getWebProjects()
|
||||||
{
|
{
|
||||||
List<String> keys = new ArrayList<String>();
|
List<String> keys = new ArrayList<String>(2);
|
||||||
keys.add(LOCK_TABLE);
|
keys.add(LOCK_TABLE);
|
||||||
keys.add(WEB_PROJECTS);
|
keys.add(WEB_PROJECTS);
|
||||||
return fAttributeService.getKeys(keys);
|
return fAttributeService.getKeys(keys);
|
||||||
|
@@ -28,6 +28,8 @@ package org.alfresco.service.cmr.avm.locking;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to handle AVM locking.
|
* Service to handle AVM locking.
|
||||||
* @author britt
|
* @author britt
|
||||||
@@ -123,6 +125,15 @@ public interface AVMLockingService
|
|||||||
*/
|
*/
|
||||||
public boolean hasAccess(String webProject, String avmPath, String user);
|
public boolean hasAccess(String webProject, String avmPath, String user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the user allowed to do anything to the given asset, other than read?
|
||||||
|
* @param webProjectRef The NodeRef to the web project that this path is being checked in.
|
||||||
|
* @param avmPath A full avmPath
|
||||||
|
* @param user The name of the user, group, role to check on.
|
||||||
|
* @return Whether the user has access.
|
||||||
|
*/
|
||||||
|
public boolean hasAccess(NodeRef webProjectRef, String avmPath, String user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the names of all the web projects the service knows about.
|
* Get the names of all the web projects the service knows about.
|
||||||
* @return The list of web project names.
|
* @return The list of web project names.
|
||||||
|
Reference in New Issue
Block a user