Merged V2.2 to HEAD

7575: Permission changes for AVM.
   7577: Incorporated most of the feedback provided by Kevin C earlier today
   7578: Removed directory not removed by patch
   7579: EmailServer bug fixes
         AR-1902:  Double posts when emailing to a document
         AR-1904:  Attachments via email should be allowed on forum posts
         AR-1903:  (Partial Fix) Text attachments should be treated the same way as other attachments 
   7583: Fixed WCM-961 & WCM-962: Added confirm dialog for 'Delete All Deployment Reports' and 'Release Server' actions


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8434 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-03-06 14:43:55 +00:00
parent a9fac10b45
commit a49bfd311d
89 changed files with 21301 additions and 11139 deletions

View File

@@ -39,6 +39,8 @@ import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.email.EmailMessage;
import org.alfresco.service.cmr.email.EmailMessagePart;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
@@ -47,6 +49,7 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -255,4 +258,113 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
log.debug("Emailed aspect has been added.");
}
}
/**
* Add new node into Alfresco repository with specified parameters. Node content isn't added.
*
* @param nodeService Alfresco Node Service
* @param parent Parent node
* @param name Name of the new node
* @param assocType Association type that should be set between parent node and the new one.
* @return Reference to created node
*/
protected NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name, QName assocType)
{
NodeRef childNodeRef = nodeService.getChildByName(parent, assocType, name);
if (childNodeRef != null)
{
// The node is present already. Make sure the name csae is correct
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, name);
}
else
{
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, name);
ChildAssociationRef associationRef = nodeService.createNode(
parent,
assocType,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
ContentModel.TYPE_CONTENT,
contentProps);
childNodeRef = associationRef.getChildRef();
}
return childNodeRef;
}
/**
* Add new node into Alfresco repository with specified parameters.
* Node content isn't added. New node will be created with ContentModel.ASSOC_CONTAINS association with parent.
*
* @param nodeService Alfresco Node Service
* @param parent Parent node
* @param name Name of the new node
* @return Reference to created node
*/
protected NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name)
{
return addContentNode(nodeService, parent, name, ContentModel.ASSOC_CONTAINS);
}
/**
* Adds new node into Alfresco repository and mark its as an attachment.
*
* @param nodeService Alfresco Node Service.
* @param folder Space/Folder to add.
* @param mainContentNode Main content node. Any mail is added into Alfresco as one main content node and several its attachments. Each attachment related with its main node.
* @param fileName File name for the attachment.
* @return Reference to created node.
*/
protected NodeRef addAttachment(NodeService nodeService, NodeRef folder, NodeRef mainContentNode, String fileName)
{
if (log.isDebugEnabled())
{
log.debug("Adding attachment node (name=" + fileName + ").");
}
NodeRef attachmentNode = addContentNode(nodeService, folder, fileName);
// Remove 'attached' aspect so that we work with the document in its clean form
if (nodeService.hasAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED))
{
nodeService.removeAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED);
}
// Add attached aspect
nodeService.addAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED, null);
// Recreate the association
nodeService.createAssociation(attachmentNode, mainContentNode, EmailServerModel.ASSOC_ATTACHMENT);
if (log.isDebugEnabled())
{
log.debug("Attachment has been added.");
}
return attachmentNode;
}
/**
* Extracts the attachments from the given message and adds them to the space. All attachments
* are linked back to the original node that they are attached to.
*
* @param spaceNodeRef the space to add the documents into
* @param nodeRef the node to which the documents will be attached
* @param message the email message
*/
protected void addAttachments(NodeRef spaceNodeRef, NodeRef nodeRef, EmailMessage message)
{
// Add attachments
EmailMessagePart[] attachments = message.getAttachments();
for (EmailMessagePart attachment : attachments)
{
String fileName = attachment.getFileName();
InputStream contentIs = attachment.getContent();
MimetypeService mimetypeService = getMimetypeService();
String mimetype = mimetypeService.guessMimetype(fileName);
String encoding = attachment.getEncoding();
NodeRef attachmentNode = addAttachment(getNodeService(), spaceNodeRef, nodeRef, fileName);
writeContent(attachmentNode, contentIs, mimetype, encoding);
}
}
}

View File

@@ -54,10 +54,11 @@ public abstract class AbstractForumEmailMessageHandler extends AbstractEmailMess
/**
* Posts content
*
* @param nodeRef Reference to node
* @param parser Mail parser
* @param nodeRef Reference to node
* @param parser Mail parser
* @return Returns the new post node
*/
protected void addPostNode(NodeRef nodeRef, EmailMessage message)
protected NodeRef addPostNode(NodeRef nodeRef, EmailMessage message)
{
NodeService nodeService = getNodeService();
Date now = new Date();
@@ -66,8 +67,8 @@ public abstract class AbstractForumEmailMessageHandler extends AbstractEmailMess
PropertyMap properties = new PropertyMap(3);
properties.put(ContentModel.PROP_NAME, nodeName);
NodeRef postNode = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
if (postNode == null)
NodeRef postNodeRef = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
if (postNodeRef == null)
{
ChildAssociationRef childAssoc = nodeService.createNode(
nodeRef,
@@ -75,27 +76,34 @@ public abstract class AbstractForumEmailMessageHandler extends AbstractEmailMess
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName),
ForumModel.TYPE_POST,
properties);
postNode = childAssoc.getChildRef();
postNodeRef = childAssoc.getChildRef();
}
// Add necessary aspects
properties.clear();
properties.put(ContentModel.PROP_TITLE, nodeName);
nodeService.addAspect(postNode, ContentModel.ASPECT_TITLED, properties);
nodeService.addAspect(postNodeRef, ContentModel.ASPECT_TITLED, properties);
properties.clear();
properties.put(ApplicationModel.PROP_EDITINLINE, true);
nodeService.addAspect(postNode, ApplicationModel.ASPECT_INLINEEDITABLE, properties);
nodeService.addAspect(postNodeRef, ApplicationModel.ASPECT_INLINEEDITABLE, properties);
// Write content
if (message.getBody() != null)
{
writeContent(postNode, message.getBody().getContent(), message.getBody().getContentType(), message.getBody().getEncoding());
writeContent(
postNodeRef,
message.getBody().getContent(),
message.getBody().getContentType(),
message.getBody().getEncoding());
}
else
{
writeContent(postNode, "<The message was empty>");
writeContent(postNodeRef, "<The message was empty>");
}
addEmailedAspect(postNode, message);
addEmailedAspect(postNodeRef, message);
// Done
return postNodeRef;
}
/**

View File

@@ -51,7 +51,7 @@ public class DocumentEmailMessageHandler extends AbstractForumEmailMessageHandle
{
private static final String forumNodeName = "EmailForum";
public void processMessage(NodeRef nodeRef, EmailMessage message)
public void processMessage(NodeRef contentNodeRef, EmailMessage message)
{
String messageSubject;
@@ -64,27 +64,34 @@ public class DocumentEmailMessageHandler extends AbstractForumEmailMessageHandle
messageSubject = "EMPTY_SUBJECT_" + System.currentTimeMillis();
}
QName nodeTypeQName = getNodeService().getType(nodeRef);
QName nodeTypeQName = getNodeService().getType(contentNodeRef);
DictionaryService dictionaryService = getDictionaryService();
if (dictionaryService.isSubClass(nodeTypeQName, ContentModel.TYPE_CONTENT))
{
NodeRef forumNode = getForumNode(nodeRef);
// Find where the content resides
NodeRef spaceNodeRef = getNodeService().getPrimaryParent(contentNodeRef).getParentRef();
NodeRef forumNode = getForumNode(contentNodeRef);
if (forumNode == null)
{
forumNode = addForumNode(nodeRef);
forumNode = addForumNode(contentNodeRef);
}
// Try to find existed node
NodeRef topicNode = getTopicNode(forumNode, messageSubject);
NodeRef topicNodeRef = getTopicNode(forumNode, messageSubject);
if (topicNode == null)
if (topicNodeRef == null)
{
topicNode = addTopicNode(forumNode, messageSubject);
topicNodeRef = addTopicNode(forumNode, messageSubject);
}
addPostNode(topicNode, message);
// Create the post
NodeRef postNodeRef = addPostNode(topicNodeRef, message);
// Add attachments
addAttachments(spaceNodeRef, postNodeRef, message);
}
else
{

View File

@@ -34,19 +34,14 @@ import java.util.Map;
import javax.mail.MessagingException;
import org.alfresco.email.server.EmailServerModel;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.email.EmailMessage;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.alfresco.service.cmr.email.EmailMessagePart;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -140,101 +135,7 @@ public class FolderEmailMessageHandler extends AbstractEmailMessageHandler
}
// Add attachments
EmailMessagePart[] attachments = message.getAttachments();
for (EmailMessagePart attachment : attachments)
{
String fileName = attachment.getFileName();
InputStream contentIs = attachment.getContent();
MimetypeService mimetypeService = getMimetypeService();
String mimetype = mimetypeService.guessMimetype(fileName);
String encoding = attachment.getEncoding();
NodeRef attachmentNode = addAttachment(getNodeService(), spaceNodeRef, contentNodeRef, fileName);
writeContent(attachmentNode, contentIs, mimetype, encoding);
}
}
/**
* Add new node into Alfresco repository with specified parameters. Node content isn't added. New node will be created with ContentModel.ASSOC_CONTAINS association with parent.
*
* @param nodeService Alfresco Node Service
* @param parent Parent node
* @param name Name of the new node
* @return Reference to created node
*/
private NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name)
{
return addContentNode(nodeService, parent, name, ContentModel.ASSOC_CONTAINS);
}
/**
* Add new node into Alfresco repository with specified parameters. Node content isn't added.
*
* @param nodeService Alfresco Node Service
* @param parent Parent node
* @param name Name of the new node
* @param assocType Association type that should be set between parent node and the new one.
* @return Reference to created node
*/
private NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name, QName assocType)
{
NodeRef childNodeRef = nodeService.getChildByName(parent, assocType, name);
if (childNodeRef != null)
{
// The node is present already. Make sure the name csae is correct
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, name);
}
else
{
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_NAME, name);
ChildAssociationRef associationRef = nodeService.createNode(
parent,
assocType,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
ContentModel.TYPE_CONTENT,
contentProps);
childNodeRef = associationRef.getChildRef();
}
return childNodeRef;
}
/**
* Adds new node into Alfresco repository and mark its as an attachment.
*
* @param nodeService Alfresco Node Service.
* @param folder Space/Folder to add.
* @param mainContentNode Main content node. Any mail is added into Alfresco as one main content node and several its attachments. Each attachment related with its main node.
* @param fileName File name for the attachment.
* @return Reference to created node.
*/
private NodeRef addAttachment(NodeService nodeService, NodeRef folder, NodeRef mainContentNode, String fileName)
{
if (log.isDebugEnabled())
{
log.debug("Adding attachment node (name=" + fileName + ").");
}
NodeRef attachmentNode = addContentNode(nodeService, folder, fileName);
// Remove 'attached' aspect so that we work with the document in its clean form
if (nodeService.hasAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED))
{
nodeService.removeAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED);
}
// Add attached aspect
nodeService.addAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED, null);
// Recreate the association
nodeService.createAssociation(attachmentNode, mainContentNode, EmailServerModel.ASSOC_ATTACHMENT);
if (log.isDebugEnabled())
{
log.debug("Attachment has been added.");
}
return attachmentNode;
addAttachments(spaceNodeRef, contentNodeRef, message);
}
/**

View File

@@ -32,6 +32,7 @@ import java.util.LinkedList;
import java.util.List;
import javax.mail.Address;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
@@ -176,13 +177,13 @@ public class SubethaEmailMessage implements EmailMessage
sentDate = new Date(); // Just anti-null stub :)
}
parseMesagePart(mimeMessage);
parseMessagePart(mimeMessage);
attachments = new EmailMessagePart[attachmentList.size()];
attachmentList.toArray(attachments);
attachmentList = null;
}
private void parseMesagePart(Part messagePart)
private void parseMessagePart(Part messagePart)
{
try
{
@@ -231,7 +232,18 @@ public class SubethaEmailMessage implements EmailMessage
}
for (int i = 0; i < count; i++)
{
parseMesagePart(mp.getBodyPart(i));
BodyPart bp = mp.getBodyPart(i);
String disposition = bp.getDisposition();
if (i > 0)
{
// It's an attachment. Recurse.
parseMessagePart(bp);
}
else
{
// It's the body
addBody(messagePart);
}
}
if (log.isDebugEnabled())
@@ -248,7 +260,7 @@ public class SubethaEmailMessage implements EmailMessage
log.debug("MIME_RFC822 part found. Processing inside part...");
}
parseMesagePart((Part) messagePart.getContent());
parseMessagePart((Part) messagePart.getContent());
if (log.isDebugEnabled())
{
@@ -281,27 +293,15 @@ public class SubethaEmailMessage implements EmailMessage
{
if (body != null)
{
if (!MIME_PLAIN_TEXT.equals(body.getContentType()) && messagePart.isMimeType(MIME_PLAIN_TEXT))
attachmentList.add(new SubethaEmailMessagePart(messagePart, getPartFileName(getSubject() + " (part " + ++bodyNumber + ")", messagePart)));
if (log.isInfoEnabled())
{
attachmentList.add(body);
body = new SubethaEmailMessagePart(messagePart);
if (log.isDebugEnabled())
{
log.debug("Body has been changed to the new one.");
}
}
else
{
attachmentList.add(new SubethaEmailMessagePart(messagePart, getPartFileName(getSubject() + " (part " + ++bodyNumber + ")", messagePart)));
if (log.isInfoEnabled())
{
log.info(String.format("Attachment \"%s\" has been added.", attachmentList.get(attachmentList.size() - 1).getFileName()));
}
log.info(String.format("Attachment \"%s\" has been added.", attachmentList.get(attachmentList.size() - 1).getFileName()));
}
}
else
{
body = new SubethaEmailMessagePart(messagePart, getPartFileName(getSubject() + " (part " + ++bodyNumber + ")", messagePart));
body = new SubethaEmailMessagePart(messagePart, getPartFileName(getSubject(), messagePart));
if (log.isDebugEnabled())
{
log.debug("Boby has been added.");
@@ -319,7 +319,7 @@ public class SubethaEmailMessage implements EmailMessage
*/
private void addAttachment(Part messagePart) throws MessagingException
{
String fileName = getPartFileName(FILENAME_ATTACHMENT_PREFIX + ++attachmentNumber, messagePart);
String fileName = getPartFileName(FILENAME_ATTACHMENT_PREFIX + attachmentNumber, messagePart);
attachmentList.add(new SubethaEmailMessagePart(messagePart, fileName));
if (log.isDebugEnabled())
{

View File

@@ -126,39 +126,46 @@ public class SubethaEmailServer extends EmailServer
public void data(InputStream data) throws TooMuchDataException, IOException, RejectException
{
if (deliveries.size() == 1)
if (deliveries.size() > 0)
{
Delivery delivery = deliveries.get(0);
processDelivery(delivery, data);
}
else if (deliveries.size() > 1)
{
DeferredFileOutputStream dfos = null;
try
{
dfos = new DeferredFileOutputStream(DEFAULT_DATA_DEFERRED_SIZE);
byte[] bytes = new byte[1024 * 8];
for (int len = -1; (len = data.read(bytes)) != -1;)
{
dfos.write(bytes, 0, len);
}
for (Delivery delivery : deliveries)
{
processDelivery(delivery, dfos.getInputStream());
}
}
finally
{
try
{
dfos.close();
}
catch (Exception e)
{
}
}
}
// Duplicate messages coming in
// http://www.subethamail.org/se/archive_msg.jsp?msgId=20938
// if (deliveries.size() == 1)
// {
// Delivery delivery = deliveries.get(0);
// processDelivery(delivery, data);
// }
// else if (deliveries.size() > 1)
// {
// DeferredFileOutputStream dfos = null;
// try
// {
// dfos = new DeferredFileOutputStream(DEFAULT_DATA_DEFERRED_SIZE);
//
// byte[] bytes = new byte[1024 * 8];
// for (int len = -1; (len = data.read(bytes)) != -1;)
// {
// dfos.write(bytes, 0, len);
// }
// for (Delivery delivery : deliveries)
// {
// processDelivery(delivery, dfos.getInputStream());
// }
// }
// finally
// {
// try
// {
// dfos.close();
// }
// catch (Exception e)
// {
// }
// }
// }
}
private void processDelivery(Delivery delivery, InputStream data) throws RejectException

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.admin.patch.impl;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* The roles defined in permissionsDefinition.xml moved from <b>wca:webfolder</b> to <b>cm:cmobject</b>.
* This effects the data stored in the <b>permission</b> table.
* <p>
*
*/
public class AVMPermissionDataPatch extends AbstractPermissionChangePatch
{
private static final String MSG_SUCCESS = "patch.updateAvmPermissionData.result";
private static final QName TYPE_QNAME_OLD = QName.createQName(NamespaceService.WCMAPP_MODEL_1_0_URI, "webfolder");
private static final QName TYPE_QNAME_NEW = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "cmobject");
private static final String[] NAMES = new String[] {"ContentManager", "ContentPublisher", "ContentContributor", "ContentReviewer"};
@Override
protected String applyInternal() throws Exception
{
int updateCount = 0;
for (String permissionName : NAMES)
{
updateCount += super.renamePermission(
AVMPermissionDataPatch.TYPE_QNAME_OLD,
permissionName,
AVMPermissionDataPatch.TYPE_QNAME_NEW,
permissionName);
}
// build the result message
String msg = I18NUtil.getMessage(MSG_SUCCESS, updateCount);
// done
return msg;
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing
*/
package org.alfresco.repo.admin.patch.impl;
import java.util.Map;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.security.permissions.ACLType;
/**
* Migrate permissions from the OLD format to defining, shared and layered
*/
public class AVMPermissionsPatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.updateAvmPermissions.result";
private AccessControlListDAO accessControlListDao;
@Override
protected String applyInternal() throws Exception
{
Map<ACLType, Integer> summary = accessControlListDao.patchAcls();
// build the result message
String msg = I18NUtil.getMessage(MSG_SUCCESS, summary.get(ACLType.DEFINING), summary.get(ACLType.LAYERED));
// done
return msg;
}
public void setAccessControlListDao(AccessControlListDAO accessControlListDao)
{
this.accessControlListDao = accessControlListDao;
}
}

View File

@@ -96,7 +96,6 @@ public abstract class AbstractPermissionChangePatch extends AbstractPatch
private static class HibernateHelper extends HibernateDaoSupport
{
private static final String QUERY_GET_PERMISSION = "permission.GetPermission";
private static final String QUERY_GET_ENTRIES_TO_CHANGE = "permission.patch.GetAccessControlEntriesToChangePermissionOn";
public int createAndUpdatePermission(
final QName oldTypeQName,
@@ -109,7 +108,7 @@ public abstract class AbstractPermissionChangePatch extends AbstractPatch
throw new IllegalArgumentException("Cannot move permission to itself: " + oldTypeQName + "-" + oldName);
}
HibernateCallback getNewPermissionCallback = new GetPermissionCallback(newTypeQName, newName);
HibernateCallback getNewPermissionCallback = new GetPermissionCallback(oldTypeQName, oldName);
DbPermission permission = (DbPermission) getHibernateTemplate().execute(getNewPermissionCallback);
if (permission == null)
{
@@ -120,58 +119,13 @@ public abstract class AbstractPermissionChangePatch extends AbstractPatch
// save
getHibernateTemplate().save(permission);
}
final DbPermission newPermission = permission;
// now update all entries that refer to the old permission
HibernateCallback updateEntriesCallback = new HibernateCallback()
else
{
private static final int MAX_RESULTS = 1000;
@SuppressWarnings("unchecked")
public Object doInHibernate(Session session)
{
int count = 0;
while (true)
{
// flush any outstanding entities
session.flush();
Query query = session.getNamedQuery(HibernateHelper.QUERY_GET_ENTRIES_TO_CHANGE);
query.setParameter("oldTypeQName", oldTypeQName)
.setParameter("oldName", oldName)
.setMaxResults(MAX_RESULTS);
List<DbAccessControlEntry> entries = (List<DbAccessControlEntry>) query.list();
// if there are no results, then we're done
if (entries.size() == 0)
{
break;
}
for (DbAccessControlEntry entry : entries)
{
entry.setPermission(newPermission);
count++;
session.evict(entry);
}
// flush and evict all the entries
session.flush();
for (DbAccessControlEntry entry : entries)
{
session.evict(entry);
}
// next set of results
}
// done
return count;
}
};
int updateCount = (Integer) getHibernateTemplate().execute(updateEntriesCallback);
// now delete the old permission
HibernateCallback getOldPermissionCallback = new GetPermissionCallback(oldTypeQName, oldName);
DbPermission oldPermission = (DbPermission) getHibernateTemplate().execute(getOldPermissionCallback);
if (oldPermission != null)
{
getHibernateTemplate().delete(oldPermission);
permission.setTypeQname(newTypeQName);
permission.setName(newName);
}
// done
return updateCount;
return 1;
}
}
}

View File

@@ -1,250 +1,250 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.namespace.QName;
/**
* The Interface for versionable objects.
* @author britt
*/
public interface AVMNode
{
/**
* Set the ancestor of this node.
* @param ancestor The ancestor to set.
*/
public void setAncestor(AVMNode ancestor);
/**
* Change the ancestor of a node.
* @param ancestor The ancestor node that should be set.
*/
public void changeAncestor(AVMNode ancestor);
/**
* Get the ancestor of this node.
* @return The ancestor of this node.
*/
public AVMNode getAncestor();
/**
* Set the merged from node.
* @param mergedFrom The merged from node.
*/
public void setMergedFrom(AVMNode mergedFrom);
/**
* Get the node this was merged from.
* @return The node this was merged from.
*/
public AVMNode getMergedFrom();
/**
* Get the version number.
* @return The version number.
*/
public int getVersionID();
/**
* Set the version number.
* @param version The version number to set.
*/
public void setVersionID(int version);
/**
* Possibly copy ourselves.
* @param lPath The Lookup for this node.
* @return A copy of ourself or null if no copy was necessary.
*/
public AVMNode copy(Lookup lPath);
/**
* Get the type of this node.
*/
public int getType();
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @param name The name of this in the current context.
* @return The descriptor for this node.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name);
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return The descriptor for this node.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath);
/**
* Get a node descriptor for this node.
* @param parentPath The parent path.
* @param name The name looked up as.
* @param parentIndirection The indirection of the parent.
* @param parentIndirectionVersion The indirection version of the parent.
* @return The descriptor for this node.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion);
/**
* Get the object id.
* @return The object id.
*/
public long getId();
/**
* Get the newnews.
* @return Whether the node is new.
*/
public boolean getIsNew();
/**
* Get a string representation for debugging.
* @param lPath The Lookup.
* @return A String representation.
*/
public String toString(Lookup lPath);
/**
* Set whether this node to be a root of a AVMStore
* @param isRoot
*/
public void setIsRoot(boolean isRoot);
/**
* Get whether this node is a root of a AVMStore.
* @return Whether this node is a root.
*/
public boolean getIsRoot();
/**
* Update the modification time of this node.
*/
public void updateModTime();
/**
* Set a property.
* @param name The name of the property.
* @param value The value to set.
*/
public void setProperty(QName name, PropertyValue value);
/**
* Set a collection of properties on this node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(Map<QName, PropertyValue> properties);
/**
* Get a property by name.
* @param name The name of the property to get.
* @return A PropertyValue
*/
public PropertyValue getProperty(QName name);
/**
* Get all the properties associated with this node.
* @return A Map of QNames to PropertyValues.
*/
public Map<QName, PropertyValue> getProperties();
/**
* Delete a property from this node.
* @param name The name of the property.
*/
public void deleteProperty(QName name);
/**
* Delete all properties from this node.
*/
public void deleteProperties();
/**
* Set an ACL on this node.
* @param acl The ACL to set.
*/
public void setAcl(DbAccessControlList acl);
/**
* Get the ACL on this node.
* @return The ACL on this node.
*/
public DbAccessControlList getAcl();
/**
* Set the store that we are new in.
* @param store The store we are new in.
*/
public void setStoreNew(AVMStore store);
/**
* Get the possibly null store that we're new in.
* @return The store that we're new in.
*/
public AVMStore getStoreNew();
/**
* Copy metadata from another node.
* @param other The other node.
*/
public void copyMetaDataFrom(AVMNode other);
/**
* Get the GUID associated with this version.
* @return The GUID.
*/
public String getGuid();
/**
* Set the GUID associated with this version.
* @param guid
*/
public void setGuid(String guid);
/**
* Get the Aspects that this node has.
* @return A Set of Aspects names.
*/
public Set<QName> getAspects();
/**
* Add properties to those that already exist.
* @param properties The properties to add.
*/
public void addProperties(Map<QName, PropertyValue> properties);
/**
* Get the Basic Attributes on this node.
* @return
*/
public BasicAttributes getBasicAttributes();
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.namespace.QName;
/**
* The Interface for versionable objects.
* @author britt
*/
public interface AVMNode
{
/**
* Set the ancestor of this node.
* @param ancestor The ancestor to set.
*/
public void setAncestor(AVMNode ancestor);
/**
* Change the ancestor of a node.
* @param ancestor The ancestor node that should be set.
*/
public void changeAncestor(AVMNode ancestor);
/**
* Get the ancestor of this node.
* @return The ancestor of this node.
*/
public AVMNode getAncestor();
/**
* Set the merged from node.
* @param mergedFrom The merged from node.
*/
public void setMergedFrom(AVMNode mergedFrom);
/**
* Get the node this was merged from.
* @return The node this was merged from.
*/
public AVMNode getMergedFrom();
/**
* Get the version number.
* @return The version number.
*/
public int getVersionID();
/**
* Set the version number.
* @param version The version number to set.
*/
public void setVersionID(int version);
/**
* Possibly copy ourselves.
* @param lPath The Lookup for this node.
* @return A copy of ourself or null if no copy was necessary.
*/
public AVMNode copy(Lookup lPath);
/**
* Get the type of this node.
*/
public int getType();
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @param name The name of this in the current context.
* @return The descriptor for this node.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name);
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return The descriptor for this node.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath);
/**
* Get a node descriptor for this node.
* @param parentPath The parent path.
* @param name The name looked up as.
* @param parentIndirection The indirection of the parent.
* @param parentIndirectionVersion The indirection version of the parent.
* @return The descriptor for this node.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion);
/**
* Get the object id.
* @return The object id.
*/
public long getId();
/**
* Get the newnews.
* @return Whether the node is new.
*/
public boolean getIsNew();
/**
* Get a string representation for debugging.
* @param lPath The Lookup.
* @return A String representation.
*/
public String toString(Lookup lPath);
/**
* Set whether this node to be a root of a AVMStore
* @param isRoot
*/
public void setIsRoot(boolean isRoot);
/**
* Get whether this node is a root of a AVMStore.
* @return Whether this node is a root.
*/
public boolean getIsRoot();
/**
* Update the modification time of this node.
*/
public void updateModTime();
/**
* Set a property.
* @param name The name of the property.
* @param value The value to set.
*/
public void setProperty(QName name, PropertyValue value);
/**
* Set a collection of properties on this node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(Map<QName, PropertyValue> properties);
/**
* Get a property by name.
* @param name The name of the property to get.
* @return A PropertyValue
*/
public PropertyValue getProperty(QName name);
/**
* Get all the properties associated with this node.
* @return A Map of QNames to PropertyValues.
*/
public Map<QName, PropertyValue> getProperties();
/**
* Delete a property from this node.
* @param name The name of the property.
*/
public void deleteProperty(QName name);
/**
* Delete all properties from this node.
*/
public void deleteProperties();
/**
* Set an ACL on this node.
* @param acl The ACL to set.
*/
public void setAcl(DbAccessControlList acl);
/**
* Get the ACL on this node.
* @return The ACL on this node.
*/
public DbAccessControlList getAcl();
/**
* Set the store that we are new in.
* @param store The store we are new in.
*/
public void setStoreNew(AVMStore store);
/**
* Get the possibly null store that we're new in.
* @return The store that we're new in.
*/
public AVMStore getStoreNew();
/**
* Copy metadata from another node.
* @param other The other node.
*/
public void copyMetaDataFrom(AVMNode other, Long parentAcl);
/**
* Get the GUID associated with this version.
* @return The GUID.
*/
public String getGuid();
/**
* Set the GUID associated with this version.
* @param guid
*/
public void setGuid(String guid);
/**
* Get the Aspects that this node has.
* @return A Set of Aspects names.
*/
public Set<QName> getAspects();
/**
* Add properties to those that already exist.
* @param properties The properties to add.
*/
public void addProperties(Map<QName, PropertyValue> properties);
/**
* Get the Basic Attributes on this node.
* @return
*/
public BasicAttributes getBasicAttributes();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,7 @@ import org.alfresco.repo.avm.util.RawServices;
import org.alfresco.repo.avm.util.SimplePath;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
import org.alfresco.service.cmr.avm.AVMException;
@@ -349,7 +350,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
// a LayeredDirectoryNode that gets its indirection from
// its parent.
{
newDir = new LayeredDirectoryNodeImpl((String)null, this, null);
newDir = new LayeredDirectoryNodeImpl((String)null, this, null, null, ACLCopyMode.INHERIT);
((LayeredDirectoryNodeImpl)newDir).setPrimaryIndirection(false);
((LayeredDirectoryNodeImpl)newDir).setLayerID(lPath.getTopLayer().getLayerID());
}
@@ -373,7 +374,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
newDir.getProperties().putAll(properties);
}
DbAccessControlList acl = dir.getAcl();
newDir.setAcl(acl != null ? acl.getCopy() : null);
newDir.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null);
}
/**
@@ -397,8 +398,9 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AVMExistsException("Child exists: " + name);
}
Long parentAcl = dir.getAcl() == null ? null : dir.getAcl().getId();
LayeredDirectoryNode newDir =
new LayeredDirectoryNodeImpl(srcPath, this, null);
new LayeredDirectoryNodeImpl(srcPath, this, null, parentAcl, ACLCopyMode.INHERIT);
if (lPath.isLayered())
{
// When a layered directory is made inside of a layered context,
@@ -458,7 +460,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
-1,
"UTF-8"));
DbAccessControlList acl = dir.getAcl();
file.setAcl(acl != null ? acl.getCopy() : null);
file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null);
ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name));
return writer.getContentOutputStream();
}
@@ -508,7 +510,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
file.getProperties().putAll(properties);
}
DbAccessControlList acl = dir.getAcl();
file.setAcl(acl != null ? acl.getCopy() : null);
file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null);
// Yet another flush.
AVMDAOs.Instance().fAVMNodeDAO.flush();
ContentWriter writer = createContentWriter(AVMNodeConverter.ExtendAVMPath(path, name));
@@ -541,7 +543,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
}
// TODO Reexamine decision to not check validity of srcPath.
LayeredFileNodeImpl newFile =
new LayeredFileNodeImpl(srcPath, this);
new LayeredFileNodeImpl(srcPath, this, null);
if (child != null)
{
newFile.setAncestor(child);
@@ -549,7 +551,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
dir.updateModTime();
dir.putChild(name, newFile);
DbAccessControlList acl = dir.getAcl();
newFile.setAcl(acl != null ? acl.getCopy() : null);
newFile.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null);
// newFile.setVersionID(getNextVersionID());
}
@@ -1431,7 +1433,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to write properties: " + path);
}
node.copyMetaDataFrom(from);
node.copyMetaDataFrom(from, node.getAcl() == null ? null : node.getAcl().getInheritsFrom());
node.setGuid(GUID.generate());
}
@@ -1565,7 +1567,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
}
if (!fAVMRepository.can(lPath.getCurrentNode(), PermissionService.READ_PERMISSIONS))
{
throw new AccessDeniedException("Not allowed to read permissions: " + path);
throw new AccessDeniedException("Not allowed to read permissions: " + path + " in "+getName());
}
return lPath.getCurrentNode().getAcl();
}

View File

@@ -1,216 +1,225 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
/**
* Place holder for a deleted node.
* @author britt
*/
public class DeletedNodeImpl extends AVMNodeImpl implements DeletedNode
{
private static final long serialVersionUID = 7283526790174482993L;
/**
* The type of node that this is a deleted node for.
*/
private int fDeletedType;
/**
* For Hibernate's use.
*/
protected DeletedNodeImpl()
{
}
/**
* Create a new one from scratch.
* @param id The node id.
* @param store The store it's being created in.
*/
public DeletedNodeImpl(long id,
AVMStore store)
{
super(id, store);
}
public DeletedNodeImpl(DeletedNode other,
AVMStore store)
{
super(store.getAVMRepository().issueID(), store);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
copyProperties(other);
copyAspects(other);
copyACLs(other);
}
/**
* Setter.
*/
public void setDeletedType(int type)
{
fDeletedType = type;
}
/**
* Getter.
*/
public int getDeletedType()
{
return fDeletedType;
}
// TODO What happens when this is called? Does it muck anything up.
/**
* This is only called rarely.
*/
public AVMNode copy(Lookup lPath)
{
AVMNode newMe = new DeletedNodeImpl(this, lPath.getAVMStore());
newMe.setAncestor(this);
return newMe;
}
/**
* Get a descriptor.
* @param lPath The Lookup to this node's parent.
* @param name The name of this node.
* @return An AVMNodeDescriptor
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
if (path.endsWith("/"))
{
path = path + name;
}
else
{
path = path + "/" + name;
}
return new AVMNodeDescriptor(path,
name,
AVMNodeType.DELETED_NODE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
-1,
fDeletedType);
}
/**
* Get a descriptor.
* @param lPath The full Lookup to this.
* @return An AVMNodeDescriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
return new AVMNodeDescriptor(path,
path.substring(path.lastIndexOf("/") + 1),
AVMNodeType.DELETED_NODE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
-1,
fDeletedType);
}
/**
* Get a descriptor.
* @param parentPath
* @param name
* @param parentIndirection Ignored.
* @return An AVMNodeDescriptor.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion)
{
BasicAttributes attrs = getBasicAttributes();
String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name;
return new AVMNodeDescriptor(path,
name,
AVMNodeType.DELETED_NODE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
-1,
fDeletedType);
}
/**
* Get the type of this node.
* @return The AVMNodeType of this.
*/
public int getType()
{
return AVMNodeType.DELETED_NODE;
}
/**
* Get a descriptive string representation.
* @param lPath The lookup we've been found through.
* @return A String representation.
*/
public String toString(Lookup lPath)
{
return "[DN:" + getId() + "]";
}
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
/**
* Place holder for a deleted node.
* @author britt
*/
public class DeletedNodeImpl extends AVMNodeImpl implements DeletedNode
{
private static final long serialVersionUID = 7283526790174482993L;
/**
* The type of node that this is a deleted node for.
*/
private int fDeletedType;
/**
* For Hibernate's use.
*/
protected DeletedNodeImpl()
{
}
/**
* Create a new one from scratch.
* @param id The node id.
* @param store The store it's being created in.
*/
public DeletedNodeImpl(long id,
AVMStore store, DbAccessControlList acl)
{
super(id, store);
this.setAcl(acl);
}
public DeletedNodeImpl(DeletedNode other,
AVMStore store, Long parentAcl, ACLCopyMode mode)
{
super(store.getAVMRepository().issueID(), store);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
copyProperties(other);
copyAspects(other);
copyACLs(other, parentAcl, mode);
}
/**
* Setter.
*/
public void setDeletedType(int type)
{
fDeletedType = type;
}
/**
* Getter.
*/
public int getDeletedType()
{
return fDeletedType;
}
// TODO What happens when this is called? Does it muck anything up.
/**
* This is only called rarely.
*/
public AVMNode copy(Lookup lPath)
{
DirectoryNode dir = lPath.getCurrentNodeDirectory();
Long parentAclId = null;
if((dir != null) && (dir.getAcl() != null))
{
parentAclId = dir.getAcl().getId();
}
AVMNode newMe = new DeletedNodeImpl(this, lPath.getAVMStore(), parentAclId, ACLCopyMode.COPY);
newMe.setAncestor(this);
return newMe;
}
/**
* Get a descriptor.
* @param lPath The Lookup to this node's parent.
* @param name The name of this node.
* @return An AVMNodeDescriptor
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
if (path.endsWith("/"))
{
path = path + name;
}
else
{
path = path + "/" + name;
}
return new AVMNodeDescriptor(path,
name,
AVMNodeType.DELETED_NODE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
-1,
fDeletedType);
}
/**
* Get a descriptor.
* @param lPath The full Lookup to this.
* @return An AVMNodeDescriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
return new AVMNodeDescriptor(path,
path.substring(path.lastIndexOf("/") + 1),
AVMNodeType.DELETED_NODE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
-1,
fDeletedType);
}
/**
* Get a descriptor.
* @param parentPath
* @param name
* @param parentIndirection Ignored.
* @return An AVMNodeDescriptor.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion)
{
BasicAttributes attrs = getBasicAttributes();
String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name;
return new AVMNodeDescriptor(path,
name,
AVMNodeType.DELETED_NODE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
-1,
fDeletedType);
}
/**
* Get the type of this node.
* @return The AVMNodeType of this.
*/
public int getType()
{
return AVMNodeType.DELETED_NODE;
}
/**
* Get a descriptive string representation.
* @param lPath The lookup we've been found through.
* @return A String representation.
*/
public String toString(Lookup lPath)
{
return "[DN:" + getId() + "]";
}
}

View File

@@ -1,79 +1,80 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMNotFoundException;
/**
* Base class for Directories.
* @author britt
*/
abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode
{
/**
* Default constructor.
*/
protected DirectoryNodeImpl()
{
}
/**
* A pass through constructor. Called when a new concrete subclass
* instance is created.
* @param id
* @param repo
*/
protected DirectoryNodeImpl(long id, AVMStore repo)
{
super(id, repo);
}
/**
* Dangerous version of link.
* @param name The name to give the child.
* @param toLink The child to link in.
*/
public void link(String name, AVMNodeDescriptor toLink)
{
AVMNode node = AVMDAOs.Instance().fAVMNodeDAO.getByID(toLink.getId());
if (node == null)
{
throw new AVMNotFoundException("Child node not found.");
}
if (node.getType() == AVMNodeType.LAYERED_DIRECTORY &&
!((LayeredDirectoryNode)node).getPrimaryIndirection())
{
throw new AVMBadArgumentException("Non primary layered directories cannot be linked.");
}
// Make the new ChildEntry and save.
ChildKey key = new ChildKey(this, name);
ChildEntry newChild = new ChildEntryImpl(key, node);
AVMDAOs.Instance().fChildEntryDAO.save(newChild);
AVMDAOs.Instance().fAVMNodeDAO.flush();
AVMDAOs.Instance().fChildEntryDAO.evict(newChild);
AVMDAOs.Instance().fAVMNodeDAO.evict(node);
}
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMNotFoundException;
/**
* Base class for Directories.
* @author britt
*/
abstract class DirectoryNodeImpl extends AVMNodeImpl implements DirectoryNode
{
/**
* Default constructor.
*/
protected DirectoryNodeImpl()
{
}
/**
* A pass through constructor. Called when a new concrete subclass
* instance is created.
* @param id
* @param repo
*/
protected DirectoryNodeImpl(long id, AVMStore repo)
{
super(id, repo);
}
/**
* Dangerous version of link.
* @param name The name to give the child.
* @param toLink The child to link in.
*/
public void link(String name, AVMNodeDescriptor toLink)
{
AVMNode node = AVMDAOs.Instance().fAVMNodeDAO.getByID(toLink.getId());
if (node == null)
{
throw new AVMNotFoundException("Child node not found.");
}
if (node.getType() == AVMNodeType.LAYERED_DIRECTORY &&
!((LayeredDirectoryNode)node).getPrimaryIndirection())
{
throw new AVMBadArgumentException("Non primary layered directories cannot be linked.");
}
// Make the new ChildEntry and save.
ChildKey key = new ChildKey(this, name);
ChildEntry newChild = new ChildEntryImpl(key, node);
AVMDAOs.Instance().fChildEntryDAO.save(newChild);
AVMDAOs.Instance().fAVMNodeDAO.flush();
AVMDAOs.Instance().fChildEntryDAO.evict(newChild);
AVMDAOs.Instance().fAVMNodeDAO.evict(node);
}
}

View File

@@ -1,48 +1,50 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
/**
* Base class for file objects.
* @author britt
*/
abstract class FileNodeImpl extends AVMNodeImpl implements FileNode
{
/**
* Default constructor.
*/
protected FileNodeImpl()
{
}
/**
* Pass through constructor.
* @param id The newly assigned object id.
* @param store The AVMStore we belong to.
*/
public FileNodeImpl(long id, AVMStore store)
{
super(id, store);
}
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import org.alfresco.repo.domain.DbAccessControlList;
/**
* Base class for file objects.
* @author britt
*/
abstract class FileNodeImpl extends AVMNodeImpl implements FileNode
{
/**
* Default constructor.
*/
protected FileNodeImpl()
{
}
/**
* Pass through constructor.
* @param id The newly assigned object id.
* @param store The AVMStore we belong to.
*/
public FileNodeImpl(long id, AVMStore store)
{
super(id, store);
}
}

View File

@@ -1,92 +1,92 @@
package org.alfresco.repo.avm;
/**
* Interface for Layered Directories.
* @author britt
*/
public interface LayeredDirectoryNode extends DirectoryNode, Layered
{
/**
* Does this node have a primary indirection.
* @return Whether this is a primary indirection.
*/
public boolean getPrimaryIndirection();
/**
* Set whether this has a primary indirection.
* @param has Whether this has a primary indirection.
*/
public void setPrimaryIndirection(boolean has);
/**
* Get the layer id for this node.
* @return The layer id.
*/
public long getLayerID();
/**
* Set the layer id for this node.
* @param id The id to set.
*/
public void setLayerID(long id);
/**
* Set this to be a primary indirection from the path
* passed in.
* @param path The indirection path.
*/
public void rawSetPrimary(String path);
/**
* Turn this node into a primary indirection node with the indirection
* taken from the Lookup passed in.
* Performs a copy on write.
* @param lPath
*/
public void turnPrimary(Lookup lPath);
/**
* Retarget this directory.
* @param lPath The Lookup.
* @param target The new target path.
*/
public void retarget(Lookup lPath, String target);
/**
* Make visible a node deleted in a layer.
* @param lPath The Lookup.
* @param name The name to make visible.
*/
public void uncover(Lookup lPath, String name);
/**
* Remove name without leaving behind a deleted node.
* @param name The name of the child to flatten.
*/
public void flatten(String name);
/**
* Set the indirection.
* @param indirection
*/
public void setIndirection(String indirection);
/**
* Get the indirection version.
* @return The indirection version.
*/
public Integer getIndirectionVersion();
/**
* Set the opacity of this.
* @param opacity Whether this should be opaque, i.e. not see the things it
* in its indirection.
*/
public void setOpacity(boolean opacity);
/**
* Get the opacity of this.
* @return The opacity.
*/
public boolean getOpacity();
package org.alfresco.repo.avm;
/**
* Interface for Layered Directories.
* @author britt
*/
public interface LayeredDirectoryNode extends DirectoryNode, Layered
{
/**
* Does this node have a primary indirection.
* @return Whether this is a primary indirection.
*/
public boolean getPrimaryIndirection();
/**
* Set whether this has a primary indirection.
* @param has Whether this has a primary indirection.
*/
public void setPrimaryIndirection(boolean has);
/**
* Get the layer id for this node.
* @return The layer id.
*/
public long getLayerID();
/**
* Set the layer id for this node.
* @param id The id to set.
*/
public void setLayerID(long id);
/**
* Set this to be a primary indirection from the path
* passed in.
* @param path The indirection path.
*/
public void rawSetPrimary(Lookup lPath, String path);
/**
* Turn this node into a primary indirection node with the indirection
* taken from the Lookup passed in.
* Performs a copy on write.
* @param lPath
*/
public void turnPrimary(Lookup lPath);
/**
* Retarget this directory.
* @param lPath The Lookup.
* @param target The new target path.
*/
public void retarget(Lookup lPath, String target);
/**
* Make visible a node deleted in a layer.
* @param lPath The Lookup.
* @param name The name to make visible.
*/
public void uncover(Lookup lPath, String name);
/**
* Remove name without leaving behind a deleted node.
* @param name The name of the child to flatten.
*/
public void flatten(String name);
/**
* Set the indirection.
* @param indirection
*/
public void setIndirection(String indirection);
/**
* Get the indirection version.
* @return The indirection version.
*/
public Integer getIndirectionVersion();
/**
* Set the opacity of this.
* @param opacity Whether this should be opaque, i.e. not see the things it
* in its indirection.
*/
public void setOpacity(boolean opacity);
/**
* Get the opacity of this.
* @return The opacity.
*/
public boolean getOpacity();
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,338 +1,363 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.repository.ContentData;
/**
* A LayeredFileNode behaves like a copy on write symlink.
* @author britt
*/
class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
{
static final long serialVersionUID = 9208423010479156363L;
/**
* The indirection.
*/
private String fIndirection;
/**
* The indirection version.
*/
private int fIndirectionVersion;
/**
* Anonymous constructor.
*/
protected LayeredFileNodeImpl()
{
}
/**
* Basically a copy constructor. Used when a branch is created
* from a layered file.
* @param other The file to make a copy of.
* @param store The store that contains us.
*/
public LayeredFileNodeImpl(LayeredFileNode other, AVMStore store)
{
super(store.getAVMRepository().issueID(), store);
fIndirection = other.getIndirection();
fIndirectionVersion = -1;
setVersionID(other.getVersionID() + 1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
copyProperties(other);
copyAspects(other);
copyACLs(other);
}
/**
* Make a brand new layered file node.
* @param indirection The thing we point to.
* @param store The store we belong to.
*/
public LayeredFileNodeImpl(String indirection, AVMStore store)
{
super(store.getAVMRepository().issueID(), store);
fIndirection = indirection;
fIndirectionVersion = -1;
setVersionID(1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
}
/**
* Copy on write logic.
* @param lPath The path by which this was found.
*/
public AVMNode copy(Lookup lPath)
{
// LayeredFileNodes are always copied.
Lookup lookup = AVMRepository.GetInstance().lookup(-1, fIndirection, false);
if (lookup == null)
{
throw new AVMException("Unbacked layered file node.");
}
AVMNode indirect = lookup.getCurrentNode();
if (indirect.getType() != AVMNodeType.LAYERED_FILE &&
indirect.getType() != AVMNodeType.PLAIN_FILE)
{
throw new AVMException("Unbacked layered file node.");
}
// TODO This doesn't look quite right.
PlainFileNodeImpl newMe = new PlainFileNodeImpl(lPath.getAVMStore(),
getBasicAttributes(),
getContentData(lPath),
indirect.getProperties(),
indirect.getAspects(),
indirect.getAcl(),
getVersionID());
newMe.setAncestor(this);
return newMe;
}
/**
* Get the type of this node.
* @return The type.
*/
public int getType()
{
return AVMNodeType.LAYERED_FILE;
}
/**
* Get the underlying path.
* @param lookup The Lookup. (Unused here.)
* @return The underlying path.
*/
public String getUnderlying(Lookup lookup)
{
return fIndirection;
}
/**
* Get a diagnostic String representation.
* @param lPath The Lookup.
* @return A diagnostic String representation.
*/
public String toString(Lookup lPath)
{
return "[LF:" + getId() + ":" + fIndirection + "]";
}
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
if (path.endsWith("/"))
{
path = path + name;
}
else
{
path = path + "/" + name;
}
return new AVMNodeDescriptor(path,
name,
AVMNodeType.LAYERED_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
getUnderlying(lPath),
getUnderlyingVersion(lPath),
false,
-1,
false,
0,
-1);
}
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
return new AVMNodeDescriptor(path,
path.substring(path.lastIndexOf("/") + 1),
AVMNodeType.LAYERED_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
getUnderlying(lPath),
getUnderlyingVersion(lPath),
false,
-1,
false,
0,
-1);
}
/**
* Get the descriptor for this node.
* @param parentPath The parent path.
* @param name The name this was looked up with.
* @param parentIndirection The parent indirection.
* @return The descriptor.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion)
{
BasicAttributes attrs = getBasicAttributes();
String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name;
return new AVMNodeDescriptor(path,
name,
AVMNodeType.LAYERED_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
fIndirection,
fIndirectionVersion,
false,
-1,
false,
0,
-1);
}
/**
* Get the indirection.
* @return The indirection.
*/
public String getIndirection()
{
return fIndirection;
}
/**
* Set the indirection.
* @param indirection
*/
public void setIndirection(String indirection)
{
fIndirection = indirection;
}
/**
* Set the ContentData for this file.
* @param contentData The value to set.
*/
public void setContentData(ContentData contentData)
{
throw new AVMException("Should not be called.");
}
// TODO The lPath argument is unnecessary.
/**
* Get the ContentData for this file.
* @return The ContentData object for this file.
*/
public ContentData getContentData(Lookup lPath)
{
Lookup lookup = lPath.getAVMStore().getAVMRepository().lookup(getUnderlyingVersion(lPath), getIndirection(), false);
if (lookup == null)
{
throw new AVMException("Invalid target.");
}
AVMNode node = lookup.getCurrentNode();
if (!(node instanceof FileNode))
{
throw new AVMException("Invalid target.");
}
FileNode file = (FileNode)node;
return file.getContentData(lookup);
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.Layered#getUnderlyingVersion(org.alfresco.repo.avm.Lookup)
*/
public int getUnderlyingVersion(Lookup lookup)
{
if (lookup.getVersion() == -1)
{
return -1;
}
return fIndirectionVersion;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.LayeredFileNode#getIndirectionVersion()
*/
public Integer getIndirectionVersion()
{
return fIndirectionVersion;
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.LayeredFileNode#setIndirectionVersion(int)
*/
public void setIndirectionVersion(Integer version)
{
if (version == null)
{
fIndirectionVersion = -1;
}
else
{
fIndirectionVersion = version;
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.LayeredFileNode#copyLiterally(org.alfresco.repo.avm.Lookup)
*/
public LayeredFileNode copyLiterally(Lookup lookup)
{
return new LayeredFileNodeImpl(this, lookup.getAVMStore());
}
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.hibernate.DbAccessControlListImpl;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.repository.ContentData;
/**
* A LayeredFileNode behaves like a copy on write symlink.
*
* @author britt
*/
class LayeredFileNodeImpl extends FileNodeImpl implements LayeredFileNode
{
static final long serialVersionUID = 9208423010479156363L;
/**
* The indirection.
*/
private String fIndirection;
/**
* The indirection version.
*/
private int fIndirectionVersion;
/**
* Anonymous constructor.
*/
protected LayeredFileNodeImpl()
{
}
/**
* Basically a copy constructor. Used when a branch is created from a layered file.
*
* @param other
* The file to make a copy of.
* @param store
* The store that contains us.
*/
public LayeredFileNodeImpl(LayeredFileNode other, AVMStore store, Long parentAcl, ACLCopyMode mode)
{
super(store.getAVMRepository().issueID(), store);
fIndirection = other.getIndirection();
fIndirectionVersion = -1;
setVersionID(other.getVersionID() + 1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
copyProperties(other);
copyAspects(other);
copyACLs(other, parentAcl, mode);
}
/**
* Make a brand new layered file node.
*
* @param indirection
* The thing we point to.
* @param store
* The store we belong to.
*/
public LayeredFileNodeImpl(String indirection, AVMStore store, DbAccessControlList acl)
{
super(store.getAVMRepository().issueID(), store);
fIndirection = indirection;
fIndirectionVersion = -1;
setVersionID(1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
if (acl != null)
{
this.setAcl(acl);
}
else
{
if (indirection != null)
{
Lookup lookup = AVMRepository.GetInstance().lookup(-1, indirection, false);
if (lookup != null)
{
AVMNode node = lookup.getCurrentNode();
if (node.getAcl() != null)
{
setAcl(DbAccessControlListImpl.createLayeredAcl(node.getAcl().getId()));
}
else
{
setAcl(DbAccessControlListImpl.createLayeredAcl(null));
}
}
else
{
setAcl(DbAccessControlListImpl.createLayeredAcl(null));
}
}
else
{
setAcl(DbAccessControlListImpl.createLayeredAcl(null));
}
}
}
/**
* Copy on write logic.
*
* @param lPath
* The path by which this was found.
*/
public AVMNode copy(Lookup lPath)
{
// LayeredFileNodes are always copied.
Lookup lookup = AVMRepository.GetInstance().lookup(-1, fIndirection, false);
if (lookup == null)
{
throw new AVMException("Unbacked layered file node.");
}
AVMNode indirect = lookup.getCurrentNode();
if (indirect.getType() != AVMNodeType.LAYERED_FILE && indirect.getType() != AVMNodeType.PLAIN_FILE)
{
throw new AVMException("Unbacked layered file node.");
}
DirectoryNode dir = lPath.getCurrentNodeDirectory();
Long parentAclId = null;
if ((dir != null) && (dir.getAcl() != null))
{
parentAclId = dir.getAcl().getId();
}
// TODO This doesn't look quite right.
PlainFileNodeImpl newMe = new PlainFileNodeImpl(lPath.getAVMStore(), getBasicAttributes(), getContentData(lPath), indirect.getProperties(), indirect.getAspects(), indirect
.getAcl(), getVersionID(), parentAclId, ACLCopyMode.COPY);
newMe.setAncestor(this);
return newMe;
}
/**
* Get the type of this node.
*
* @return The type.
*/
public int getType()
{
return AVMNodeType.LAYERED_FILE;
}
/**
* Get the underlying path.
*
* @param lookup
* The Lookup. (Unused here.)
* @return The underlying path.
*/
public String getUnderlying(Lookup lookup)
{
return fIndirection;
}
/**
* Get a diagnostic String representation.
*
* @param lPath
* The Lookup.
* @return A diagnostic String representation.
*/
public String toString(Lookup lPath)
{
return "[LF:" + getId() + ":" + fIndirection + "]";
}
/**
* Get the descriptor for this node.
*
* @param lPath
* The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
if (path.endsWith("/"))
{
path = path + name;
}
else
{
path = path + "/" + name;
}
return new AVMNodeDescriptor(path, name, AVMNodeType.LAYERED_FILE, attrs.getCreator(), attrs.getOwner(), attrs.getLastModifier(), attrs.getCreateDate(),
attrs.getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), getUnderlying(lPath), getUnderlyingVersion(lPath), false, -1, false, 0, -1);
}
/**
* Get the descriptor for this node.
*
* @param lPath
* The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
return new AVMNodeDescriptor(path, path.substring(path.lastIndexOf("/") + 1), AVMNodeType.LAYERED_FILE, attrs.getCreator(), attrs.getOwner(), attrs.getLastModifier(),
attrs.getCreateDate(), attrs.getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), getUnderlying(lPath), getUnderlyingVersion(lPath), false, -1,
false, 0, -1);
}
/**
* Get the descriptor for this node.
*
* @param parentPath
* The parent path.
* @param name
* The name this was looked up with.
* @param parentIndirection
* The parent indirection.
* @return The descriptor.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion)
{
BasicAttributes attrs = getBasicAttributes();
String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name;
return new AVMNodeDescriptor(path, name, AVMNodeType.LAYERED_FILE, attrs.getCreator(), attrs.getOwner(), attrs.getLastModifier(), attrs.getCreateDate(),
attrs.getModDate(), attrs.getAccessDate(), getId(), getGuid(), getVersionID(), fIndirection, fIndirectionVersion, false, -1, false, 0, -1);
}
/**
* Get the indirection.
*
* @return The indirection.
*/
public String getIndirection()
{
return fIndirection;
}
/**
* Set the indirection.
*
* @param indirection
*/
public void setIndirection(String indirection)
{
fIndirection = indirection;
}
/**
* Set the ContentData for this file.
*
* @param contentData
* The value to set.
*/
public void setContentData(ContentData contentData)
{
throw new AVMException("Should not be called.");
}
// TODO The lPath argument is unnecessary.
/**
* Get the ContentData for this file.
*
* @return The ContentData object for this file.
*/
public ContentData getContentData(Lookup lPath)
{
Lookup lookup = lPath.getAVMStore().getAVMRepository().lookup(getUnderlyingVersion(lPath), getIndirection(), false);
if (lookup == null)
{
throw new AVMException("Invalid target.");
}
AVMNode node = lookup.getCurrentNode();
if (!(node instanceof FileNode))
{
throw new AVMException("Invalid target.");
}
FileNode file = (FileNode) node;
return file.getContentData(lookup);
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.avm.Layered#getUnderlyingVersion(org.alfresco.repo.avm.Lookup)
*/
public int getUnderlyingVersion(Lookup lookup)
{
if (lookup.getVersion() == -1)
{
return -1;
}
return fIndirectionVersion;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.avm.LayeredFileNode#getIndirectionVersion()
*/
public Integer getIndirectionVersion()
{
return fIndirectionVersion;
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.avm.LayeredFileNode#setIndirectionVersion(int)
*/
public void setIndirectionVersion(Integer version)
{
if (version == null)
{
fIndirectionVersion = -1;
}
else
{
fIndirectionVersion = version;
}
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.avm.LayeredFileNode#copyLiterally(org.alfresco.repo.avm.Lookup)
*/
public LayeredFileNode copyLiterally(Lookup lookup)
{
// As far As I can tell this not used
DirectoryNode dir = lookup.getCurrentNodeDirectory();
Long parentAclId = null;
if ((dir != null) && (dir.getAcl() != null))
{
parentAclId = dir.getAcl().getId();
}
return new LayeredFileNodeImpl(this, lookup.getAVMStore(), parentAclId, ACLCopyMode.COPY);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,352 +1,349 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import java.util.LinkedList;
import java.util.List;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.transaction.TransactionService;
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import java.util.LinkedList;
import java.util.List;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.transaction.TransactionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
/**
* This is the background thread for reaping no longer referenced nodes
* in the AVM repository. These orphans arise from purge operations.
* @author britt
*/
public class OrphanReaper
{
public void execute()
{
synchronized (this)
{
if (fRunning)
{
return;
}
fRunning = true;
}
try
{
do
{
doBatch();
if (fDone)
{
return;
}
try
{
Thread.sleep(fActiveBaseSleep);
}
catch (InterruptedException e)
{
// Do nothing.
}
} while (fActive);
}
finally
{
synchronized (this)
{
fRunning = false;
}
}
}
private Log fgLogger = LogFactory.getLog(OrphanReaper.class);
/**
* The Transaction Service
*/
private TransactionService fTransactionService;
/**
* The Session Factory
*/
private SessionFactory fSessionFactory;
/**
* Active base sleep interval.
*/
private long fActiveBaseSleep;
/**
* Batch size.
*/
private int fBatchSize;
/**
* Whether we are currently active, ie have
* work queued up.
*/
private boolean fActive;
/**
* The maximum length of the queue.
*/
private int fQueueLength;
/**
* The linked list containing ids of nodes that are purgable.
*/
private LinkedList<Long> fPurgeQueue;
private boolean fDone = false;
private boolean fRunning = false;
/**
* Create one with default parameters.
*/
public OrphanReaper()
{
fActiveBaseSleep = 1000;
fBatchSize = 50;
fQueueLength = 1000;
fActive = false;
}
// Setters for configuration.
/**
* Set the active base sleep interval.
* @param interval The interval to set in ms.
*/
public void setActiveBaseSleep(long interval)
{
fActiveBaseSleep = interval;
}
/**
* Set the batch size.
* @param size The batch size to set.
*/
public void setBatchSize(int size)
{
fBatchSize = size;
}
/**
* Set the transaction service.
* @param transactionService The service.
*/
public void setTransactionService(TransactionService transactionService)
{
fTransactionService = transactionService;
}
/**
* Set the hibernate session factory. (For Spring.)
* @param sessionFactory
*/
public void setSessionFactory(SessionFactory sessionFactory)
{
fSessionFactory = sessionFactory;
}
/**
* Set the maximum size of the queue of purgeable nodes.
* @param queueLength The max length.
*/
public void setMaxQueueLength(int queueLength)
{
fQueueLength = queueLength;
}
/**
* Start things up after configuration is complete.
*/
// public void init()
// {
// fThread = new Thread(this);
// fThread.start();
// }
/**
* Shutdown the reaper. This needs to be called when
* the application shuts down.
*/
public void shutDown()
{
fDone = true;
}
/**
* Sit in a loop, periodically querying for orphans. When orphans
* are found, unhook them in bite sized batches.
*/
// public void run()
// {
// while (!fDone)
// {
// synchronized (this)
// {
// try
// {
// wait(fActive? fActiveBaseSleep : fInactiveBaseSleep);
// }
// catch (InterruptedException ie)
// {
// // Do nothing.
// }
// doBatch();
// }
// }
// }
/**
* This is really for debugging and testing. Allows another thread to
* mark the orphan reaper busy so that it can monitor for it's being done.
*/
public void activate()
{
fActive = true;
}
/**
* See if the reaper is actively reaping.
* @return Whether this is actively reaping.
*/
public boolean isActive()
{
return fActive;
}
/**
* Do a batch of cleanup work.
*/
public void doBatch()
{
class TxnWork implements RetryingTransactionCallback<Object>
{
public Object execute()
throws Exception
{
if (fPurgeQueue == null)
{
List<AVMNode> nodes = AVMDAOs.Instance().fAVMNodeDAO.getOrphans(fQueueLength);
if (nodes.size() == 0)
{
fActive = false;
return null;
}
fPurgeQueue = new LinkedList<Long>();
for (AVMNode node : nodes)
{
fPurgeQueue.add(node.getId());
}
}
fActive = true;
for (int i = 0; i < fBatchSize; i++)
{
if (fPurgeQueue.size() == 0)
{
fPurgeQueue = null;
return null;
}
AVMNode node = AVMDAOs.Instance().fAVMNodeDAO.getByID(fPurgeQueue.removeFirst());
// Save away the ancestor and merged from fields from this node.
HistoryLink hlink = AVMDAOs.Instance().fHistoryLinkDAO.getByDescendent(node);
AVMNode ancestor = null;
if (hlink != null)
{
ancestor = hlink.getAncestor();
AVMDAOs.Instance().fHistoryLinkDAO.delete(hlink);
}
MergeLink mlink = AVMDAOs.Instance().fMergeLinkDAO.getByTo(node);
AVMNode mergedFrom = null;
if (mlink != null)
{
mergedFrom = mlink.getMfrom();
AVMDAOs.Instance().fMergeLinkDAO.delete(mlink);
}
AVMDAOs.Instance().fAVMNodeDAO.flush();
// Get all the nodes that have this node as ancestor.
List<HistoryLink> links = AVMDAOs.Instance().fHistoryLinkDAO.getByAncestor(node);
for (HistoryLink link : links)
{
AVMNode desc = link.getDescendent();
desc.setAncestor(ancestor);
if (desc.getMergedFrom() == null)
{
desc.setMergedFrom(mergedFrom);
}
AVMDAOs.Instance().fHistoryLinkDAO.delete(link);
}
// Get all the nodes that have this node as mergedFrom
List<MergeLink> mlinks = AVMDAOs.Instance().fMergeLinkDAO.getByFrom(node);
for (MergeLink link : mlinks)
{
link.getMto().setMergedFrom(ancestor);
AVMDAOs.Instance().fMergeLinkDAO.delete(link);
}
// Get rid of all properties belonging to this node.
// AVMDAOs.Instance().fAVMNodePropertyDAO.deleteAll(node);
// Get rid of all aspects belonging to this node.
// AVMDAOs.Instance().fAVMAspectNameDAO.delete(node);
// Get rid of ACL.
DbAccessControlList acl = node.getAcl();
node.setAcl(null);
if (acl != null)
{
acl.deleteEntries();
(new HibernateTemplate(fSessionFactory)).delete(acl);
}
// Extra work for directories.
if (node.getType() == AVMNodeType.PLAIN_DIRECTORY ||
node.getType() == AVMNodeType.LAYERED_DIRECTORY)
{
// First get rid of all child entries for the node.
AVMDAOs.Instance().fChildEntryDAO.deleteByParent(node);
}
// This is not on, since content urls can be shared.
// else if (node.getType() == AVMNodeType.PLAIN_FILE)
// {
// PlainFileNode file = (PlainFileNode)node;
// String url = file.getContentData(null).getContentUrl();
// if (url != null)
// {
// RawServices.Instance().getContentStore().delete(url);
// }
// }
AVMDAOs.Instance().fAVMNodeDAO.delete(node);
}
return null;
}
}
try
{
fTransactionService.getRetryingTransactionHelper().doInTransaction(new TxnWork());
}
catch (Exception e)
{
fgLogger.error("Garbage collector error", e);
}
}
}
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
/**
* This is the background thread for reaping no longer referenced nodes
* in the AVM repository. These orphans arise from purge operations.
* @author britt
*/
public class OrphanReaper
{
public void execute()
{
synchronized (this)
{
if (fRunning)
{
return;
}
fRunning = true;
}
try
{
do
{
doBatch();
if (fDone)
{
return;
}
try
{
Thread.sleep(fActiveBaseSleep);
}
catch (InterruptedException e)
{
// Do nothing.
}
} while (fActive);
}
finally
{
synchronized (this)
{
fRunning = false;
}
}
}
private Log fgLogger = LogFactory.getLog(OrphanReaper.class);
/**
* The Transaction Service
*/
private TransactionService fTransactionService;
/**
* The Session Factory
*/
private SessionFactory fSessionFactory;
/**
* Active base sleep interval.
*/
private long fActiveBaseSleep;
/**
* Batch size.
*/
private int fBatchSize;
/**
* Whether we are currently active, ie have
* work queued up.
*/
private boolean fActive;
/**
* The maximum length of the queue.
*/
private int fQueueLength;
/**
* The linked list containing ids of nodes that are purgable.
*/
private LinkedList<Long> fPurgeQueue;
private boolean fDone = false;
private boolean fRunning = false;
/**
* Create one with default parameters.
*/
public OrphanReaper()
{
fActiveBaseSleep = 1000;
fBatchSize = 50;
fQueueLength = 1000;
fActive = false;
}
// Setters for configuration.
/**
* Set the active base sleep interval.
* @param interval The interval to set in ms.
*/
public void setActiveBaseSleep(long interval)
{
fActiveBaseSleep = interval;
}
/**
* Set the batch size.
* @param size The batch size to set.
*/
public void setBatchSize(int size)
{
fBatchSize = size;
}
/**
* Set the transaction service.
* @param transactionService The service.
*/
public void setTransactionService(TransactionService transactionService)
{
fTransactionService = transactionService;
}
/**
* Set the hibernate session factory. (For Spring.)
* @param sessionFactory
*/
public void setSessionFactory(SessionFactory sessionFactory)
{
fSessionFactory = sessionFactory;
}
/**
* Set the maximum size of the queue of purgeable nodes.
* @param queueLength The max length.
*/
public void setMaxQueueLength(int queueLength)
{
fQueueLength = queueLength;
}
/**
* Start things up after configuration is complete.
*/
// public void init()
// {
// fThread = new Thread(this);
// fThread.start();
// }
/**
* Shutdown the reaper. This needs to be called when
* the application shuts down.
*/
public void shutDown()
{
fDone = true;
}
/**
* Sit in a loop, periodically querying for orphans. When orphans
* are found, unhook them in bite sized batches.
*/
// public void run()
// {
// while (!fDone)
// {
// synchronized (this)
// {
// try
// {
// wait(fActive? fActiveBaseSleep : fInactiveBaseSleep);
// }
// catch (InterruptedException ie)
// {
// // Do nothing.
// }
// doBatch();
// }
// }
// }
/**
* This is really for debugging and testing. Allows another thread to
* mark the orphan reaper busy so that it can monitor for it's being done.
*/
public void activate()
{
fActive = true;
}
/**
* See if the reaper is actively reaping.
* @return Whether this is actively reaping.
*/
public boolean isActive()
{
return fActive;
}
/**
* Do a batch of cleanup work.
*/
public void doBatch()
{
class TxnWork implements RetryingTransactionCallback<Object>
{
public Object execute()
throws Exception
{
if (fPurgeQueue == null)
{
List<AVMNode> nodes = AVMDAOs.Instance().fAVMNodeDAO.getOrphans(fQueueLength);
if (nodes.size() == 0)
{
fActive = false;
return null;
}
fPurgeQueue = new LinkedList<Long>();
for (AVMNode node : nodes)
{
fPurgeQueue.add(node.getId());
}
}
fActive = true;
for (int i = 0; i < fBatchSize; i++)
{
if (fPurgeQueue.size() == 0)
{
fPurgeQueue = null;
return null;
}
AVMNode node = AVMDAOs.Instance().fAVMNodeDAO.getByID(fPurgeQueue.removeFirst());
// Save away the ancestor and merged from fields from this node.
HistoryLink hlink = AVMDAOs.Instance().fHistoryLinkDAO.getByDescendent(node);
AVMNode ancestor = null;
if (hlink != null)
{
ancestor = hlink.getAncestor();
AVMDAOs.Instance().fHistoryLinkDAO.delete(hlink);
}
MergeLink mlink = AVMDAOs.Instance().fMergeLinkDAO.getByTo(node);
AVMNode mergedFrom = null;
if (mlink != null)
{
mergedFrom = mlink.getMfrom();
AVMDAOs.Instance().fMergeLinkDAO.delete(mlink);
}
AVMDAOs.Instance().fAVMNodeDAO.flush();
// Get all the nodes that have this node as ancestor.
List<HistoryLink> links = AVMDAOs.Instance().fHistoryLinkDAO.getByAncestor(node);
for (HistoryLink link : links)
{
AVMNode desc = link.getDescendent();
desc.setAncestor(ancestor);
if (desc.getMergedFrom() == null)
{
desc.setMergedFrom(mergedFrom);
}
AVMDAOs.Instance().fHistoryLinkDAO.delete(link);
}
// Get all the nodes that have this node as mergedFrom
List<MergeLink> mlinks = AVMDAOs.Instance().fMergeLinkDAO.getByFrom(node);
for (MergeLink link : mlinks)
{
link.getMto().setMergedFrom(ancestor);
AVMDAOs.Instance().fMergeLinkDAO.delete(link);
}
// Get rid of all properties belonging to this node.
// AVMDAOs.Instance().fAVMNodePropertyDAO.deleteAll(node);
// Get rid of all aspects belonging to this node.
// AVMDAOs.Instance().fAVMAspectNameDAO.delete(node);
// Get rid of ACL.
DbAccessControlList acl = node.getAcl();
node.setAcl(null);
// Unused acls will be garbage collected
// Many acls will be shared
// Extra work for directories.
if (node.getType() == AVMNodeType.PLAIN_DIRECTORY ||
node.getType() == AVMNodeType.LAYERED_DIRECTORY)
{
// First get rid of all child entries for the node.
AVMDAOs.Instance().fChildEntryDAO.deleteByParent(node);
}
// This is not on, since content urls can be shared.
// else if (node.getType() == AVMNodeType.PLAIN_FILE)
// {
// PlainFileNode file = (PlainFileNode)node;
// String url = file.getContentData(null).getContentUrl();
// if (url != null)
// {
// RawServices.Instance().getContentStore().delete(url);
// }
// }
AVMDAOs.Instance().fAVMNodeDAO.delete(node);
}
return null;
}
}
try
{
fTransactionService.getRetryingTransactionHelper().doInTransaction(new TxnWork());
}
catch (Exception e)
{
fgLogger.error("Garbage collector error", e);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,391 +1,398 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.avm.util.RawServices;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.QName;
/**
* A plain old file. Contains a Content object.
* @author britt
*/
class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
{
static final long serialVersionUID = 8720376837929735294L;
/**
* The Content URL.
*/
private String fContentURL;
/**
* The Mime type.
*/
private String fMimeType;
/**
* The character encoding.
*/
private String fEncoding;
/**
* The length of the file.
*/
private long fLength;
/**
* Default constructor.
*/
protected PlainFileNodeImpl()
{
}
/**
* Make one from just an AVMStore.
* This is the constructor used when a brand new plain file is being made.
* @param store An AVMStore.
*/
public PlainFileNodeImpl(AVMStore store)
{
super(store.getAVMRepository().issueID(), store);
setVersionID(1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
}
/**
* Copy on write constructor.
* @param other The node we are being copied from.
* @param store The AVMStore.
*/
public PlainFileNodeImpl(PlainFileNode other,
AVMStore store)
{
super(store.getAVMRepository().issueID(), store);
// The null is OK because the Lookup argument is only use by
// layered files.
setContentData(other.getContentData(null));
setVersionID(other.getVersionID() + 1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
copyProperties(other);
copyAspects(other);
copyACLs(other);
}
// TODO Is there a reason for passing all these parameters instead
// of just the LayeredFileNode?
/**
* Construct a new one. This is called when a LayeredFileNode
* is copied.
* @param store
* @param attrs
* @param content
*/
public PlainFileNodeImpl(AVMStore store,
BasicAttributes attrs,
ContentData content,
Map<QName, PropertyValue> props,
Set<QName> aspects,
DbAccessControlList acl,
int versionID)
{
super(store.getAVMRepository().issueID(), store);
setContentData(content);
setBasicAttributes(attrs);
setVersionID(versionID + 1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
addProperties(props);
setAspects(new HashSet<QName>(aspects));
if (acl != null)
{
setAcl(acl.getCopy());
}
}
/**
* Copy on write logic.
* @param lPath The lookup path.
*/
public AVMNode copy(Lookup lPath)
{
PlainFileNodeImpl newMe = new PlainFileNodeImpl(this, lPath.getAVMStore());
newMe.setAncestor(this);
return newMe;
}
/**
* Get the type of this node.
* @return The type.
*/
public int getType()
{
return AVMNodeType.PLAIN_FILE;
}
/**
* Get a diagnostic string representation.
* @param lPath The Lookup.
* @return A diagnostic String representation.
*/
// @Override
public String toString(Lookup lPath)
{
return "[PF:" + getId() + "]";
}
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
if (path.endsWith("/"))
{
path = path + name;
}
else
{
path = path + "/" + name;
}
return new AVMNodeDescriptor(path,
name,
AVMNodeType.PLAIN_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
getLength(),
-1);
}
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
return new AVMNodeDescriptor(path,
path.substring(path.lastIndexOf("/") + 1),
AVMNodeType.PLAIN_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
getFileLength(),
-1);
}
/**
* Get the descriptor for this.
* @param parentPath The parent path.
* @param name The name this was looked up with.
* @param parentIndirection The parent indirection.
* @return The descriptor for this.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion)
{
BasicAttributes attrs = getBasicAttributes();
String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name;
return new AVMNodeDescriptor(path,
name,
AVMNodeType.PLAIN_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
getFileLength(),
-1);
}
/**
* Get the Content URL.
* @return The content URL.
*/
public String getContentURL()
{
return fContentURL;
}
/**
* Set the Content URL.
* @param contentURL
*/
protected void setContentURL(String contentURL)
{
fContentURL = contentURL;
}
/**
* Get the character encoding.
* @return The encoding.
*/
public String getEncoding()
{
return fEncoding;
}
/**
* Set the character encoding.
* @param encoding The encoding to set.
*/
public void setEncoding(String encoding)
{
fEncoding = encoding;
}
/**
* Get the file length.
* @return The file length or null if unknown.
*/
public long getLength()
{
return fLength;
}
/**
* Get the actual file length.
* @return The actual file length;
*/
private long getFileLength()
{
if (fContentURL == null)
{
return 0L;
}
ContentReader reader = RawServices.Instance().getContentStore().getReader(fContentURL);
return reader.getSize();
}
/**
* Set the file length.
* @param length The length of the file.
*/
protected void setLength(long length)
{
fLength = length;
}
/**
* Get the mime type of the content.
* @return The Mime Type of the content.
*/
public String getMimeType()
{
return fMimeType;
}
/**
* Set the Mime Type of the content.
* @param mimeType The Mime Type to set.
*/
public void setMimeType(String mimeType)
{
fMimeType = mimeType;
}
/**
* Set the ContentData for this file.
* @param contentData The value to set.
*/
public void setContentData(ContentData contentData)
{
fContentURL = contentData.getContentUrl();
fMimeType = contentData.getMimetype();
if (fMimeType == null)
{
throw new AVMException("Null mime type.");
}
fEncoding = contentData.getEncoding();
fLength = contentData.getSize();
}
/**
* Get the ContentData for this file.
* @param lPath The lookup path used to get here. Unused here.
* @return The ContentData object for this file.
*/
public ContentData getContentData(Lookup lPath)
{
return getContentData();
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.PlainFileNode#getContentData()
*/
public ContentData getContentData()
{
return new ContentData(fContentURL, fMimeType, fLength, fEncoding);
}
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.avm;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.avm.util.RawServices;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.QName;
/**
* A plain old file. Contains a Content object.
* @author britt
*/
class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
{
static final long serialVersionUID = 8720376837929735294L;
/**
* The Content URL.
*/
private String fContentURL;
/**
* The Mime type.
*/
private String fMimeType;
/**
* The character encoding.
*/
private String fEncoding;
/**
* The length of the file.
*/
private long fLength;
/**
* Default constructor.
*/
protected PlainFileNodeImpl()
{
}
/**
* Make one from just an AVMStore.
* This is the constructor used when a brand new plain file is being made.
* @param store An AVMStore.
*/
public PlainFileNodeImpl(AVMStore store)
{
super(store.getAVMRepository().issueID(), store);
setVersionID(1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
}
/**
* Copy on write constructor.
* @param other The node we are being copied from.
* @param store The AVMStore.
*/
public PlainFileNodeImpl(PlainFileNode other,
AVMStore store, Long parentAcl, ACLCopyMode mode)
{
super(store.getAVMRepository().issueID(), store);
// The null is OK because the Lookup argument is only use by
// layered files.
setContentData(other.getContentData(null));
setVersionID(other.getVersionID() + 1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
copyProperties(other);
copyAspects(other);
copyACLs(other, parentAcl, mode);
}
// TODO Is there a reason for passing all these parameters instead
// of just the LayeredFileNode?
/**
* Construct a new one. This is called when a LayeredFileNode
* is copied.
* @param store
* @param attrs
* @param content
*/
public PlainFileNodeImpl(AVMStore store,
BasicAttributes attrs,
ContentData content,
Map<QName, PropertyValue> props,
Set<QName> aspects,
DbAccessControlList acl,
int versionID, Long parentAcl, ACLCopyMode mode)
{
super(store.getAVMRepository().issueID(), store);
setContentData(content);
setBasicAttributes(attrs);
setVersionID(versionID + 1);
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
addProperties(props);
setAspects(new HashSet<QName>(aspects));
if (acl != null)
{
setAcl(acl.getCopy(parentAcl, mode));
}
}
/**
* Copy on write logic.
* @param lPath The lookup path.
*/
public AVMNode copy(Lookup lPath)
{
DirectoryNode dir = lPath.getCurrentNodeDirectory();
Long parentAclId = null;
if((dir != null) && (dir.getAcl() != null))
{
parentAclId = dir.getAcl().getId();
}
PlainFileNodeImpl newMe = new PlainFileNodeImpl(this, lPath.getAVMStore(), parentAclId, ACLCopyMode.COW);
newMe.setAncestor(this);
return newMe;
}
/**
* Get the type of this node.
* @return The type.
*/
public int getType()
{
return AVMNodeType.PLAIN_FILE;
}
/**
* Get a diagnostic string representation.
* @param lPath The Lookup.
* @return A diagnostic String representation.
*/
// @Override
public String toString(Lookup lPath)
{
return "[PF:" + getId() + "]";
}
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath, String name)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
if (path.endsWith("/"))
{
path = path + name;
}
else
{
path = path + "/" + name;
}
return new AVMNodeDescriptor(path,
name,
AVMNodeType.PLAIN_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
getLength(),
-1);
}
/**
* Get the descriptor for this node.
* @param lPath The Lookup.
* @return A descriptor.
*/
public AVMNodeDescriptor getDescriptor(Lookup lPath)
{
BasicAttributes attrs = getBasicAttributes();
String path = lPath.getRepresentedPath();
return new AVMNodeDescriptor(path,
path.substring(path.lastIndexOf("/") + 1),
AVMNodeType.PLAIN_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
getFileLength(),
-1);
}
/**
* Get the descriptor for this.
* @param parentPath The parent path.
* @param name The name this was looked up with.
* @param parentIndirection The parent indirection.
* @return The descriptor for this.
*/
public AVMNodeDescriptor getDescriptor(String parentPath, String name, String parentIndirection, int parentIndirectionVersion)
{
BasicAttributes attrs = getBasicAttributes();
String path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name;
return new AVMNodeDescriptor(path,
name,
AVMNodeType.PLAIN_FILE,
attrs.getCreator(),
attrs.getOwner(),
attrs.getLastModifier(),
attrs.getCreateDate(),
attrs.getModDate(),
attrs.getAccessDate(),
getId(),
getGuid(),
getVersionID(),
null,
-1,
false,
-1,
false,
getFileLength(),
-1);
}
/**
* Get the Content URL.
* @return The content URL.
*/
public String getContentURL()
{
return fContentURL;
}
/**
* Set the Content URL.
* @param contentURL
*/
protected void setContentURL(String contentURL)
{
fContentURL = contentURL;
}
/**
* Get the character encoding.
* @return The encoding.
*/
public String getEncoding()
{
return fEncoding;
}
/**
* Set the character encoding.
* @param encoding The encoding to set.
*/
public void setEncoding(String encoding)
{
fEncoding = encoding;
}
/**
* Get the file length.
* @return The file length or null if unknown.
*/
public long getLength()
{
return fLength;
}
/**
* Get the actual file length.
* @return The actual file length;
*/
private long getFileLength()
{
if (fContentURL == null)
{
return 0L;
}
ContentReader reader = RawServices.Instance().getContentStore().getReader(fContentURL);
return reader.getSize();
}
/**
* Set the file length.
* @param length The length of the file.
*/
protected void setLength(long length)
{
fLength = length;
}
/**
* Get the mime type of the content.
* @return The Mime Type of the content.
*/
public String getMimeType()
{
return fMimeType;
}
/**
* Set the Mime Type of the content.
* @param mimeType The Mime Type to set.
*/
public void setMimeType(String mimeType)
{
fMimeType = mimeType;
}
/**
* Set the ContentData for this file.
* @param contentData The value to set.
*/
public void setContentData(ContentData contentData)
{
fContentURL = contentData.getContentUrl();
fMimeType = contentData.getMimetype();
if (fMimeType == null)
{
throw new AVMException("Null mime type.");
}
fEncoding = contentData.getEncoding();
fLength = contentData.getSize();
}
/**
* Get the ContentData for this file.
* @param lPath The lookup path used to get here. Unused here.
* @return The ContentData object for this file.
*/
public ContentData getContentData(Lookup lPath)
{
return getContentData();
}
/* (non-Javadoc)
* @see org.alfresco.repo.avm.PlainFileNode#getContentData()
*/
public ContentData getContentData()
{
return new ContentData(fContentURL, fMimeType, fLength, fEncoding);
}
}

View File

@@ -44,7 +44,7 @@
<property name="isRoot" column="is_root" type="boolean"/>
<many-to-one name="storeNew" class="AVMStoreImpl" column="store_new_id" foreign-key="fk_avm_n_store"/>
<!-- ACL -->
<many-to-one name="acl" column="acl_id" foreign-key="fk_avm_n_acl"
<many-to-one name="acl" column="acl_id" foreign-key="fk_avm_n_acl" cascade="none"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"/>
<set name="aspects" fetch="join" lazy="false" table="avm_aspects_new" cascade="all" optimistic-lock="true">
<cache usage="read-write"/>

View File

@@ -1,50 +1,87 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.domain;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This abstracts the reading and writing of ACLs on nodes
* from particular node implementations.
* @author britt
*/
public interface AccessControlListDAO
{
/**
* Get the ACL from a node.
* @param nodeRef The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef);
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl);
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.domain;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.security.permissions.ACLType;
import org.alfresco.repo.security.permissions.impl.AclChange;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This abstracts the reading and writing of ACLs on nodes from particular node implementations.
*
* @author britt
*/
public interface AccessControlListDAO
{
/**
* Get the ACL from a node.
*
* @param nodeRef
* The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef);
/**
* Set the ACL on a node.
*
* @param nodeRef
* The reference to the node.
* @param acl
* The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl);
/**
* Update any associated ACLs
*
* @param startingPoint
* @param chnages
*/
public void updateChangedAcls(NodeRef startingPoint, List<AclChange> changes);
/**
* Update inheritance
*
* @param parent
* @param mergeFrom
* @param previousId
* @return
*/
public List<AclChange> setInheritanceForChildren(NodeRef parent, Long mergeFrom);
public Long getIndirectAcl(NodeRef nodeRef);
public Long getInheritedAcl(NodeRef nodeRef);
public void forceCopy(NodeRef nodeRef);
public Map<ACLType, Integer> patchAcls();
}

View File

@@ -24,6 +24,9 @@
*/
package org.alfresco.repo.domain;
import org.alfresco.repo.security.permissions.ACEType;
import org.alfresco.repo.security.permissions.AccessControlEntry;
/**
@@ -44,16 +47,6 @@ public interface DbAccessControlEntry
*/
public Long getVersion();
/**
* @return Returns the containing access control list
*/
public DbAccessControlList getAccessControlList();
/**
* @param acl the accession control list to which entry belongs
*/
public void setAccessControlList(DbAccessControlList acl);
/**
* @return Returns the permission to which this entry applies
*/
@@ -86,6 +79,30 @@ public interface DbAccessControlEntry
*/
public void setAllowed(boolean allowed);
/**
* Get the ACE type
* @return
*/
public ACEType getAceType();
/**
* Set the ACEType
* @param type
*/
public void setAceType(ACEType type);
/**
* Get the ACE context - may be null and may well mostly be null
* @return
*/
public DbAccessControlEntryContext getContext();
/**
* Set the ACE context
* @param context
*/
public void setContext(DbAccessControlEntryContext context);
/**
* Helper method to delete the instance and make sure that all
* inverse associations are properly maintained.

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain;
/**
* Context for permission evaluation
*
* @author andyh
*
*/
public interface DbAccessControlEntryContext
{
/**
* Get the id for this object
* @return
*/
public Long getId();
/**
* Get the version for this object
* @return
*/
public Long getVersion();
/**
* Get the class context.
*
* This is a space separated list of QNames
* with an optional + or minus
*
* +QName => Must be of this type or have the aspect
* -Qname => Must not be of this type or have the aspect
* +QName +QName +QName => Must have all of these types
* -QName -Qname => Must not have any of these types
* QName QName QName => Must have one of the types
* QName => requires exact type match
* QName~ => requires a match on the type or subtype
*
* Supports () for grouping
*
* @return
*/
public String getClassContext();
/**
* Set the class context - as described above
*
* @param classContext
*/
public void setClassContext(String classContext);
/**
* Get the property context
*
* QName QName Qname => property types to which it applies
*
* @return
*/
public String getPropertyContext();
/**
* Get the property context strin as a above
* @param propertyContext
*/
public void setPropertyContext(String propertyContext);
/**
* Get the key value pair context
*
* Serialized Map
*
* @return
*/
public String getKvpContext();
/**
* Get the key value pair context
* @param kvpContext
*/
public void setKvpContext(String kvpContext);
}

View File

@@ -24,9 +24,8 @@
*/
package org.alfresco.repo.domain;
import java.util.Set;
import org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.repo.security.permissions.ACLType;
/**
@@ -36,61 +35,141 @@ import org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl;
*/
public interface DbAccessControlList
{
/**
* Get the long key
* @return
*/
public Long getId();
/**
* Get the ACL ID
* @return
*/
public String getAclId();
/**
* Get the ACL version
* @return
*/
public long getAclVersion();
/**
* Is this the latest version of the acl identified by the acl id string?
* @return
*/
public boolean isLatest();
/**
* @return Returns the version number for optimistic locking
*/
public Long getVersion();
/**
*
* @return Returns the access control entries for this access control list
*/
public Set<DbAccessControlEntry> getEntries();
/**
* Get inheritance behaviour
* @return Returns the inheritance status of this list
*/
public boolean getInherits();
/**
* Get the ACL from which this one inherits
*
* @return
*/
public Long getInheritsFrom();
/**
* Get the type for this ACL
*
* @return
*/
public ACLType getAclType();
/**
* Get the ACL inherited from nodes which have this ACL
*
* @return
*/
public Long getInheritedAclId();
/**
* Is this ACL versioned - if not there will be no old versions of the ACL
* and the long id will remain unchanged.
*
* If an acl is versioned it can not be updated - a new copy has to be created,
*
* @return
*/
public boolean isVersioned();
/**
* Set the string ACL ID (not the auto generated long)
* @param id
*/
public void setAclId(String id);
/**
* Set the ACL version (not the optimistic version used by hibernate)
* @param version
*/
public void setAclVersion(long version);
/**
* Set if this ACL is the latest version of the ACL as identified by getAclId()
* @param isLatest
*/
public void setLatest(boolean isLatest);
/**
* Set inheritance behaviour
* @param inherits true to set the permissions to inherit
*/
public void setInherits(boolean inherits);
public int deleteEntriesForAuthority(String authorityKey);
public int deleteEntriesForPermission(DbPermissionKey permissionKey);
public int deleteEntry(String authorityKey, DbPermissionKey permissionKey);
/**
* Set the ACL from which this one inherits
* @param id
*/
public void setInheritsFrom(Long id);
/**
* Delete the entries related to this access control list
*
* @return Returns the number of entries deleted
* Set the ACL Type
* @param type
*/
public int deleteEntries();
public DbAccessControlEntry getEntry(String authorityKey, DbPermissionKey permissionKey);
public void setAclType(ACLType type);
/**
* Factory method to create an entry and wire it up.
* Note that the returned value may still be transient. Saving it should be fine, but
* is not required.
*
* @param permission the mandatory permission association with this entry
* @param authority the mandatory authority. Must not be transient.
* @param allowed allowed or disallowed. Must not be transient.
* @return Returns the new entry
* Set the ACL that should be set when inheriting from this one.
* This ACL does not contain any object specific settings.
* @param acl
*/
public DbAccessControlEntryImpl newEntry(DbPermission permission, DbAuthority authority, boolean allowed);
public void setInheritedAclId(Long acl);
/**
* Make a copy of this ACL (persistently)
* @return The copy.
* Set if this ACL is versioned on write
* @param isVersioned
*/
public DbAccessControlList getCopy();
public void setVersioned(boolean isVersioned);
/**
* Set the change set
* @param aclChangeSet
*/
public void setAclChangeSet(DbAccessControlListChangeSet aclChangeSet);
/**
* Get the change set
* @return
*/
public DbAccessControlListChangeSet getAclChangeSet();
// Stuff to fix up in AVM
public DbAccessControlList getCopy(Long parent, ACLCopyMode node);
public void setRequiresVersion(boolean requiresVersion);
public boolean getRequiresVersion();
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain;
public interface DbAccessControlListChangeSet
{
/**
* Get the long key
* @return
*/
public Long getId();
/**
* @return Returns the version number for optimistic locking
*/
public Long getVersion();
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain;
/**
* Realtes an ACE to an ACL with a position
*
* @author andyh
*
*/
public interface DbAccessControlListMember
{
/**
* Get the ID for the membership entry
* @return - the id
*/
public Long getId();
/**
* Get the version for this membership entry
* @return - the version
*/
public Long getVersion();
/**
* Get the ACL to which the ACE belongs.
* @return - the acl id
*/
public DbAccessControlList getAccessControlList();
/**
* Get the ACE included in the ACL
* @return - the ace id
*/
public DbAccessControlEntry getAccessControlEntry();
/**
* Get the position group for this member in the ACL
*
* 0 - implies the ACE is om the object
* >0 - that it is inhertied in some way
*
* The lower values are checked first so take precidence.
*
* @return - the position of the ace in the acl
*/
public int getPosition();
/**
* Set the ACL
* @param acl
*/
public void setAccessControlList(DbAccessControlList acl);
/**
* Set the ACE
* @param ace
*/
public void setAccessControlEntry(DbAccessControlEntry ace);
/**
* Set the position for the ACL-ACE relationship
* @param position
*/
public void setPosition(int position);
}

View File

@@ -25,7 +25,6 @@
package org.alfresco.repo.domain;
import java.io.Serializable;
import java.util.Set;
/**
* The interface against which recipients of permission are persisted
@@ -33,30 +32,25 @@ import java.util.Set;
*/
public interface DbAuthority extends Serializable
{
/**
* Get the object id
* @return
*/
public Long getId();
/**
* @return Returns the version number for optimistic locking
*/
public Long getVersion();
/**
* @return Returns the recipient
* @return Returns the authority
*/
public String getRecipient();
public String getAuthority();
/**
* @param recipient the authority recipient
* @param the authority
*/
public void setRecipient(String recipient);
/**
* @return Returns the external keys associated with this authority
*/
public Set<String> getExternalKeys();
/**
* Delete the access control entries related to this authority
*
* @return Returns the number of entries deleted
*/
public int deleteEntries();
public void setAuthority(String authority);
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain;
/**
* Hibernate persistence for authority aliases
*
* @author andyh
*
*/
public interface DbAuthorityAlias
{
/**
* Get the object id.
* @return
*/
public Long getId();
/**
* Get the version used for optimistic locking
* @return
*/
public Long getVersion();
/**
* Get the authority for which this is an alias
* @return
*/
public DbAuthority getAuthority();
/**
* Get the alias for the authority
* @return
*/
public DbAuthority getAlias();
/**
* Set the authority
* @param authority
*/
public void setAuthority(DbAuthority authority);
/**
* Set the alias
* @param alias
*/
public void setAlias(DbAuthority alias);
}

View File

@@ -1,103 +1,839 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.domain.hibernate;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.avm.AVMRepository;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.Pair;
/**
* The AVM implementation for getting and setting ACLs.
* @author britt
*/
public class AVMAccessControlListDAO implements AccessControlListDAO
{
/**
* Reference to the AVM Repository instance.
*/
private AVMRepository fAVMRepository;
/**
* Default constructory.
*/
public AVMAccessControlListDAO()
{
}
public void setAvmRepository(AVMRepository repository)
{
fAVMRepository = repository;
}
/**
* Get the ACL from a node.
* @param nodeRef The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = avmVersionPath.getFirst();
String path = avmVersionPath.getSecond();
try
{
return fAVMRepository.getACL(version, path);
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = avmVersionPath.getFirst();
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", nodeRef);
}
String path = avmVersionPath.getSecond();
try
{
fAVMRepository.setACL(path, acl);
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.domain.hibernate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.avm.AVMRepository;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.ACLType;
import org.alfresco.repo.security.permissions.AccessControlEntry;
import org.alfresco.repo.security.permissions.AccessControlList;
import org.alfresco.repo.security.permissions.SimpleAccessControlListProperties;
import org.alfresco.repo.security.permissions.impl.AclChange;
import org.alfresco.repo.security.permissions.impl.AclDaoComponent;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.Pair;
/**
* The AVM implementation for getting and setting ACLs.
*
* @author britt
*/
public class AVMAccessControlListDAO implements AccessControlListDAO
{
/**
* Reference to the AVM Repository instance.
*/
private AVMRepository fAVMRepository;
private AVMService fAVMService;
private AclDaoComponent aclDaoComponent;
/**
* Default constructory.
*/
public AVMAccessControlListDAO()
{
}
public void setAvmRepository(AVMRepository repository)
{
fAVMRepository = repository;
}
public void setAvmService(AVMService avmService)
{
fAVMService = avmService;
}
public void setAclDaoComponent(AclDaoComponent aclDaoComponent)
{
this.aclDaoComponent = aclDaoComponent;
}
public Long getIndirectAcl(NodeRef nodeRef)
{
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = avmVersionPath.getFirst();
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", nodeRef);
}
String path = avmVersionPath.getSecond();
try
{
AVMNodeDescriptor descriptor = fAVMService.lookup(version, path);
if (descriptor == null)
{
return null;
}
if (descriptor.isPrimary())
{
DbAccessControlList acl = getAclAsSystem(descriptor.getIndirectionVersion(), descriptor.getIndirection());
if (acl == null)
{
return null;
}
else
{
return acl.getId();
}
}
else
{
DbAccessControlList acl = getAclAsSystem(version, path);
if (acl == null)
{
return null;
}
else
{
return acl.getId();
}
}
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
public Long getInheritedAcl(NodeRef nodeRef)
{
// TODO OK, for now we'll simply return the single parent that corresponds
// to the path stuffed in the NodeRef.
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
String path = avmVersionPath.getSecond();
List<ChildAssociationRef> result = new ArrayList<ChildAssociationRef>();
String[] splitPath = AVMNodeConverter.SplitBase(path);
if (splitPath[0] == null)
{
return null;
}
DbAccessControlList acl = getAclAsSystem(avmVersionPath.getFirst(), splitPath[0]);
if (acl == null)
{
return null;
}
else
{
return acl.getId();
}
}
/**
* Get the ACL from a node.
*
* @param nodeRef
* The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = avmVersionPath.getFirst();
String path = avmVersionPath.getSecond();
try
{
return getAclAsSystem(version, path);
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
/**
* Set the ACL on a node.
*
* @param nodeRef
* The reference to the node.
* @param acl
* The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = avmVersionPath.getFirst();
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", nodeRef);
}
String path = avmVersionPath.getSecond();
try
{
setAclAsSystem(path, acl);
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
public void updateChangedAcls(NodeRef startingPoint, List<AclChange> changes)
{
Long after = null;
for (AclChange change : changes)
{
if (change.getBefore() == null)
{
after = change.getAfter();
}
else if (change.getTypeBefore() != change.getTypeAfter())
{
after = change.getAfter();
}
}
Long inherited = null;
if (after != null)
{
inherited = aclDaoComponent.getInheritedAccessControlList(after);
}
updateChangedAclsImpl(startingPoint, changes, SetMode.ALL, inherited, after);
}
private void updateChangedAclsImpl(NodeRef startingPoint, List<AclChange> changes, SetMode mode, Long inherited, Long setAcl)
{
HashMap<Long, Long> changeMap = new HashMap<Long, Long>();
HashSet<Long> unchangedSet = new HashSet<Long>();
for (AclChange change : changes)
{
if (change.getBefore() == null)
{
// null is treated using the inherited acl
}
else if (!change.getBefore().equals(change.getAfter()))
{
changeMap.put(change.getBefore(), change.getAfter());
}
else
{
unchangedSet.add(change.getBefore());
}
}
unchangedSet.add(inherited);
unchangedSet.add(setAcl);
if (inherited != null)
{
updateReferencingLayeredAcls(startingPoint, inherited);
}
updateInheritedChangedAcls(startingPoint, changeMap, unchangedSet, inherited, mode);
updateLayeredAclsChangedByInheritance(changes, changeMap, unchangedSet);
}
public void forceCopy(NodeRef nodeRef)
{
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = avmVersionPath.getFirst();
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", nodeRef);
}
String path = avmVersionPath.getSecond();
try
{
fAVMRepository.forceCopy(path);
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
private void updateReferencingLayeredAcls(NodeRef node, Long inherited)
{
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(node);
int version = avmVersionPath.getFirst();
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", node);
}
String path = avmVersionPath.getSecond();
try
{
AVMNodeDescriptor descriptor = fAVMService.lookup(version, path);
if (descriptor == null)
{
return;
}
else
{
List<Pair<Integer, String>> paths = fAVMService.getHeadPaths(descriptor);
for (Pair<Integer, String> current : paths)
{
List<Long> avmNodeIds = aclDaoComponent.getAvmNodesByIndirection(current.getSecond());
for (Long id : avmNodeIds)
{
// need to fix up inheritance as is has changed
AVMNodeDescriptor layerDesc = new AVMNodeDescriptor(null, null, 0, null, null, null, 0, 0, 0, id, null, 0, null, 0, false, 0, false, 0, 0);
List<Pair<Integer, String>> layerPaths = fAVMRepository.getHeadPaths(layerDesc);
// Update all locations with the updated ACL
for (Pair<Integer, String> layerPath : layerPaths)
{
AVMNodeDescriptor test = fAVMService.lookup(-1, layerPath.getSecond());
if (test.isPrimary())
{
DbAccessControlList target = getAclAsSystem(-1, layerPath.getSecond());
if (target != null)
{
if (target.getAclType() == ACLType.LAYERED)
{
fAVMService.forceCopy(layerPath.getSecond());
List<AclChange> layeredChanges = aclDaoComponent.mergeInheritedAccessControlList(inherited, target.getId());
NodeRef layeredNode = AVMNodeConverter.ToNodeRef(-1, layerPath.getSecond());
for (AclChange change : layeredChanges)
{
if (change.getBefore().equals(target.getId()))
{
Long newInherited = null;
if (change.getAfter() != null)
{
newInherited = aclDaoComponent.getInheritedAccessControlList(change.getAfter());
}
updateChangedAclsImpl(layeredNode, layeredChanges, SetMode.DIRECT_ONLY, newInherited, change.getAfter());
break;
}
}
}
}
}
}
}
}
}
}
catch (AVMException e)
{
throw new InvalidNodeRefException(node);
}
}
private void updateLayeredAclsChangedByInheritance(List<AclChange> changes, HashMap<Long, Long> changeMap, Set<Long> unchanged)
{
for (AclChange change : changes)
{
if ((change.getTypeBefore() == ACLType.LAYERED) && (change.getTypeAfter() == ACLType.LAYERED))
{
// Query for affected nodes
List<Long> avmNodeIds = aclDaoComponent.getAvmNodesByACL(change.getBefore());
for (Long id : avmNodeIds)
{
// Find all paths to the nodes
AVMNodeDescriptor desc = new AVMNodeDescriptor(null, null, 0, null, null, null, 0, 0, 0, id, null, 0, null, 0, false, 0, false, 0, 0);
List<Pair<Integer, String>> paths = fAVMRepository.getHeadPaths(desc);
// Update all locations with the updated ACL
for (Pair<Integer, String> path : paths)
{
// No need to force COW - any inherited ACL will have COWED if the top ACL required it
setAclAsSystem(path.getSecond(), aclDaoComponent.getDbAccessControlList(change.getAfter()));
NodeRef layeredNode = AVMNodeConverter.ToNodeRef(-1, path.getSecond());
updateInheritedChangedAcls(layeredNode, changeMap, unchanged, aclDaoComponent.getInheritedAccessControlList(change.getAfter()), SetMode.DIRECT_ONLY);
}
}
}
}
}
private void updateInheritedChangedAcls(NodeRef startingPoint, HashMap<Long, Long> changeMap, Set<Long> unchanged, Long unsetAcl, SetMode mode)
{
// Walk children and fix up any that reference the given list ..
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(startingPoint);
int version = avmVersionPath.getFirst();
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", startingPoint);
}
String path = avmVersionPath.getSecond();
try
{
AVMNodeDescriptor descriptor = fAVMService.lookup(version, path);
if (descriptor == null)
{
return;
}
else
{
if (descriptor.isLayeredDirectory())
{
setInheritanceForDirectChildren(descriptor, changeMap, aclDaoComponent.getInheritedAccessControlList(getAclAsSystem(-1, descriptor.getPath()).getId()));
}
fixUpAcls(descriptor, changeMap, unchanged, unsetAcl, mode);
}
}
catch (AVMException e)
{
throw new InvalidNodeRefException(startingPoint);
}
}
private void fixUpAcls(AVMNodeDescriptor descriptor, Map<Long, Long> changes, Set<Long> unchanged, Long unsetAcl, SetMode mode)
{
DbAccessControlList acl = getAclAsSystem(-1, descriptor.getPath());
Long id = null;
if (acl != null)
{
id = acl.getId();
}
if (id == null)
{
// No need to force COW - ACL should have COWed if required
setAclAsSystem(descriptor.getPath(), aclDaoComponent.getDbAccessControlList(unsetAcl));
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, descriptor.getPath());
updateReferencingLayeredAcls(nodeRef, unsetAcl);
}
else if (changes.containsKey(id))
{
Long updateId = changes.get(id);
if (updateId != id)
{
DbAccessControlList newAcl = aclDaoComponent.getDbAccessControlList(updateId);
// No need to force COW - ACL should have COWed if required
setAclAsSystem(descriptor.getPath(), newAcl);
}
}
else if (unchanged.contains(id))
{
// carry on
}
else
{
// Not in the list
return;
}
if (descriptor.isDirectory())
{
Map<String, AVMNodeDescriptor> children;
switch (mode)
{
case ALL:
children = fAVMService.getDirectoryListing(descriptor, false);
break;
case DIRECT_ONLY:
children = fAVMService.getDirectoryListingDirect(descriptor, false);
break;
default:
throw new IllegalStateException();
}
for (AVMNodeDescriptor child : children.values())
{
fixUpAcls(child, changes, unchanged, unsetAcl, mode);
}
}
}
private void setInheritanceForDirectChildren(AVMNodeDescriptor descriptor, Map<Long, Long> changeMap, Long mergeFrom)
{
List<AclChange> changes = new ArrayList<AclChange>();
setFixedAcls(descriptor, mergeFrom, changes, SetMode.DIRECT_ONLY, false);
for (AclChange change : changes)
{
if (!change.getBefore().equals(change.getAfter()))
{
changeMap.put(change.getBefore(), change.getAfter());
}
}
}
public List<AclChange> setInheritanceForChildren(NodeRef parent, Long mergeFrom)
{
// Walk children and fix up any that reference the given list ..
// If previous is null we need to visit all descendants with a null acl and set
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(parent);
int version = avmVersionPath.getFirst();
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", parent);
}
String path = avmVersionPath.getSecond();
try
{
List<AclChange> changes = new ArrayList<AclChange>();
AVMNodeDescriptor descriptor = fAVMService.lookup(version, path);
setFixedAcls(descriptor, mergeFrom, changes, SetMode.ALL, false);
return changes;
}
catch (AVMException e)
{
throw new InvalidNodeRefException(parent);
}
}
public void setFixedAcls(AVMNodeDescriptor descriptor, Long mergeFrom, List<AclChange> changes, SetMode mode, boolean set)
{
if (descriptor == null)
{
return;
}
else
{
if (set)
{
// Simple set does not require any special COW wire up
// The AVM node will COW as required
DbAccessControlList previous = getAclAsSystem(-1, descriptor.getPath());
setAclAsSystem(descriptor.getPath(), aclDaoComponent.getDbAccessControlList(mergeFrom));
if (previous == null)
{
NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, descriptor.getPath());
updateReferencingLayeredAcls(nodeRef, mergeFrom);
}
}
if (descriptor.isDirectory())
{
Map<String, AVMNodeDescriptor> children;
switch (mode)
{
case ALL:
children = fAVMService.getDirectoryListing(descriptor, false);
break;
case DIRECT_ONLY:
children = fAVMService.getDirectoryListingDirect(descriptor, false);
break;
default:
throw new IllegalStateException();
}
for (String key : children.keySet())
{
AVMNodeDescriptor child = children.get(key);
DbAccessControlList acl = getAclAsSystem(-1, child.getPath());
if (acl == null)
{
setFixedAcls(child, mergeFrom, changes, mode, true);
}
else if (acl.getAclType() == ACLType.LAYERED)
{
// nothing to do
}
else if (acl.getAclType() == ACLType.DEFINING)
{
// Can require copy on right to be triggered for ACLS
// So we force a copy on write (which marks ACLS and below to copy if required)
fAVMService.forceCopy(child.getPath());
List<AclChange> newChanges = aclDaoComponent.mergeInheritedAccessControlList(mergeFrom, acl.getId());
for (AclChange change : newChanges)
{
if (change.getBefore().equals(acl.getId()))
{
setAclAsSystem(child.getPath(), aclDaoComponent.getDbAccessControlList(change.getAfter()));
setFixedAcls(child, aclDaoComponent.getInheritedAccessControlList(change.getAfter()), newChanges, SetMode.DIRECT_ONLY, false);
changes.addAll(newChanges);
break;
}
}
}
else
{
setFixedAcls(child, mergeFrom, changes, mode, true);
}
}
}
}
}
private enum SetMode
{
ALL, DIRECT_ONLY;
}
public Map<ACLType, Integer> patchAcls()
{
CounterSet result = new CounterSet();
List<AVMStoreDescriptor> stores = fAVMService.getStores();
for (AVMStoreDescriptor store : stores)
{
AVMNodeDescriptor root = fAVMService.getStoreRoot(-1, store.getName());
CounterSet update = fixOldAvmAcls(root);
result.add(update);
}
HashMap<ACLType, Integer> toReturn = new HashMap<ACLType, Integer>();
toReturn.put(ACLType.DEFINING, Integer.valueOf(result.get(ACLType.DEFINING).getCounter()));
toReturn.put(ACLType.FIXED, Integer.valueOf(result.get(ACLType.FIXED).getCounter()));
toReturn.put(ACLType.GLOBAL, Integer.valueOf(result.get(ACLType.GLOBAL).getCounter()));
toReturn.put(ACLType.LAYERED, Integer.valueOf(result.get(ACLType.LAYERED).getCounter()));
toReturn.put(ACLType.OLD, Integer.valueOf(result.get(ACLType.OLD).getCounter()));
toReturn.put(ACLType.SHARED, Integer.valueOf(result.get(ACLType.SHARED).getCounter()));
return toReturn;
}
private CounterSet fixOldAvmAcls(AVMNodeDescriptor node)
{
CounterSet result = new CounterSet();
// Do the children first
if (node.isDirectory())
{
Map<String, AVMNodeDescriptor> children = fAVMRepository.getListingDirect(node, true);
for (AVMNodeDescriptor child : children.values())
{
CounterSet update = fixOldAvmAcls(child);
result.add(update);
}
}
DbAccessControlList existingAcl = getAclAsSystem(-1, node.getPath());
if (existingAcl != null)
{
if (existingAcl.getAclType() == ACLType.OLD)
{
result.increment(ACLType.DEFINING);
//
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
properties.setAclType(ACLType.DEFINING);
// Accept default versioning
Long id = aclDaoComponent.createAccessControlList(properties);
DbAccessControlList newAcl = aclDaoComponent.getDbAccessControlList(id);
AccessControlList existing = aclDaoComponent.getAccessControlList(existingAcl.getId());
for (AccessControlEntry entry : existing.getEntries())
{
if (entry.getPosition() == 0)
{
aclDaoComponent.setAccessControlEntry(id, entry);
}
}
setAclAsSystem(node.getPath(), newAcl);
// Cascade to children - changes should all be 1-1 so we do not have to post fix
List<AclChange> changes = new ArrayList<AclChange>();
setFixedAcls(node, aclDaoComponent.getInheritedAccessControlList(id), changes, SetMode.DIRECT_ONLY, false);
for (AclChange change : changes)
{
if (!change.getBefore().equals(change.getAfter()))
{
throw new IllegalStateException("ACL fix should not change the acl ids - unexpected COW!");
}
}
}
else
{
throw new IllegalStateException();
}
}
else if (node.isLayeredDirectory())
{
result.increment(ACLType.LAYERED);
// create layered permission entry
if (node.getIndirection() != null)
{
AVMNodeDescriptor referencedNode = fAVMService.lookup(-1, node.getIndirection(), false);
if ((referencedNode != null) && (referencedNode.isDirectory()))
{
DbAccessControlList acl = getAclAsSystem(-1, referencedNode.getPath());
if (acl != null)
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(acl.getId()));
}
else
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(null));
}
}
else
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(null));
}
}
else
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(null));
}
List<AclChange> changes = new ArrayList<AclChange>();
setFixedAcls(node, aclDaoComponent.getInheritedAccessControlList(getAclAsSystem(-1, node.getPath()).getId()), changes, SetMode.DIRECT_ONLY, false);
for (AclChange change : changes)
{
if (!change.getBefore().equals(change.getAfter()))
{
throw new IllegalStateException("ACL fix should not change the acl ids - unexpected COW!");
}
}
}
else if (node.isLayeredFile())
{
result.increment(ACLType.LAYERED);
if (node.getIndirection() != null)
{
AVMNodeDescriptor referencedNode = fAVMService.lookup(-1, node.getIndirection(), false);
if (referencedNode != null)
{
DbAccessControlList acl = getAclAsSystem(-1, referencedNode.getPath());
if (acl != null)
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(acl.getId()));
}
else
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(null));
}
}
else
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(null));
}
}
else
{
setAclAsSystem(node.getPath(), DbAccessControlListImpl.createLayeredAcl(null));
}
List<AclChange> changes = new ArrayList<AclChange>();
setFixedAcls(node, aclDaoComponent.getInheritedAccessControlList(getAclAsSystem(-1, node.getPath()).getId()), changes, SetMode.DIRECT_ONLY, false);
for (AclChange change : changes)
{
if (!change.getBefore().equals(change.getAfter()))
{
throw new IllegalStateException("ACL fix should not change the acl ids - unexpected COW!");
}
}
}
return result;
}
private class CounterSet extends HashMap<ACLType, Counter>
{
CounterSet()
{
super();
this.put(ACLType.DEFINING, new Counter());
this.put(ACLType.FIXED, new Counter());
this.put(ACLType.GLOBAL, new Counter());
this.put(ACLType.LAYERED, new Counter());
this.put(ACLType.OLD, new Counter());
this.put(ACLType.SHARED, new Counter());
}
void add(ACLType type, Counter c)
{
Counter counter = get(type);
counter.add(c.getCounter());
}
void increment(ACLType type)
{
Counter counter = get(type);
counter.increment();
}
void add(CounterSet other)
{
add(ACLType.DEFINING, other.get(ACLType.DEFINING));
add(ACLType.FIXED, other.get(ACLType.FIXED));
add(ACLType.GLOBAL, other.get(ACLType.GLOBAL));
add(ACLType.LAYERED, other.get(ACLType.LAYERED));
add(ACLType.OLD, other.get(ACLType.OLD));
add(ACLType.SHARED, other.get(ACLType.SHARED));
}
}
private class Counter
{
int counter;
void increment()
{
counter++;
}
int getCounter()
{
return counter;
}
void add(int i)
{
counter += i;
}
}
private DbAccessControlList getAclAsSystem(final int version, final String path)
{
return AuthenticationUtil.runAs(new RunAsWork<DbAccessControlList>(){
public DbAccessControlList doWork() throws Exception
{
return fAVMRepository.getACL(version, path);
}}, AuthenticationUtil.getSystemUserName());
}
private void setAclAsSystem(final String path, final DbAccessControlList acl)
{
AuthenticationUtil.runAs(new RunAsWork<Object>(){
public Object doWork() throws Exception
{
fAVMRepository.setACL(path, acl);
return null;
}}, AuthenticationUtil.getSystemUserName());
}
}

View File

@@ -0,0 +1,494 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain.hibernate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.security.permissions.ACEType;
import org.alfresco.repo.security.permissions.AccessControlEntry;
import org.alfresco.repo.security.permissions.AccessControlList;
import org.alfresco.repo.security.permissions.NodePermissionEntry;
import org.alfresco.repo.security.permissions.PermissionEntry;
import org.alfresco.repo.security.permissions.PermissionReference;
import org.alfresco.repo.security.permissions.SimpleAccessControlEntry;
import org.alfresco.repo.security.permissions.impl.AclChange;
import org.alfresco.repo.security.permissions.impl.AclDaoComponent;
import org.alfresco.repo.security.permissions.impl.PermissionsDaoComponent;
import org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry;
import org.alfresco.repo.security.permissions.impl.SimplePermissionEntry;
import org.alfresco.repo.transaction.TransactionalDao;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.util.GUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public abstract class AbstractPermissionsDaoComponentImpl implements PermissionsDaoComponent, TransactionalDao
{
private static Log logger = LogFactory.getLog(AbstractPermissionsDaoComponentImpl.class);
protected static final boolean INHERIT_PERMISSIONS_DEFAULT = true;
protected AclDaoComponent aclDaoComponent;
private Map<String, AccessControlListDAO> fProtocolToACLDAO;
private AccessControlListDAO fDefaultACLDAO;
/** a uuid identifying this unique instance */
private String uuid;
AbstractPermissionsDaoComponentImpl()
{
this.uuid = GUID.generate();
}
public AclDaoComponent getAclDaoComponent()
{
return aclDaoComponent;
}
public void setAclDaoComponent(AclDaoComponent aclDaoComponent)
{
this.aclDaoComponent = aclDaoComponent;
}
/**
* Checks equality by type and uuid
*/
public boolean equals(Object obj)
{
if (obj == null)
{
return false;
}
else if (!(obj instanceof AbstractPermissionsDaoComponentImpl))
{
return false;
}
AbstractPermissionsDaoComponentImpl that = (AbstractPermissionsDaoComponentImpl) obj;
return this.uuid.equals(that.uuid);
}
/**
* @see #uuid
*/
public int hashCode()
{
return uuid.hashCode();
}
/**
* Does this <tt>Session</tt> contain any changes which must be synchronized with the store?
*
* @return true => changes are pending
*/
public boolean isDirty()
{
return aclDaoComponent.isDirty();
}
/**
* Just flushes the session
*/
public void flush()
{
aclDaoComponent.flush();
}
/**
* NO-OP
*/
public void beforeCommit()
{
aclDaoComponent.beforeCommit();
}
public void setProtocolToACLDAO(Map<String, AccessControlListDAO> map)
{
fProtocolToACLDAO = map;
}
public void setDefaultACLDAO(AccessControlListDAO defaultACLDAO)
{
fDefaultACLDAO = defaultACLDAO;
}
/**
* Helper to choose appropriate NodeService for the given NodeRef
*
* @param nodeRef
* The NodeRef to dispatch from.
* @return The appropriate NodeService.
*/
protected AccessControlListDAO getACLDAO(NodeRef nodeRef)
{
AccessControlListDAO ret = fProtocolToACLDAO.get(nodeRef.getStoreRef().getProtocol());
if (ret == null)
{
return fDefaultACLDAO;
}
return ret;
}
protected DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
DbAccessControlList acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
return acl;
}
protected CreationReport getMutableAccessControlList(NodeRef nodeRef)
{
DbAccessControlList acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
if (acl == null)
{
return createAccessControlList(nodeRef, INHERIT_PERMISSIONS_DEFAULT, null);
}
else
{
switch (acl.getAclType())
{
case FIXED:
case GLOBAL:
case SHARED:
case LAYERED:
// We can not set an ACL on node that has one of these types so we need to make a new one ....
return createAccessControlList(nodeRef, INHERIT_PERMISSIONS_DEFAULT, acl);
case DEFINING:
case OLD:
default:
// Force a copy on write if one is required
getACLDAO(nodeRef).forceCopy(nodeRef);
return new CreationReport(acl, Collections.<AclChange> emptyList());
}
}
}
public NodePermissionEntry getPermissions(NodeRef nodeRef)
{
// Create the object if it is not found.
// Null objects are not cached in hibernate
// If the object does not exist it will repeatedly query to check its
// non existence.
NodePermissionEntry npe = null;
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
// Do nothing.
}
if (acl == null)
{
// there isn't an access control list for the node - spoof a null one
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections.<SimplePermissionEntry> emptySet());
npe = snpe;
}
else
{
npe = createSimpleNodePermissionEntry(nodeRef);
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Got NodePermissionEntry for node: \n" + " node: " + nodeRef + "\n" + " acl: " + npe);
}
return npe;
}
@SuppressWarnings("unchecked")
public Map<NodeRef, Set<AccessPermission>> getAllSetPermissions(final String authority)
{
throw new UnsupportedOperationException();
}
public Set<NodeRef> findNodeByPermission(final String authority, final PermissionReference permission, final boolean allow)
{
throw new UnsupportedOperationException();
}
// Utility methods to create simple detached objects for the outside world
// We do not pass out the hibernate objects
private SimpleNodePermissionEntry createSimpleNodePermissionEntry(NodeRef nodeRef)
{
DbAccessControlList acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
if (acl == null)
{
// there isn't an access control list for the node - spoof a null one
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections.<SimplePermissionEntry> emptySet());
return snpe;
}
else
{
AccessControlList info = aclDaoComponent.getAccessControlList(acl.getId());
HashSet<SimplePermissionEntry> spes = new HashSet<SimplePermissionEntry>(info.getEntries().size(), 1.0f);
for (AccessControlEntry entry : info.getEntries())
{
SimplePermissionEntry spe = new SimplePermissionEntry(nodeRef, entry.getPermission(), entry.getAuthority(), entry.getAccessStatus());
spes.add(spe);
}
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, acl.getInherits(), spes);
return snpe;
}
}
public boolean getInheritParentPermissions(NodeRef nodeRef)
{
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return INHERIT_PERMISSIONS_DEFAULT;
}
if (acl == null)
{
return INHERIT_PERMISSIONS_DEFAULT;
}
else
{
return aclDaoComponent.getAccessControlListProperties(acl.getId()).getInherits();
}
}
@SuppressWarnings("unchecked")
public void deletePermissions(String authority)
{
@SuppressWarnings("unused")
List<AclChange> changes = aclDaoComponent.deleteAccessControlEntries(authority);
// ignore changes - deleting an authority does not casue all acls to version
}
public void deletePermissions(NodeRef nodeRef, final String authority)
{
DbAccessControlList acl = null;
try
{
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
switch (acl.getAclType())
{
case FIXED:
case GLOBAL:
case SHARED:
throw new IllegalStateException("Can not delete from this acl in a node context " + acl.getAclType());
case DEFINING:
case LAYERED:
case OLD:
default:
CreationReport report = getMutableAccessControlList(nodeRef);
SimpleAccessControlEntry pattern = new SimpleAccessControlEntry();
pattern.setAuthority(authority);
List<AclChange> changes = aclDaoComponent.deleteAccessControlEntries(report.getCreated().getId(), pattern);
getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
break;
}
}
/**
* Deletes all permission entries (access control list entries) that match the given criteria. Note that the access
* control list for the node is not deleted.
*/
public void deletePermission(NodeRef nodeRef, String authority, PermissionReference permission)
{
DbAccessControlList acl = null;
try
{
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
switch (acl.getAclType())
{
case FIXED:
case GLOBAL:
case SHARED:
throw new IllegalStateException("Can not delete from this acl in a node context " + acl.getAclType());
case DEFINING:
case LAYERED:
case OLD:
default:
CreationReport report = getMutableAccessControlList(nodeRef);
SimpleAccessControlEntry pattern = new SimpleAccessControlEntry();
pattern.setAuthority(authority);
pattern.setPermission(permission);
List<AclChange> changes = aclDaoComponent.deleteAccessControlEntries(report.getCreated().getId(), pattern);
getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
break;
}
}
public void setPermission(NodeRef nodeRef, String authority, PermissionReference permission, boolean allow)
{
CreationReport report = null;
try
{
report = getMutableAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
if (report.getCreated() != null)
{
SimpleAccessControlEntry entry = new SimpleAccessControlEntry();
entry.setAuthority(authority);
entry.setPermission(permission);
entry.setAccessStatus(allow ? AccessStatus.ALLOWED : AccessStatus.DENIED);
entry.setAceType(ACEType.ALL);
List<AclChange> changes = aclDaoComponent.setAccessControlEntry(report.getCreated().getId(), entry);
List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size());
all.addAll(report.getChanges());
all.addAll(changes);
getACLDAO(nodeRef).updateChangedAcls(nodeRef, all);
}
}
public void setPermission(PermissionEntry permissionEntry)
{
setPermission(permissionEntry.getNodeRef(), permissionEntry.getAuthority(), permissionEntry.getPermissionReference(), permissionEntry.isAllowed());
}
public void setPermission(NodePermissionEntry nodePermissionEntry)
{
NodeRef nodeRef = nodePermissionEntry.getNodeRef();
// Get the access control list
// Note the logic here requires to know whether it was created or not
DbAccessControlList existing = getAccessControlList(nodeRef);
if (existing != null)
{
deletePermissions(nodeRef);
}
// create the access control list
CreationReport report = createAccessControlList(nodeRef, nodePermissionEntry.inheritPermissions(), existing);
// add all entries
for (PermissionEntry pe : nodePermissionEntry.getPermissionEntries())
{
SimpleAccessControlEntry entry = new SimpleAccessControlEntry();
entry.setAuthority(pe.getAuthority());
entry.setPermission(pe.getPermissionReference());
entry.setAccessStatus(pe.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED);
entry.setAceType(ACEType.ALL);
List<AclChange> changes = aclDaoComponent.setAccessControlEntry(report.getCreated().getId(), entry);
List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size());
all.addAll(report.getChanges());
all.addAll(changes);
getACLDAO(nodeRef).updateChangedAcls(nodeRef, all);
}
}
public void setInheritParentPermissions(NodeRef nodeRef, boolean inheritParentPermissions)
{
DbAccessControlList acl = getAccessControlList(nodeRef);
if ((acl == null) && (inheritParentPermissions == INHERIT_PERMISSIONS_DEFAULT))
{
return;
}
if ((acl != null) && (acl.getInherits() == inheritParentPermissions))
{
return;
}
CreationReport report = getMutableAccessControlList(nodeRef);
List<AclChange> changes;
if (!inheritParentPermissions)
{
changes = aclDaoComponent.disableInheritance(report.getCreated().getId(), false);
}
else
{
// TODO: Find inheritance
changes = aclDaoComponent.enableInheritance(report.getCreated().getId(), null);
}
List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size());
all.addAll(report.getChanges());
all.addAll(changes);
getACLDAO(nodeRef).updateChangedAcls(nodeRef, all);
}
protected abstract CreationReport createAccessControlList(NodeRef nodeRef, boolean inherit, DbAccessControlList existing);
static class CreationReport
{
DbAccessControlList created;
List<AclChange> changes;
CreationReport(DbAccessControlList created, List<AclChange> changes)
{
this.created = created;
this.changes = changes;
}
public void setChanges(List<AclChange> changes)
{
this.changes = changes;
}
public void setCreated(DbAccessControlList created)
{
this.created = created;
}
public List<AclChange> getChanges()
{
return changes;
}
public DbAccessControlList getCreated()
{
return created;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,163 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain.hibernate;
import java.io.Serializable;
import org.alfresco.repo.domain.DbAccessControlEntryContext;
public class DbAccessControlEntryContextImpl implements DbAccessControlEntryContext, Serializable
{
/**
*
*/
private static final long serialVersionUID = -4479587461724827683L;
private String classContext;
private String kvpContext;
private String propertyContext;
private Long id;
private Long version;
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("DbAccessControlEntryContextImpl").append("[ id=").append(id).append(", version=").append(version).append(", classContext=").append(classContext).append(
", kvpContext=").append(kvpContext).append(", propertyContext=").append(propertyContext);
return sb.toString();
}
@Override
public int hashCode()
{
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((classContext == null) ? 0 : classContext.hashCode());
result = PRIME * result + ((kvpContext == null) ? 0 : kvpContext.hashCode());
result = PRIME * result + ((propertyContext == null) ? 0 : propertyContext.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final DbAccessControlEntryContextImpl other = (DbAccessControlEntryContextImpl) obj;
if (classContext == null)
{
if (other.classContext != null)
return false;
}
else if (!classContext.equals(other.classContext))
return false;
if (kvpContext == null)
{
if (other.kvpContext != null)
return false;
}
else if (!kvpContext.equals(other.kvpContext))
return false;
if (propertyContext == null)
{
if (other.propertyContext != null)
return false;
}
else if (!propertyContext.equals(other.propertyContext))
return false;
return true;
}
public String getClassContext()
{
return classContext;
}
public Long getId()
{
return id;
}
public String getKvpContext()
{
return kvpContext;
}
public String getPropertyContext()
{
return propertyContext;
}
public Long getVersion()
{
return version;
}
public void setClassContext(String classContext)
{
this.classContext = classContext;
}
public void setKvpContext(String kvpContext)
{
this.kvpContext = kvpContext;
}
public void setPropertyContext(String propertyContext)
{
this.propertyContext = propertyContext;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setId(Long id)
{
this.id = id;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setVersion(Long version)
{
this.version = version;
}
}

View File

@@ -27,32 +27,41 @@ package org.alfresco.repo.domain.hibernate;
import java.io.Serializable;
import org.alfresco.repo.domain.DbAccessControlEntry;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.DbAccessControlEntryContext;
import org.alfresco.repo.domain.DbAuthority;
import org.alfresco.repo.domain.DbPermission;
import org.alfresco.util.EqualsHelper;
import org.alfresco.repo.domain.DbPermissionKey;
import org.alfresco.repo.security.permissions.ACEType;
import org.alfresco.service.namespace.QName;
import org.hibernate.CallbackException;
import org.hibernate.Session;
/**
* Persisted permission entries
*
* @author andyh
*/
public class DbAccessControlEntryImpl extends LifecycleAdapter
implements DbAccessControlEntry, Serializable
public class DbAccessControlEntryImpl implements DbAccessControlEntry, Serializable
{
private static final long serialVersionUID = -418837862334064582L;
private Long id;
private Long version;
/** The container of these entries */
private DbAccessControlList accessControlList;
/** The permission to which this applies (non null - all is a special string) */
private DbPermission permission;
/** The recipient to which this applies (non null - all is a special string) */
private DbAuthority authority;
/** Is this permission allowed? */
private boolean allowed;
private int aceType;
private DbAccessControlEntryContext context;
public DbAccessControlEntryImpl()
{
super();
@@ -62,58 +71,69 @@ public class DbAccessControlEntryImpl extends LifecycleAdapter
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("DbAccessControlEntryImpl")
.append("[ id=").append(id)
.append(", acl=").append(accessControlList.getId())
.append(", permission=").append(permission.getKey())
.append(", authority=").append(authority.getRecipient())
.append("]");
sb.append("DbAccessControlEntryImpl").append("[ id=").append(id).append(", version=").append(version).append(", permission=").append(permission.getKey()).append(
", authority=").append(authority.getAuthority()).append(", allowed=").append(allowed).append(", authorityDeleted=").append(", aceType=")
.append(ACEType.getACETypeFromId(aceType)).append(", context=").append(context).append("]");
return sb.toString();
}
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof DbAccessControlEntry))
{
return false;
}
DbAccessControlEntry other = (DbAccessControlEntry) o;
if (EqualsHelper.nullSafeEquals(id, other.getId()))
{
return true;
}
else
{
return (EqualsHelper.nullSafeEquals(this.permission, other.getPermission())
&& EqualsHelper.nullSafeEquals(this.authority, other.getAuthority()));
}
}
@Override
public int hashCode()
{
int hashCode = 0;
if (permission != null)
final int PRIME = 31;
int result = 1;
result = PRIME * result + aceType;
result = PRIME * result + (allowed ? 1231 : 1237);
result = PRIME * result + ((authority == null) ? 0 : authority.hashCode());
result = PRIME * result + ((context == null) ? 0 : context.hashCode());
result = PRIME * result + ((permission == null) ? 0 : permission.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final DbAccessControlEntryImpl other = (DbAccessControlEntryImpl) obj;
if (aceType != other.aceType)
return false;
if (allowed != other.allowed)
return false;
if (authority == null)
{
hashCode = hashCode * 37 + permission.hashCode();
if (other.authority != null)
return false;
}
if (authority != null)
else if (!authority.equals(other.authority))
return false;
if (context == null)
{
hashCode = hashCode * 37 + authority.hashCode();
if (other.context != null)
return false;
}
return hashCode;
else if (!context.equals(other.context))
return false;
if (permission == null)
{
if (other.permission != null)
return false;
}
else if (!permission.equals(other.permission))
return false;
return true;
}
public Long getId()
{
return id;
}
/**
* For Hibernate use
*/
@@ -137,16 +157,6 @@ public class DbAccessControlEntryImpl extends LifecycleAdapter
this.version = version;
}
public DbAccessControlList getAccessControlList()
{
return accessControlList;
}
public void setAccessControlList(DbAccessControlList nodePermissionEntry)
{
this.accessControlList = nodePermissionEntry;
}
public DbPermission getPermission()
{
return permission;
@@ -177,12 +187,54 @@ public class DbAccessControlEntryImpl extends LifecycleAdapter
this.allowed = allowed;
}
public ACEType getAceType()
{
return ACEType.getACETypeFromId(aceType);
}
public void setAceType(ACEType aceType)
{
this.aceType = aceType.getId();
}
@SuppressWarnings("unused")
private void setApplies(int applies)
{
this.aceType = applies;
}
@SuppressWarnings("unused")
private int getApplies()
{
return aceType;
}
public DbAccessControlEntryContext getContext()
{
return context;
}
public void setContext(DbAccessControlEntryContext context)
{
this.context = context;
}
public void delete()
{
// remove the instance from the access control list
@SuppressWarnings("unused")
boolean removed = getAccessControlList().getEntries().remove(this);
// delete the instance
getSession().delete(this);
throw new UnsupportedOperationException("TODO");
}
public static DbAccessControlEntry find(Session session, ACEType type, boolean allow, String authority, DbPermissionKey permissionKey)
{
// Query query = session
// .getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_PERMISSION)
// .setString("permissionTypeQName", qname.toString())
// .setString("permissionName", name);
// return (DbPermission) query.uniqueResult();
throw new UnsupportedOperationException("TODO");
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain.hibernate;
import java.io.Serializable;
import org.alfresco.repo.domain.DbAccessControlListChangeSet;
public class DbAccessControlListChangeSetImpl implements DbAccessControlListChangeSet, Serializable
{
/**
*
*/
private static final long serialVersionUID = 3433168181194696611L;
private Long id;
private Long version;
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("DBAccessControlListChangeSetImpl")
.append("[ id=").append(id)
.append(", version=").append(version)
.append("]");
return sb.toString();
}
public Long getId()
{
return id;
}
public Long getVersion()
{
return version;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setId(Long id)
{
this.id = id;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setVersion(Long version)
{
this.version = version;
}
}

View File

@@ -26,80 +26,102 @@ package org.alfresco.repo.domain.hibernate;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Map;
import org.alfresco.repo.domain.DbAccessControlEntry;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.DbAccessControlListChangeSet;
import org.alfresco.repo.domain.DbAccessControlListMember;
import org.alfresco.repo.domain.DbAuthority;
import org.alfresco.repo.domain.DbPermission;
import org.alfresco.repo.domain.DbPermissionKey;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.repo.security.permissions.ACLType;
import org.alfresco.repo.security.permissions.AccessControlEntry;
import org.alfresco.repo.security.permissions.SimpleAccessControlListProperties;
import org.alfresco.repo.security.permissions.impl.AclDaoComponent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.CallbackException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
/**
* The hibernate persisted class for node permission entries.
*
* @author andyh
*/
public class DbAccessControlListImpl extends LifecycleAdapter
implements DbAccessControlList, Serializable
public class DbAccessControlListImpl extends LifecycleAdapter implements DbAccessControlList, Serializable
{
private static AclDaoComponent s_aclDaoComponent;
private static final long serialVersionUID = 3123277428227075648L;
private static Log logger = LogFactory.getLog(DbAccessControlListImpl.class);
private Long id;
private Long version;
private Set<DbAccessControlEntry> entries;
private String aclId;
private long aclVersion;
private boolean latest;
private boolean inherits;
private int aclType;
private Long inheritedAclId;
private boolean versioned;
private DbAccessControlListChangeSet aclChangeSet;
private Long inheritsFrom;
private boolean requiresVersion;
public static void setAclDaoComponent(AclDaoComponent aclDaoComponent)
{
s_aclDaoComponent = aclDaoComponent;
}
public DbAccessControlListImpl()
{
entries = new HashSet<DbAccessControlEntry>(5);
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("DbAccessControlListImpl")
.append("[ id=").append(id)
.append(", entries=").append(entries.size())
.append(", inherits=").append(inherits)
.append("]");
sb.append("DbAccessControlListImpl").append("[ id=").append(id).append(", version=").append(version).append(", aclId=").append(aclId).append(", aclVersion=").append(
aclVersion).append(", latest=").append(latest).append(", inherits=").append(inherits).append(", aclType=").append(ACLType.getACLTypeFromId(aclType)).append(
", inheritedAclId=").append(inheritedAclId).append(", versioned=").append(versioned).append(", changesetId=").append(aclChangeSet).append(", inheritsFrom=")
.append(inheritsFrom).append(", requiresVersion=").append(requiresVersion).append("]");
return sb.toString();
}
/**
* Support cascade delete of ACLs from DM nodes (which cascade delete the ACL)
*/
@Override
public boolean equals(Object o)
public boolean onDelete(Session session) throws CallbackException
{
if (this == o)
{
return true;
}
if (!(o instanceof DbAccessControlList))
{
return false;
}
DbAccessControlList other = (DbAccessControlList) o;
return (this.inherits == other.getInherits());
}
@Override
public int hashCode()
{
return (inherits == false ? 0 : 17);
s_aclDaoComponent.onDeleteAccessControlList(id);
return super.onDelete(session);
}
public Long getId()
{
return id;
}
/**
* Hibernate use
*/
@@ -123,20 +145,6 @@ public class DbAccessControlListImpl extends LifecycleAdapter
this.version = version;
}
public Set<DbAccessControlEntry> getEntries()
{
return entries;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setEntries(Set<DbAccessControlEntry> entries)
{
this.entries = entries;
}
public boolean getInherits()
{
return inherits;
@@ -147,130 +155,131 @@ public class DbAccessControlListImpl extends LifecycleAdapter
this.inherits = inherits;
}
/**
* @see #deleteEntry(String, DbPermissionKey)
*/
public int deleteEntriesForAuthority(String authority)
public String getAclId()
{
return deleteEntry(authority, null);
return aclId;
}
public void setAclId(String aclId)
{
this.aclId = aclId;
}
public ACLType getAclType()
{
return ACLType.getACLTypeFromId(aclType);
}
public void setAclType(ACLType aclType)
{
this.aclType = aclType.getId();
}
/**
* @see #deleteEntry(String, DbPermissionKey)
* Hibernate
*/
public int deleteEntriesForPermission(DbPermissionKey permissionKey)
private int getType()
{
return deleteEntry(null, permissionKey);
return aclType;
}
public int deleteEntry(String authority, DbPermissionKey permissionKey)
private void setType(int aclType)
{
List<DbAccessControlEntry> toDelete = new ArrayList<DbAccessControlEntry>(2);
for (DbAccessControlEntry entry : entries)
{
if (authority != null && !authority.equals(entry.getAuthority().getRecipient()))
{
// authority is not a match
continue;
}
else if (permissionKey != null && !permissionKey.equals(entry.getPermission().getKey()))
{
// permission is not a match
continue;
}
toDelete.add(entry);
}
// delete them
for (DbAccessControlEntry entry : toDelete)
{
// remove from the entry list
entry.delete();
}
// Fix issues with deleting and adding permissions
// See AR-918
this.getSession().flush();
// done
if (logger.isDebugEnabled())
{
logger.debug("Deleted " + toDelete.size() + " access entries: \n" +
" access control list: " + id + "\n" +
" authority: " + authority + "\n" +
" permission: " + permissionKey);
}
return toDelete.size();
this.aclType = aclType;
}
public int deleteEntries()
public long getAclVersion()
{
/*
* We don't do the full delete-remove-from-set thing here. Just delete each child entity
* and then clear the entry set.
*/
Session session = getSession();
List<DbAccessControlEntry> toDelete = new ArrayList<DbAccessControlEntry>(entries);
// delete each entry
for (DbAccessControlEntry entry : toDelete)
{
session.delete(entry);
}
// clear the list
int count = entries.size();
entries.clear();
// done
if (logger.isDebugEnabled())
{
logger.debug("Deleted " + count + " access entries for access control list " + this.id);
}
return count;
return aclVersion;
}
public DbAccessControlEntry getEntry(String authority, DbPermissionKey permissionKey)
public void setAclVersion(long aclVersion)
{
for (DbAccessControlEntry entry : entries)
{
DbAuthority authorityEntity = entry.getAuthority();
DbPermission permissionEntity = entry.getPermission();
// check for a match
if (authorityEntity.getRecipient().equals(authority)
&& permissionEntity.getKey().equals(permissionKey))
{
// found it
return entry;
}
}
return null;
this.aclVersion = aclVersion;
}
public DbAccessControlEntryImpl newEntry(DbPermission permission, DbAuthority authority, boolean allowed)
public Long getInheritedAclId()
{
DbAccessControlEntryImpl accessControlEntry = new DbAccessControlEntryImpl();
// fill
accessControlEntry.setAccessControlList(this);
accessControlEntry.setPermission(permission);
accessControlEntry.setAuthority(authority);
accessControlEntry.setAllowed(allowed);
// save it
getSession().save(accessControlEntry);
// maintain inverse set on the acl
getEntries().add(accessControlEntry);
// done
return accessControlEntry;
return inheritedAclId;
}
/**
* Make a copy of this ACL.
* @return The copy.
*/
public DbAccessControlList getCopy()
public void setInheritedAclId(Long inheritedAclId)
{
DbAccessControlList newAcl =
new DbAccessControlListImpl();
getSession().save(newAcl);
for (DbAccessControlEntry entry : entries)
this.inheritedAclId = inheritedAclId;
}
public boolean isLatest()
{
return latest;
}
public void setLatest(boolean latest)
{
this.latest = latest;
}
public boolean isVersioned()
{
return versioned;
}
public void setVersioned(boolean versioned)
{
this.versioned = versioned;
}
public DbAccessControlListChangeSet getAclChangeSet()
{
return aclChangeSet;
}
public void setAclChangeSet(DbAccessControlListChangeSet aclChangeSet)
{
this.aclChangeSet = aclChangeSet;
}
public static DbAccessControlList find(Session session)
{
// TODO: Needs to use a query
throw new UnsupportedOperationException("TODO");
}
public Long getInheritsFrom()
{
return inheritsFrom;
}
public void setInheritsFrom(Long id)
{
this.inheritsFrom = id;
}
public DbAccessControlList getCopy(Long parentAcl, ACLCopyMode mode)
{
return s_aclDaoComponent.getDbAccessControlListCopy(this.getId(), parentAcl, mode);
}
public static DbAccessControlList createLayeredAcl(Long indirectedAcl)
{
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
properties.setAclType(ACLType.LAYERED);
Long id = s_aclDaoComponent.createAccessControlList(properties);
if (indirectedAcl != null)
{
newAcl.newEntry(entry.getPermission(), entry.getAuthority(), entry.isAllowed());
s_aclDaoComponent.mergeInheritedAccessControlList(indirectedAcl, id);
}
return newAcl;
return s_aclDaoComponent.getDbAccessControlList(id);
}
public boolean getRequiresVersion()
{
return requiresVersion;
}
public void setRequiresVersion(boolean requiresVersion)
{
this.requiresVersion = requiresVersion;
}
}

View File

@@ -0,0 +1,175 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain.hibernate;
import java.io.Serializable;
import org.alfresco.repo.domain.DbAccessControlEntry;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.DbAccessControlListMember;
import org.hibernate.Session;
/**
* Hibernate support to store acl-acxe entries
*/
public class DbAccessControlListMemberImpl implements DbAccessControlListMember, Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
private Long id;
private Long version;
private DbAccessControlList acl;
private DbAccessControlEntry ace;
private int position;
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("DbAccessControlListMemberImpl").append("[ id=").append(id).append(", version=").append(version).append(", acl=").append(acl).append(", ace=").append(ace)
.append(", position=").append(position).append("]");
return sb.toString();
}
@Override
public int hashCode()
{
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((ace == null) ? 0 : ace.hashCode());
result = PRIME * result + ((acl == null) ? 0 : acl.hashCode());
result = PRIME * result + position;
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final DbAccessControlListMemberImpl other = (DbAccessControlListMemberImpl) obj;
if (ace == null)
{
if (other.ace != null)
return false;
}
else if (!ace.equals(other.ace))
return false;
if (acl == null)
{
if (other.acl != null)
return false;
}
else if (!acl.equals(other.acl))
return false;
if (position != other.position)
return false;
return true;
}
public DbAccessControlEntry getAccessControlEntry()
{
return ace;
}
public DbAccessControlList getAccessControlList()
{
return acl;
}
public Long getId()
{
return id;
}
public int getPosition()
{
return position;
}
public Long getVersion()
{
return version;
}
public void setAccessControlEntry(DbAccessControlEntry ace)
{
this.ace = ace;
}
public void setAccessControlList(DbAccessControlList acl)
{
this.acl = acl;
}
public void setPosition(int position)
{
this.position = position;
}
@SuppressWarnings("unused")
private void setId(Long id)
{
this.id = id;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setVersion(Long version)
{
this.version = version;
}
/**
*
* @param session
* @param acl => can be null - implies all entries that match ace
* @param ace => can be null - implies all entries that match acl
* @param position => -1 is all positions
*
* Note: both acl and ace may not be null;
*
* @return
*/
public static DbAccessControlListMember find(Session session, DbAccessControlList acl, DbAccessControlEntry ace, int position)
{
// TODO: Needs to use a query
throw new UnsupportedOperationException("TODO");
}
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain.hibernate;
import java.io.Serializable;
import org.alfresco.repo.domain.DbAuthority;
import org.alfresco.repo.domain.DbAuthorityAlias;
import org.hibernate.Session;
public class DbAuthorityAliasImpl implements DbAuthorityAlias, Serializable
{
/**
*
*/
private static final long serialVersionUID = -774180120537804154L;
private Long id;
private Long version;
private DbAuthority authority;
private DbAuthority alias;
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("DbAuthorityAliasImpl")
.append("[ id=").append(id)
.append(", version=").append(version)
.append(", authority=").append(authority)
.append(", alias=").append(alias)
.append("]");
return sb.toString();
}
@Override
public int hashCode()
{
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((alias == null) ? 0 : alias.hashCode());
result = PRIME * result + ((authority == null) ? 0 : authority.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final DbAuthorityAliasImpl other = (DbAuthorityAliasImpl) obj;
if (alias == null)
{
if (other.alias != null)
return false;
}
else if (!alias.equals(other.alias))
return false;
if (authority == null)
{
if (other.authority != null)
return false;
}
else if (!authority.equals(other.authority))
return false;
return true;
}
public DbAuthority getAlias()
{
return alias;
}
public DbAuthority getAuthority()
{
return authority;
}
public Long getId()
{
return id;
}
public Long getVersion()
{
return version;
}
public void setAlias(DbAuthority alias)
{
this.alias = alias;
}
public void setAuthority(DbAuthority authority)
{
this.authority = authority;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setId(Long id)
{
this.id = id;
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setVersion(Long version)
{
this.version = version;
}
/**
* Helper method to find an authority alias based on the authority and alias
*
* @param session the Hibernate session to use
* @param authority the authority name
* @return Returns an existing instance or null if not found
*/
public static DbAuthorityAlias find(Session session, String authority, String alias)
{
// TODO: Needs to use a query
throw new UnsupportedOperationException("TODO");
}
}

View File

@@ -25,14 +25,11 @@
package org.alfresco.repo.domain.hibernate;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import org.alfresco.repo.domain.DbAuthority;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.CallbackException;
import org.hibernate.Query;
import org.hibernate.Session;
/**
@@ -40,20 +37,31 @@ import org.hibernate.Session;
*
* @author andyh
*/
public class DbAuthorityImpl extends LifecycleAdapter
public class DbAuthorityImpl
implements DbAuthority, Serializable
{
private static final long serialVersionUID = -5582068692208928127L;
private static Log logger = LogFactory.getLog(DbAuthorityImpl.class);
private Long id;
private Long version;
private String recipient;
private Set<String> externalKeys;
private String authority;
public DbAuthorityImpl()
{
externalKeys = new HashSet<String>();
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("DbAuthorityImpl")
.append("[ id=").append(id)
.append(", version=").append(version)
.append(", authority=").append(authority)
.append("]");
return sb.toString();
}
@Override
@@ -68,44 +76,27 @@ public class DbAuthorityImpl extends LifecycleAdapter
return false;
}
DbAuthority other = (DbAuthority)o;
return this.getRecipient().equals(other.getRecipient());
return this.getAuthority().equals(other.getAuthority());
}
@Override
public int hashCode()
{
return getRecipient().hashCode();
return getAuthority().hashCode();
}
public int deleteEntries()
public Long getId()
{
/*
* This can use a delete direct to the database as well, but then care must be taken
* to evict the instances from the session.
*/
// bypass L2 cache and get all entries for this list
Query query = getSession()
.getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_AC_ENTRIES_FOR_AUTHORITY)
.setString("authorityRecipient", this.recipient);
int count = HibernateHelper.deleteDbAccessControlEntries(getSession(), query);
// done
if (logger.isDebugEnabled())
{
logger.debug("Deleted " + count + " access entries for access control list " + this.recipient);
}
return count;
return id;
}
/**
* Ensures that all this access control list's entries have been deleted.
*/
public boolean onDelete(Session session) throws CallbackException
@SuppressWarnings("unused")
private void setId(Long id)
{
deleteEntries();
return super.onDelete(session);
this.id = id;
}
public Long getVersion()
{
return version;
@@ -120,25 +111,14 @@ public class DbAuthorityImpl extends LifecycleAdapter
this.version = version;
}
public String getRecipient()
public String getAuthority()
{
return recipient;
return authority;
}
public void setRecipient(String recipient)
public void setAuthority(String authority)
{
this.recipient = recipient;
}
public Set<String> getExternalKeys()
{
return externalKeys;
}
// Hibernate
/* package */ void setExternalKeys(Set<String> externalKeys)
{
this.externalKeys = externalKeys;
this.authority = authority;
}
/**
@@ -150,6 +130,7 @@ public class DbAuthorityImpl extends LifecycleAdapter
*/
public static DbAuthority find(Session session, String authority)
{
return (DbAuthority) session.get(DbAuthorityImpl.class, authority);
// TODO: Needs to use a query
throw new UnsupportedOperationException("TODO");
}
}

View File

@@ -41,49 +41,47 @@ import org.hibernate.Session;
*
* @author andyh
*/
public class DbPermissionImpl extends LifecycleAdapter
implements DbPermission, Serializable
{
public class DbPermissionImpl implements DbPermission, Serializable
{
private static final long serialVersionUID = -6352566900815035461L;
private static Log logger = LogFactory.getLog(DbPermissionImpl.class);
private Long id;
private Long version;
private QName typeQname;
private String name;
public DbPermissionImpl()
{
super();
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(128);
sb.append("PermissionImpl")
.append("[ id=").append(id)
.append(", typeQname=").append(typeQname)
.append(", name=").append(getName())
.append("]");
sb.append("DbPermissionImpl").append("[ id=").append(id).append(", version=").append(version).append(", typeQname=").append(typeQname).append(", name=").append(getName())
.append("]");
return sb.toString();
}
@Override
public boolean equals(Object o)
{
if(this == o)
if (this == o)
{
return true;
}
if(!(o instanceof DbPermission))
if (!(o instanceof DbPermission))
{
return false;
}
DbPermission other = (DbPermission)o;
return (EqualsHelper.nullSafeEquals(typeQname, other.getTypeQname()))
&& (EqualsHelper.nullSafeEquals(name, other.getName()));
DbPermission other = (DbPermission) o;
return (EqualsHelper.nullSafeEquals(typeQname, other.getTypeQname())) && (EqualsHelper.nullSafeEquals(name, other.getName()));
}
@Override
@@ -91,35 +89,6 @@ public class DbPermissionImpl extends LifecycleAdapter
{
return typeQname.hashCode() + (37 * name.hashCode());
}
public int deleteEntries()
{
/*
* This can use a delete direct to the database as well, but then care must be taken
* to evict the instances from the session.
*/
// bypass L2 cache and get all entries for this list
Query query = getSession()
.getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_AC_ENTRIES_FOR_PERMISSION)
.setSerializable("permissionId", this.id);
int count = HibernateHelper.deleteDbAccessControlEntries(getSession(), query);
// done
if (logger.isDebugEnabled())
{
logger.debug("Deleted " + count + " access entries for permission " + this.id);
}
return count;
}
/**
* Ensures that all this access control list's entries have been deleted.
*/
public boolean onDelete(Session session) throws CallbackException
{
deleteEntries();
return super.onDelete(session);
}
public Long getId()
{
@@ -168,7 +137,7 @@ public class DbPermissionImpl extends LifecycleAdapter
{
this.name = name;
}
public DbPermissionKey getKey()
{
return new DbPermissionKey(typeQname, name);
@@ -177,17 +146,21 @@ public class DbPermissionImpl extends LifecycleAdapter
/**
* Helper method to find a permission based on its natural key
*
* @param session the Hibernate session to use
* @param qname the type qualified name
* @param name the name of the permission
* @param session
* the Hibernate session to use
* @param qname
* the type qualified name
* @param name
* the name of the permission
* @return Returns an existing instance or null if not found
*/
public static DbPermission find(Session session, QName qname, String name)
{
Query query = session
.getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_PERMISSION)
.setString("permissionTypeQName", qname.toString())
.setString("permissionName", name);
return (DbPermission) query.uniqueResult();
// Query query = session
// .getNamedQuery(PermissionsDaoComponentImpl.QUERY_GET_PERMISSION)
// .setString("permissionTypeQName", qname.toString())
// .setString("permissionName", name);
// return (DbPermission) query.uniqueResult();
throw new UnsupportedOperationException("TODO");
}
}

View File

@@ -1,88 +1,149 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.domain.hibernate;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The Node implementation for getting and setting ACLs.
* @author britt
*/
public class NodeAccessControlListDAO extends HibernateDaoSupport implements AccessControlListDAO
{
/**
* The DAO for Nodes.
*/
private NodeDaoService fNodeDAOService;
/**
* Default constructor.
*/
public NodeAccessControlListDAO()
{
}
public void setNodeDaoService(NodeDaoService nodeDAOService)
{
fNodeDAOService = nodeDAOService;
}
/**
* Get the ACL from a node.
* @param nodeRef The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Node node = fNodeDAOService.getNode(nodeRef);
if (node == null)
{
throw new InvalidNodeRefException(nodeRef);
}
return node.getAccessControlList();
}
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Node node = fNodeDAOService.getNode(nodeRef);
if (node == null)
{
throw new InvalidNodeRefException(nodeRef);
}
node.setAccessControlList(acl);
}
}
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
package org.alfresco.repo.domain.hibernate;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.ChildAssoc;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.repo.security.permissions.ACLType;
import org.alfresco.repo.security.permissions.impl.AclChange;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* The Node implementation for getting and setting ACLs.
*
* @author britt
*/
public class NodeAccessControlListDAO implements AccessControlListDAO
{
/**
* The DAO for Nodes.
*/
private NodeDaoService fNodeDAOService;
/**
* Default constructor.
*/
public NodeAccessControlListDAO()
{
}
public void setNodeDaoService(NodeDaoService nodeDAOService)
{
fNodeDAOService = nodeDAOService;
}
/**
* Get the ACL from a node.
*
* @param nodeRef
* The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Node node = fNodeDAOService.getNode(nodeRef);
if (node == null)
{
throw new InvalidNodeRefException(nodeRef);
}
return node.getAccessControlList();
}
/**
* Set the ACL on a node.
*
* @param nodeRef
* The reference to the node.
* @param acl
* The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Node node = fNodeDAOService.getNode(nodeRef);
if (node == null)
{
throw new InvalidNodeRefException(nodeRef);
}
node.setAccessControlList(acl);
}
public void updateChangedAcls(NodeRef startingPoint, List<AclChange> changes)
{
// Nothing to do here
}
public List<AclChange> setInheritanceForChildren(NodeRef parent, Long mergeFrom)
{
// Nothing to do here
return Collections.<AclChange> emptyList();
}
public Long getIndirectAcl(NodeRef nodeRef)
{
return getAccessControlList(nodeRef).getId();
}
public Long getInheritedAcl(NodeRef nodeRef)
{
Node node = fNodeDAOService.getNode(nodeRef);
ChildAssoc ca = fNodeDAOService.getPrimaryParentAssoc(node);
if ((ca != null) && (ca.getParent() != null))
{
DbAccessControlList acl = getAccessControlList(ca.getParent().getNodeRef());
if (acl != null)
{
return acl.getId();
}
else
{
return null;
}
}
else
{
return null;
}
}
public void forceCopy(NodeRef nodeRef)
{
// nothing to do;
}
public Map<ACLType, Integer> patchAcls()
{
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.domain.hibernate;
import java.util.Collections;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.security.permissions.ACLType;
import org.alfresco.repo.security.permissions.SimpleAccessControlListProperties;
import org.alfresco.repo.security.permissions.impl.AclChange;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Support for accessing persisted permission information. This class maps between persisted objects and the external
* API defined in the PermissionsDAO interface.
*
* @author andyh
*/
public class OldADMPermissionsDaoComponentImpl extends AbstractPermissionsDaoComponentImpl
{
private static Log logger = LogFactory.getLog(OldADMPermissionsDaoComponentImpl.class);
/**
*
*/
public OldADMPermissionsDaoComponentImpl()
{
super();
}
/**
* Creates an access control list for the node and removes the entry from the nullPermsionCache.
*/
protected AbstractPermissionsDaoComponentImpl.CreationReport createAccessControlList(NodeRef nodeRef, boolean inherit, DbAccessControlList existing)
{
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
properties.setAclType(ACLType.OLD);
properties.setInherits(inherit);
Long id = aclDaoComponent.createAccessControlList(properties);
DbAccessControlList acl = aclDaoComponent.getDbAccessControlList(id);
// maintain inverse
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
// done
if (logger.isDebugEnabled())
{
logger.debug("Created Access Control List: \n" + " node: " + nodeRef + "\n" + " list: " + acl);
}
AbstractPermissionsDaoComponentImpl.CreationReport report = new AbstractPermissionsDaoComponentImpl.CreationReport(acl, Collections.<AclChange>singletonList(new AclDaoComponentImpl.AclChangeImpl(null, id, null, acl.getAclType())));
return report;
}
public void deletePermissions(NodeRef nodeRef)
{
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
if (acl != null)
{
// maintain referencial integrity
getACLDAO(nodeRef).setAccessControlList(nodeRef, null);
aclDaoComponent.deleteAccessControlList(acl.getId());
}
}
}

View File

@@ -5,6 +5,23 @@
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
<hibernate-mapping>
<class
name="org.alfresco.repo.domain.hibernate.DbAccessControlListChangeSetImpl"
proxy="org.alfresco.repo.domain.DbAccessControlListChangeSet"
table="alf_acl_change_set"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
lazy="true"
optimistic-lock="version" >
<!-- auto-generated ID -->
<id name="id" column="id" type="long" >
<generator class="native" />
</id>
<!-- Optimistic locking -->
<version column="version" name="version" type="long" />
</class>
<class
name="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"
proxy="org.alfresco.repo.domain.DbAccessControlList"
@@ -19,67 +36,105 @@
<generator class="native" />
</id>
<version column="version" name="version" type="long" />
<set name="entries"
inverse="true"
lazy="false"
cascade="delete"
optimistic-lock="true"
fetch="join" >
<key column="acl_id" />
<one-to-many class="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl" />
</set>
<natural-id mutable="true">
<property name="aclId" column="acl_id" type="string" length="36"
not-null="true"/>
<property name="latest" column="latest" type="boolean" not-null="true"/>
<property name="aclVersion" column="acl_version" type="long"
not-null="true"/>
<property name="inherits" column="inherits" type="boolean" not-null="true" />
</class>
<class
name="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl"
proxy="org.alfresco.repo.domain.DbAccessControlEntry"
table="alf_access_control_entry"
dynamic-insert="false"
dynamic-update="false"
select-before-update="false"
lazy="true"
optimistic-lock="version" >
<id name="id" column="id" type="long" >
<generator class="native" />
</id>
<natural-id mutable="true" >
<many-to-one
name="accessControlList"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"
column="acl_id"
lazy="no-proxy"
fetch="select"
optimistic-lock="true"
not-null="true" />
<many-to-one
name="permission"
class="org.alfresco.repo.domain.hibernate.DbPermissionImpl"
column="permission_id"
lazy="no-proxy"
fetch="select"
optimistic-lock="true"
not-null="true" />
<many-to-one
name="authority"
class="org.alfresco.repo.domain.hibernate.DbAuthorityImpl"
column="authority_id"
lazy="no-proxy"
fetch="select"
optimistic-lock="true"
not-null="true" />
</natural-id>
<version column="version" name="version" type="long" />
<property name="allowed" column="allowed" type="boolean" not-null="true" />
<property name="inherits" column="inherits" type="boolean" not-null="true" />
<property name="inheritsFrom" column="inherits_from" type="long" not-null="false" />
<property name="type" column="type" type="int" not-null="true" />
<property name="inheritedAclId" column="inherited_acl" type="long" not-null="false" />
<property name="versioned" column="is_versioned" type="boolean" not-null="true" />
<property name="requiresVersion" column="requires_version" type="boolean" not-null="true" />
<many-to-one
name="aclChangeSet"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListChangeSetImpl"
column="acl_change_set"
lazy="proxy"
fetch="select"
unique="false"
not-null="false"
cascade="none" />
</class>
<class
name="org.alfresco.repo.domain.hibernate.DbAccessControlListMemberImpl"
proxy="org.alfresco.repo.domain.DbAccessControlListMember"
table="alf_acl_member" dynamic-insert="false" dynamic-update="false"
select-before-update="false" lazy="true" optimistic-lock="version">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<natural-id mutable="true">
<many-to-one name="accessControlList"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"
column="acl_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
<many-to-one name="accessControlEntry"
class="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl"
column="ace_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
<property name="position" column="pos" type="int"/>
</natural-id>
<version column="version" name="version" type="long"/>
</class>
<class name="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl"
proxy="org.alfresco.repo.domain.DbAccessControlEntry"
table="alf_access_control_entry" dynamic-insert="false"
dynamic-update="false" select-before-update="false" lazy="true"
optimistic-lock="version">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<natural-id>
<many-to-one name="permission"
class="org.alfresco.repo.domain.hibernate.DbPermissionImpl"
column="permission_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
<many-to-one name="authority"
class="org.alfresco.repo.domain.hibernate.DbAuthorityImpl"
column="authority_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
<property name="allowed" column="allowed" type="boolean"
not-null="true"/>
<property name="applies" column="applies" type="int" not-null="true"/>
<many-to-one name="context"
class="org.alfresco.repo.domain.hibernate.DbAccessControlEntryContextImpl"
column="context_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="false"/>
</natural-id>
<version column="version" name="version" type="long"/>
</class>
<class
@@ -115,26 +170,67 @@
lazy="false"
optimistic-lock="version" >
<id name="recipient" column="recipient" type="string" length="100" />
<id name="id" column="id" type="long" >
<generator class="native" />
</id>
<version column="version" name="version" type="long" />
<property name="authority" column="authority" type="string" length="100" unique="true"/>
<set
name="externalKeys"
table="alf_auth_ext_keys"
lazy="true"
sort="unsorted"
fetch="select"
optimistic-lock="true" >
<key >
<column name="id" />
</key>
<element column="externalKey" length="100" not-null="true" type="string" />
</set>
</class>
<class
name="org.alfresco.repo.domain.hibernate.DbAccessControlEntryContextImpl"
proxy="org.alfresco.repo.domain.DbAccessControlEntryContext"
table="alf_ace_context"
dynamic-insert="false"
dynamic-update="false"
select-before-update="false"
lazy="false"
optimistic-lock="version" >
<id name="id" column="id" type="long" >
<generator class="native" />
</id>
<version column="version" name="version" type="long" />
<property name="classContext" column="class_context" type="string" length="1024" />
<property name="propertyContext" column="property_context" type="string" length="1024" />
<property name="kvpContext" column="kvp_context" type="string" length="1024" />
</class>
<class name="org.alfresco.repo.domain.hibernate.DbAuthorityAliasImpl"
proxy="org.alfresco.repo.domain.DbAuthorityAlias"
table="alf_authority_alias" dynamic-insert="false" dynamic-update="false"
select-before-update="false" lazy="false" optimistic-lock="version">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<natural-id mutable="true">
<many-to-one name="authority"
class="org.alfresco.repo.domain.hibernate.DbAuthorityImpl"
column="auth_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
<many-to-one name="alias"
class="org.alfresco.repo.domain.hibernate.DbAuthorityImpl"
column="alias_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
</natural-id>
<version column="version" name="version" type="long"/>
</class>
<query name="permission.GetPermission" cacheable="true">
select distinct
select
permission
from
org.alfresco.repo.domain.hibernate.DbPermissionImpl as permission
@@ -142,7 +238,108 @@
permission.typeQname = :permissionTypeQName and
permission.name = :permissionName
</query>
<query name="permission.GetAuthority" cacheable="true">
select
authority
from
org.alfresco.repo.domain.hibernate.DbAuthorityImpl as authority
where
authority.authority = :authority
</query>
<query name="permission.GetAceWithNoContext" cacheable="true">
select
ace
from
org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl as ace
where
ace.permission.id = :permissionId and
ace.authority.id = :authorityId and
ace.allowed = :allowed and
ace.applies = :applies and
ace.context is null
</query>
<query name="permission.GetAuthorityAlias" cacheable="true">
select
alias
from
org.alfresco.repo.domain.hibernate.DbAuthorityAliasImpl as alias
join alias.authority as authority
join alias.alias as authorityAlias
where
authority.authority = :authority and
authorityAlias.authority = :alias
</query>
<query name="permission.GetAuthorityAliases" cacheable="true">
select
authorityAlias.authority
from
org.alfresco.repo.domain.hibernate.DbAuthorityAliasImpl as alias
join alias.authority as authority
join alias.alias as authorityAlias
where
authority.authority = :authority
</query>
<query name="permission.GetAcesAndAclsByAuthority" cacheable="true">
select
aclmem.id, acl.id, ace.id
from
org.alfresco.repo.domain.hibernate.DbAccessControlListMemberImpl as aclmem
join aclmem.accessControlList as acl
join aclmem.accessControlEntry as ace
join ace.authority as authority
where
authority.authority = :authority
</query>
<query name="permission.GetAcesForAcl" cacheable="true">
select
aclmem
from
org.alfresco.repo.domain.hibernate.DbAccessControlListMemberImpl as aclmem
where
aclmem.accessControlList.id = :id
</query>
<query name="permission.GetAclsThatInheritFromThisAcl" cacheable="true">
select
acl.id
from
org.alfresco.repo.domain.hibernate.DbAccessControlListImpl as acl
where acl.inheritsFrom = :id and acl.inherits = true
</query>
<query name="permission.FindAvmNodesByACL" cacheable="true">
select
node.id
from
org.alfresco.repo.avm.AVMNodeImpl node
where node.acl.id = :acl
</query>
<query name="permission.FindAvmNodesIndirection" cacheable="true">
select
node.id
from
org.alfresco.repo.avm.LayeredDirectoryNodeImpl node
where node.primaryIndirection = true and node.indirection = :indirection
</query>
<query name="permission.FindLatestAclByGuid" cacheable="true">
select
acl.id
from
org.alfresco.repo.domain.hibernate.DbAccessControlListImpl as acl
where acl.aclId = :aclId and latest = true
</query>
<!--
<query name="permission.GetAccessControlEntriesForAuthority">
select
ace
@@ -151,38 +348,28 @@
where
ace.authority.recipient = :authorityRecipient
</query>
<query name="permission.GetAllAccessControlEntriesForAuthority">
select
ace, acl, node
from org.alfresco.repo.domain.hibernate.NodeImpl as node
join node.accessControlList as acl
join acl.entries as ace
join node.accessControlList as acl
join acl.entries as ace
where
ace.authority.recipient = :authorityRecipient
</query>
<query name="permission.FindNodesByPermission">
select
ace, acl, node
from org.alfresco.repo.domain.hibernate.NodeImpl as node
join node.accessControlList as acl
join acl.entries as ace
join node.accessControlList as acl
join acl.entries as ace
where
ace.authority.recipient = :authorityRecipient and
ace.allowed = :allow and
ace.permission.name = :permissionName and
ace.permission.typeQname = :permissionTypeQname
ace.allowed = :allow and
ace.permission.name = :permissionName and
ace.permission.typeQname = :permissionTypeQname
</query>
<query name="permission.patch.GetAccessControlEntriesToChangePermissionOn" >
select
entry
from
org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl entry
where
entry.permission.typeQname = :oldTypeQName and
entry.permission.name = :oldName
</query>
-->
</hibernate-mapping>

View File

@@ -24,226 +24,107 @@
*/
package org.alfresco.repo.domain.hibernate;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.List;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlEntry;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.DbAuthority;
import org.alfresco.repo.domain.DbPermission;
import org.alfresco.repo.domain.DbPermissionKey;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeStatus;
import org.alfresco.repo.security.permissions.NodePermissionEntry;
import org.alfresco.repo.security.permissions.PermissionEntry;
import org.alfresco.repo.security.permissions.PermissionReference;
import org.alfresco.repo.security.permissions.impl.AccessPermissionImpl;
import org.alfresco.repo.security.permissions.impl.PermissionReferenceImpl;
import org.alfresco.repo.security.permissions.impl.PermissionsDaoComponent;
import org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry;
import org.alfresco.repo.security.permissions.impl.SimplePermissionEntry;
import org.alfresco.repo.security.permissions.impl.SimplePermissionReference;
import org.alfresco.repo.transaction.TransactionalDao;
import org.alfresco.repo.domain.hibernate.AbstractPermissionsDaoComponentImpl.CreationReport;
import org.alfresco.repo.security.permissions.ACLType;
import org.alfresco.repo.security.permissions.AccessControlEntry;
import org.alfresco.repo.security.permissions.AccessControlList;
import org.alfresco.repo.security.permissions.SimpleAccessControlListProperties;
import org.alfresco.repo.security.permissions.impl.AclChange;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Support for accessing persisted permission information. This class maps between persisted objects and the external
* API defined in the PermissionsDAO interface.
*
* @author andyh
*/
public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements PermissionsDaoComponent,
TransactionalDao
public class PermissionsDaoComponentImpl extends AbstractPermissionsDaoComponentImpl
{
private static final boolean INHERIT_PERMISSIONS_DEFAULT = true;
public static final String QUERY_GET_PERMISSION = "permission.GetPermission";
public static final String QUERY_GET_AC_ENTRIES_FOR_AUTHORITY = "permission.GetAccessControlEntriesForAuthority";
public static final String QUERY_GET_ALL_AC_ENTRIES_FOR_AUTHORITY = "permission.GetAllAccessControlEntriesForAuthority";
public static final String QUERY_GET_AC_ENTRIES_FOR_PERMISSION = "permission.GetAccessControlEntriesForPermission";
public static final String QUERY_FIND_NODES_BY_PERMISSION = "permission.FindNodesByPermission";
private Map<String, AccessControlListDAO> fProtocolToACLDAO;
private AccessControlListDAO fDefaultACLDAO;
/** a uuid identifying this unique instance */
private String uuid;
/**
*
*/
public PermissionsDaoComponentImpl()
@Override
protected CreationReport createAccessControlList(NodeRef nodeRef, boolean inherit, DbAccessControlList existing)
{
this.uuid = GUID.generate();
}
/**
* Checks equality by type and uuid
*/
public boolean equals(Object obj)
{
if (obj == null)
if (existing == null)
{
return false;
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
properties.setAclType(ACLType.DEFINING);
// Accept default versioning
Long id = aclDaoComponent.createAccessControlList(properties);
List<AclChange> changes = new ArrayList<AclChange>();
DbAccessControlList acl = aclDaoComponent.getDbAccessControlList(id);
changes.add(new AclDaoComponentImpl.AclChangeImpl(null, id, null, acl.getAclType()));
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, aclDaoComponent.getInheritedAccessControlList(id)));
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
return new CreationReport(acl, changes);
}
else if (!(obj instanceof PermissionsDaoComponentImpl))
SimpleAccessControlListProperties properties;
Long id;
List<AclChange> changes;
DbAccessControlList acl;
switch (existing.getAclType())
{
return false;
}
PermissionsDaoComponentImpl that = (PermissionsDaoComponentImpl) obj;
return this.uuid.equals(that.uuid);
}
case OLD:
throw new IllegalStateException("Can not mix old and new style permissions");
case DEFINING:
return new CreationReport(existing, Collections.<AclChange> emptyList());
case FIXED:
case GLOBAL:
case SHARED:
// create new defining, wire up and report changes to acl required.
properties = new SimpleAccessControlListProperties();
properties.setAclType(ACLType.DEFINING);
properties.setInherits(existing.getInherits());
// Accept default versioning
id = aclDaoComponent.createAccessControlList(properties);
changes = new ArrayList<AclChange>();
acl = aclDaoComponent.getDbAccessControlList(id);
changes.add(new AclDaoComponentImpl.AclChangeImpl(existing.getId(), id, existing.getAclType(), acl.getAclType()));
changes.addAll(aclDaoComponent.mergeInheritedAccessControlList(existing.getId(), id));
// set this to inherit to children
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, aclDaoComponent.getInheritedAccessControlList(id)));
/**
* @see #uuid
*/
public int hashCode()
{
return uuid.hashCode();
}
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
return new CreationReport(acl, changes);
case LAYERED:
// Need to get the indirected node ACL
Long indirectAclId = getACLDAO(nodeRef).getIndirectAcl(nodeRef);
Long inheritedAclId = getACLDAO(nodeRef).getInheritedAcl(nodeRef);
/**
* Does this <tt>Session</tt> contain any changes which must be synchronized with the store?
*
* @return true => changes are pending
*/
public boolean isDirty()
{
// create a callback for the task
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
// create new defining, wire up and report changes to acl required.
properties = new SimpleAccessControlListProperties();
properties.setAclType(ACLType.DEFINING);
if (indirectAclId != null)
{
return session.isDirty();
properties.setInherits(aclDaoComponent.getAccessControlListProperties(indirectAclId).getInherits());
}
};
// execute the callback
return ((Boolean) getHibernateTemplate().execute(callback)).booleanValue();
}
// Accept default versioning
id = aclDaoComponent.createAccessControlList(properties);
changes = new ArrayList<AclChange>();
acl = aclDaoComponent.getDbAccessControlList(id);
changes.add(new AclDaoComponentImpl.AclChangeImpl(existing.getId(), id, existing.getAclType(), acl.getAclType()));
if (indirectAclId != null)
{
AccessControlList indirectAcl = aclDaoComponent.getAccessControlList(indirectAclId);
for (AccessControlEntry entry : indirectAcl.getEntries())
{
if (entry.getPosition() == 0)
{
aclDaoComponent.setAccessControlEntry(id, entry);
}
}
}
if (inheritedAclId != null)
{
changes.addAll(aclDaoComponent.mergeInheritedAccessControlList(inheritedAclId, id));
}
// set this to inherit to children
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, aclDaoComponent.getInheritedAccessControlList(id)));
/**
* Just flushes the session
*/
public void flush()
{
getSession().flush();
}
/**
* NO-OP
*/
public void beforeCommit()
{
}
public void setProtocolToACLDAO(Map<String, AccessControlListDAO> map)
{
fProtocolToACLDAO = map;
}
public void setDefaultACLDAO(AccessControlListDAO defaultACLDAO)
{
fDefaultACLDAO = defaultACLDAO;
}
public NodePermissionEntry getPermissions(NodeRef nodeRef)
{
// Create the object if it is not found.
// Null objects are not cached in hibernate
// If the object does not exist it will repeatedly query to check its
// non existence.
NodePermissionEntry npe = null;
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef, false);
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
return new CreationReport(acl, changes);
default:
throw new IllegalStateException("Unknown type " + existing.getAclType());
}
catch (InvalidNodeRefException e)
{
// Do nothing.
}
if (acl == null)
{
// there isn't an access control list for the node - spoof a null one
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections
.<SimplePermissionEntry> emptySet());
npe = snpe;
}
else
{
npe = createSimpleNodePermissionEntry(nodeRef);
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Created access control list for node: \n" + " node: " + nodeRef + "\n" + " acl: " + npe);
}
return npe;
}
/**
* Get the persisted access control list or create it if required.
*
* @param nodeRef -
* the node for which to create the list
* @param create -
* create the object if it is missing
* @return Returns the current access control list or null if not found
*/
private DbAccessControlList getAccessControlList(NodeRef nodeRef, boolean create)
{
DbAccessControlList acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
if (acl == null && create)
{
acl = createAccessControlList(nodeRef);
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Retrieved access control list: \n" + " node: " + nodeRef + "\n" + " list: " + acl);
}
return acl;
}
/**
* Creates an access control list for the node and removes the entry from the nullPermsionCache.
*/
private DbAccessControlList createAccessControlList(NodeRef nodeRef)
{
DbAccessControlList acl = new DbAccessControlListImpl();
acl.setInherits(INHERIT_PERMISSIONS_DEFAULT);
getHibernateTemplate().save(acl);
// maintain inverse
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
// done
if (logger.isDebugEnabled())
{
logger.debug("Created Access Control List: \n" + " node: " + nodeRef + "\n" + " list: " + acl);
}
return acl;
}
public void deletePermissions(NodeRef nodeRef)
@@ -251,7 +132,7 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef, false);
acl = getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
@@ -259,422 +140,32 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
}
if (acl != null)
{
// maintain referencial integrity
getACLDAO(nodeRef).setAccessControlList(nodeRef, null);
// delete the access control list - it will cascade to the entries
getHibernateTemplate().delete(acl);
}
}
@SuppressWarnings("unchecked")
public void deletePermissions(final String authority)
{
// get the authority
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
if (acl.getInheritsFrom() != null)
{
Query query = session.getNamedQuery(QUERY_GET_AC_ENTRIES_FOR_AUTHORITY).setString("authorityRecipient",
authority);
return (Integer) HibernateHelper.deleteDbAccessControlEntries(session, query);
Long deleted = acl.getId();
Long inheritsFrom = acl.getInheritsFrom();
getACLDAO(nodeRef).setAccessControlList(nodeRef, aclDaoComponent.getDbAccessControlList(inheritsFrom));
aclDaoComponent.deleteAccessControlList(acl.getId());
List<AclChange> changes = new ArrayList<AclChange>();
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, inheritsFrom));
getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
}
};
Integer deletedCount = (Integer) getHibernateTemplate().execute(callback);
// done
if (logger.isDebugEnabled())
{
logger.debug("Deleted " + deletedCount + " entries for authority " + authority);
}
}
public void deletePermissions(final NodeRef nodeRef, final String authority)
{
DbAccessControlList acl = null;
try
{
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
int deletedCount = 0;
if (acl != null)
{
deletedCount = acl.deleteEntriesForAuthority(authority);
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Deleted "
+ deletedCount + "entries for criteria: \n" + " node: " + nodeRef + "\n" + " authority: "
+ authority);
}
}
/**
* Deletes all permission entries (access control list entries) that match the given criteria. Note that the access
* control list for the node is not deleted.
*/
public void deletePermission(NodeRef nodeRef, String authority, PermissionReference permission)
{
DbAccessControlList acl = null;
try
{
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
int deletedCount = 0;
if (acl != null)
{
DbPermissionKey permissionKey = new DbPermissionKey(permission.getQName(), permission.getName());
deletedCount = acl.deleteEntry(authority, permissionKey);
}
// done
if (logger.isDebugEnabled())
{
logger.debug("Deleted "
+ deletedCount + "entries for criteria: \n" + " node: " + nodeRef + "\n" + " permission: "
+ permission + "\n" + " authority: " + authority);
}
}
public void setPermission(NodeRef nodeRef, String authority, PermissionReference permission, boolean allow)
{
// get the entry
DbAccessControlEntry entry = getAccessControlEntry(nodeRef, authority, permission);
if (entry == null)
{
// need to create it
DbAccessControlList dbAccessControlList = getAccessControlList(nodeRef, true);
DbPermission dbPermission = getPermission(permission, true);
DbAuthority dbAuthority = getAuthority(authority, true);
// set persistent objects
entry = dbAccessControlList.newEntry(dbPermission, dbAuthority, allow);
// done
if (logger.isDebugEnabled())
else
{
logger.debug("Created new access control entry: " + entry);
}
}
else
{
entry.setAllowed(allow);
// done
if (logger.isDebugEnabled())
{
logger.debug("Updated access control entry: " + entry);
// TODO: could just cear out existing
Long deleted = acl.getId();
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
properties.setAclType(ACLType.DEFINING);
properties.setInherits(Boolean.FALSE);
// Accept default versioning
Long id = aclDaoComponent.createAccessControlList(properties);
getACLDAO(nodeRef).setAccessControlList(nodeRef, aclDaoComponent.getDbAccessControlList(id));
aclDaoComponent.deleteAccessControlList(acl.getId());
List<AclChange> changes = new ArrayList<AclChange>();
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, id));
getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
}
}
}
/**
* @param nodeRef
* the node against which to join
* @param authority
* the authority against which to join
* @param perm
* the permission against which to join
* @return Returns all access control entries that match the criteria
*/
private DbAccessControlEntry getAccessControlEntry(NodeRef nodeRef, String authority, PermissionReference permission)
{
DbAccessControlList acl = getAccessControlList(nodeRef, false);
DbAccessControlEntry entry = null;
if (acl != null)
{
DbPermissionKey permissionKey = new DbPermissionKey(permission.getQName(), permission.getName());
entry = acl.getEntry(authority, permissionKey);
}
// done
if (logger.isDebugEnabled())
{
logger.debug(""
+ (entry == null ? "Did not find" : "Found") + " entry for criteria: \n" + " node: " + nodeRef
+ "\n" + " authority: " + authority + "\n" + " permission: " + permission);
}
return entry;
}
/**
* Utility method to find or create a persisted authority
*/
private DbAuthority getAuthority(String authority, boolean create)
{
DbAuthority entity = (DbAuthority) getHibernateTemplate().get(DbAuthorityImpl.class, authority);
if ((entity == null) && create)
{
entity = new DbAuthorityImpl();
entity.setRecipient(authority);
getHibernateTemplate().save(entity);
return entity;
}
else
{
return entity;
}
}
/**
* Utility method to find and optionally create a persisted permission.
*/
private DbPermission getPermission(PermissionReference permissionRef, final boolean create)
{
final QName qname = permissionRef.getQName();
final String name = permissionRef.getName();
Session session = getSession();
DbPermission dbPermission = DbPermissionImpl.find(session, qname, name);
// create if necessary
if ((dbPermission == null) && create)
{
dbPermission = new DbPermissionImpl();
dbPermission.setTypeQname(qname);
dbPermission.setName(name);
getHibernateTemplate().save(dbPermission);
}
return dbPermission;
}
public void setPermission(PermissionEntry permissionEntry)
{
setPermission(permissionEntry.getNodeRef(), permissionEntry.getAuthority(), permissionEntry
.getPermissionReference(), permissionEntry.isAllowed());
}
public void setPermission(NodePermissionEntry nodePermissionEntry)
{
NodeRef nodeRef = nodePermissionEntry.getNodeRef();
// Get the access control list
// Note the logic here requires to know whether it was created or not
DbAccessControlList acl = getAccessControlList(nodeRef, false);
if (acl != null)
{
// maintain referencial integrity
getACLDAO(nodeRef).setAccessControlList(nodeRef, null);
// drop the list
getHibernateTemplate().delete(acl);
}
// create the access control list
acl = createAccessControlList(nodeRef);
// set attributes
acl.setInherits(nodePermissionEntry.inheritPermissions());
// add all entries
for (PermissionEntry pe : nodePermissionEntry.getPermissionEntries())
{
PermissionReference permission = pe.getPermissionReference();
String authority = pe.getAuthority();
boolean isAllowed = pe.isAllowed();
DbPermission permissionEntity = getPermission(permission, true);
DbAuthority authorityEntity = getAuthority(authority, true);
@SuppressWarnings("unused")
DbAccessControlEntryImpl entry = acl.newEntry(permissionEntity, authorityEntity, isAllowed);
}
}
public void setInheritParentPermissions(NodeRef nodeRef, boolean inheritParentPermissions)
{
DbAccessControlList acl = null;
if (!inheritParentPermissions)
{
// Inheritance == true is the default, so only force a create of the ACL if the value false
acl = getAccessControlList(nodeRef, true);
acl.setInherits(false);
}
else
{
acl = getAccessControlList(nodeRef, false);
if (acl != null)
{
acl.setInherits(true);
}
}
}
public boolean getInheritParentPermissions(NodeRef nodeRef)
{
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef, false);
}
catch (InvalidNodeRefException e)
{
return INHERIT_PERMISSIONS_DEFAULT;
}
if (acl == null)
{
return true;
}
else
{
return acl.getInherits();
}
}
// Utility methods to create simple detached objects for the outside world
// We do not pass out the hibernate objects
private SimpleNodePermissionEntry createSimpleNodePermissionEntry(NodeRef nodeRef)
{
DbAccessControlList acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
if (acl == null)
{
// there isn't an access control list for the node - spoof a null one
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections
.<SimplePermissionEntry> emptySet());
return snpe;
}
else
{
Set<DbAccessControlEntry> entries = acl.getEntries();
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, acl.getInherits(),
createSimplePermissionEntries(nodeRef, entries));
return snpe;
}
}
/**
* @param entries
* access control entries
* @return Returns a unique set of entries that can be given back to the outside world
*/
private Set<SimplePermissionEntry> createSimplePermissionEntries(NodeRef nodeRef,
Collection<DbAccessControlEntry> entries)
{
if (entries == null)
{
return null;
}
HashSet<SimplePermissionEntry> spes = new HashSet<SimplePermissionEntry>(entries.size(), 1.0f);
if (entries.size() != 0)
{
for (DbAccessControlEntry entry : entries)
{
spes.add(createSimplePermissionEntry(nodeRef, entry));
}
}
return spes;
}
private static SimplePermissionEntry createSimplePermissionEntry(NodeRef nodeRef, DbAccessControlEntry ace)
{
if (ace == null)
{
return null;
}
return new SimplePermissionEntry(nodeRef, createSimplePermissionReference(ace.getPermission()), ace
.getAuthority().getRecipient(), ace.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED);
}
private static SimplePermissionReference createSimplePermissionReference(DbPermission perm)
{
if (perm == null)
{
return null;
}
return new SimplePermissionReference(perm.getTypeQname(), perm.getName());
}
/**
* Helper to choose appropriate NodeService for the given NodeRef
*
* @param nodeRef
* The NodeRef to dispatch from.
* @return The appropriate NodeService.
*/
private AccessControlListDAO getACLDAO(NodeRef nodeRef)
{
AccessControlListDAO ret = fProtocolToACLDAO.get(nodeRef.getStoreRef().getProtocol());
if (ret == null)
{
return fDefaultACLDAO;
}
return ret;
}
@SuppressWarnings("unchecked")
public Map<NodeRef, Set<AccessPermission>> getAllSetPermissions(final String authority)
{
// get the authority
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
Query query = session.getNamedQuery(QUERY_GET_ALL_AC_ENTRIES_FOR_AUTHORITY).setString(
"authorityRecipient", authority);
Map<NodeRef, Set<AccessPermission>> result = new HashMap<NodeRef, Set<AccessPermission>>();
ScrollableResults entities = query.scroll(ScrollMode.FORWARD_ONLY);
while (entities.next())
{
DbAccessControlEntry entry = (DbAccessControlEntry) entities.get(0);
// DbAccessControlList acl = (DbAccessControlList) entities.get(1);
Node node = (Node) entities.get(2);
DbPermission dbPermission = entry.getPermission();
PermissionReferenceImpl pr = new PermissionReferenceImpl(dbPermission.getTypeQname(), dbPermission
.getName());
AccessStatus accessStatus = entry.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED;
AccessPermission ap = new AccessPermissionImpl(pr.toString(), accessStatus, entry.getAuthority()
.getRecipient());
NodeRef nodeRef = node.getNodeRef();
Set<AccessPermission> nodeSet = result.get(nodeRef);
if (nodeSet == null)
{
nodeSet = new HashSet<AccessPermission>();
result.put(nodeRef, nodeSet);
}
nodeSet.add(ap);
}
return result;
}
};
return (Map<NodeRef, Set<AccessPermission>>) getHibernateTemplate().execute(callback);
}
public Set<NodeRef> findNodeByPermission(final String authority, final PermissionReference permission, final boolean allow)
{
// get the authority
HibernateCallback callback = new HibernateCallback()
{
public Object doInHibernate(Session session)
{
Query query = session.getNamedQuery(QUERY_FIND_NODES_BY_PERMISSION).setString(
"authorityRecipient", authority).setBoolean("allow", allow).setString("permissionName", permission.getName()).setString("permissionTypeQname", permission.getQName().toString());
Set<NodeRef> result = new HashSet<NodeRef>();
ScrollableResults entities = query.scroll(ScrollMode.FORWARD_ONLY);
while (entities.next())
{
DbAccessControlEntry entry = (DbAccessControlEntry) entities.get(0);
// DbAccessControlList acl = (DbAccessControlList) entities.get(1);
Node node = (Node) entities.get(2);
DbPermission dbPermission = entry.getPermission();
PermissionReferenceImpl pr = new PermissionReferenceImpl(dbPermission.getTypeQname(), dbPermission
.getName());
AccessStatus accessStatus = entry.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED;
AccessPermission ap = new AccessPermissionImpl(pr.toString(), accessStatus, entry.getAuthority()
.getRecipient());
NodeRef nodeRef = node.getNodeRef();
result.add(nodeRef);
}
return result;
}
};
return (Set<NodeRef>) getHibernateTemplate().execute(callback);
}
}

View File

@@ -390,7 +390,7 @@ public class LockServiceImpl implements LockService,
* @param userName the user name
* @return the lock status
*/
private LockStatus getLockStatus(NodeRef nodeRef, String userName)
public LockStatus getLockStatus(NodeRef nodeRef, String userName)
{
LockStatus result = LockStatus.NO_LOCK;

View File

@@ -0,0 +1,25 @@
package org.alfresco.repo.search.impl.lucene.analysis;
import java.io.Reader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.ISOLatin1AccentFilter;
import org.apache.lucene.analysis.TokenStream;
public class FrenchSnowballAnalyserThatRemovesAccents extends Analyzer
{
Analyzer analyzer = new FrenchSnowballAnalyser();
public FrenchSnowballAnalyserThatRemovesAccents()
{
}
public TokenStream tokenStream(String fieldName, Reader reader)
{
TokenStream result = analyzer.tokenStream(fieldName, reader);
result = new ISOLatin1AccentFilter(result);
return result;
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
/**
* The ACE Type
* @author andyh
*
*/
public enum ACEType
{
/**
* ACE applies to the object and its children
*/
ALL
{
public int getId()
{
return 0;
}
},
/**
* ACE applies to the object only
*/
OBJECT
{
public int getId()
{
return 1;
}
},
/**
* ACE only applies to children
*/
CHILDREN
{
public int getId()
{
return 2;
}
};
/**
* Get the id for the ACEType stored in the DB.
* @return
*/
public abstract int getId();
/**
* Get the ACEType from the value stored in the DB.
* @param id
* @return
*/
public static ACEType getACETypeFromId(int id)
{
switch(id)
{
case 0:
return ACEType.ALL;
case 1:
return ACEType.OBJECT;
case 2:
return ACEType.CHILDREN;
default:
throw new IllegalArgumentException("Unknown ace type "+id);
}
}
}

View File

@@ -0,0 +1,6 @@
package org.alfresco.repo.security.permissions;
public enum ACLCopyMode
{
COPY, COW, INHERIT, REDIRECT;
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
/**
* The ACL Type
*
* @author andyh
*
*/
public enum ACLType
{
/**
* Old style permissions that require a parent wlak to resolve
*/
OLD
{
public int getId()
{
return 0;
}
},
/**
* Defining permission - not reused anywhere
*/
DEFINING
{
public int getId()
{
return 1;
}
},
/**
* Shared permission, reused for inhertiance from defining permission
*/
SHARED
{
public int getId()
{
return 2;
}
},
/**
* An ACL defined in its own right - there is no inheriance context
*
*/
FIXED
{
public int getId()
{
return 3;
}
},
/**
* A single instance for global permissions
*/
GLOBAL
{
public int getId()
{
return 4;
}
},
/**
* Layered types
*/
LAYERED
{
public int getId()
{
return 5;
}
};
/**
* Get the id for the ACLType stored in the DB
*
* @return
*/
public abstract int getId();
/**
* Get the ACLType from the value stored in the DB
* @param id
* @return
*/
public static ACLType getACLTypeFromId(int id)
{
switch(id)
{
case 0:
return ACLType.OLD;
case 1:
return ACLType.DEFINING;
case 2:
return ACLType.SHARED;
case 3:
return ACLType.FIXED;
case 4:
return ACLType.GLOBAL;
case 5:
return ACLType.LAYERED;
default:
throw new IllegalArgumentException("Unknown acl type "+id);
}
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
import org.alfresco.service.cmr.security.AccessStatus;
public interface AccessControlEntry extends Comparable<AccessControlEntry>
{
public Integer getPosition();
public PermissionReference getPermission();
public String getAuthority();
public AccessStatus getAccessStatus();
public ACEType getAceType();
public AccessControlEntryContext getContext();
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
public interface AccessControlEntryContext
{
/**
* Get the class context.
*
* This is a space separated list of QNames
* with an optional + or minus
*
* +QName => Must be of this type or have the aspect
* -Qname => Must not be of this type or have the aspect
* +QName +QName +QName => Must have all of these types
* -QName -Qname => Must not have any of these types
* QName QName QName => Must have one of the types
* QName => requires exact type match
* QName~ => requires a match on the type or subtype
*
* Supports () for grouping
*
* @return
*/
public String getClassContext();
/**
* Get the property context
*
* QName QName Qname => property types to which it applies
*
* @return
*/
public String getPropertyContext();
/**
* Get the key value pair context
*
* Serialized Map
*
* @return
*/
public String getKVPContext();}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
import java.util.List;
public interface AccessControlList
{
/**
* Get the properties
* @return
*/
public AccessControlListProperties getProperties();
/**
* Get the members of the ACL in order
* Ordered by:
* position,
* then deny followed by allow,
* then by authority type
* then ....
*
* To make permission evaluation faster for the common cases
*
* @return
*/
public List<AccessControlEntry> getEntries();
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
public interface AccessControlListProperties
{
/**
* Get the ACL ID
* @return
*/
public String getAclId();
/**
* Get the ACL version
* @return
*/
public Long getAclVersion();
/**
* Is this the latest version of the acl identified by the acl id string?
* @return
*/
public Boolean isLatest();
/**
* Get inheritance behaviour
* @return Returns the inheritance status of this list
*/
public Boolean getInherits();
/**
* Get the type for this ACL
*
* @return
*/
public ACLType getAclType();
/**
* Is this ACL versioned - if not there will be no old versions of the ACL
* and the long id will remain unchanged.
*
* If an acl is versioned it can not be updated - a new copy has to be created,
*
* @return
*/
public Boolean isVersioned();
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthorityType;
public class SimpleAccessControlEntry implements AccessControlEntry
{
private AccessStatus accessStatus;
private ACEType aceType;
private String authority;
private AccessControlEntryContext context;
private PermissionReference permission;
private Integer position;
public AccessStatus getAccessStatus()
{
return accessStatus;
}
public ACEType getAceType()
{
return aceType;
}
public String getAuthority()
{
return authority;
}
public AccessControlEntryContext getContext()
{
return context;
}
public PermissionReference getPermission()
{
return permission;
}
public Integer getPosition()
{
return position;
}
public void setAccessStatus(AccessStatus accessStatus)
{
this.accessStatus = accessStatus;
}
public void setAceType(ACEType aceType)
{
this.aceType = aceType;
}
public void setAuthority(String authority)
{
this.authority = authority;
}
public void setContext(AccessControlEntryContext context)
{
this.context = context;
}
public void setPermission(PermissionReference permission)
{
this.permission = permission;
}
public void setPosition(Integer position)
{
this.position = position;
}
public int compareTo(AccessControlEntry other)
{
int diff = this.getPosition() - other.getPosition();
if(diff == 0)
{
diff = (this.getAccessStatus()== AccessStatus.DENIED ? 0 : 1) - (other.getAccessStatus()== AccessStatus.DENIED ? 0 : 1);
if(diff == 0)
{
return AuthorityType.getAuthorityType(this.getAuthority()).getOrderPosition() - AuthorityType.getAuthorityType(other.getAuthority()).getOrderPosition();
}
else
{
return diff;
}
}
else
{
return diff;
}
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
public class SimpleAccessControlEntryContext implements AccessControlEntryContext
{
private String classContext;
private String KVPContext;
private String propertyContext;
public String getClassContext()
{
return classContext;
}
public String getKVPContext()
{
return KVPContext;
}
public String getPropertyContext()
{
return propertyContext;
}
public void setClassContext(String classContext)
{
this.classContext = classContext;
}
public void setKVPContext(String context)
{
KVPContext = context;
}
public void setPropertyContext(String propertyContext)
{
this.propertyContext = propertyContext;
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.repo.security.permissions;
import java.util.ArrayList;
import java.util.List;
public class SimpleAccessControlList implements AccessControlList
{
private AccessControlListProperties properties;
private List<AccessControlEntry> entries = new ArrayList<AccessControlEntry>();
public List<AccessControlEntry> getEntries()
{
return entries;
}
public AccessControlListProperties getProperties()
{
return properties;
}
public void setEntries(List<AccessControlEntry> entries)
{
this.entries = entries;
}
public void setProperties(AccessControlListProperties properties)
{
this.properties = properties;
}
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions;
public class SimpleAccessControlListProperties implements AccessControlListProperties
{
private String aclId;
private ACLType aclType;
private Long aclVersion;
private Boolean inherits;
private Boolean latest;
private Boolean versioned;
public String getAclId()
{
return aclId;
}
public ACLType getAclType()
{
return aclType;
}
public Long getAclVersion()
{
return aclVersion;
}
public Boolean getInherits()
{
return inherits;
}
public Boolean isLatest()
{
return latest;
}
public Boolean isVersioned()
{
return versioned;
}
public void setAclId(String aclId)
{
this.aclId = aclId;
}
public void setAclType(ACLType aclType)
{
this.aclType = aclType;
}
public void setAclVersion(Long aclVersion)
{
this.aclVersion = aclVersion;
}
public void setInherits(boolean inherits)
{
this.inherits = inherits;
}
public void setLatest(boolean latest)
{
this.latest = latest;
}
public void setVersioned(boolean versioned)
{
this.versioned = versioned;
}
}

View File

@@ -27,6 +27,8 @@ package org.alfresco.repo.security.permissions.dynamic;
import java.io.Serializable;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.DynamicAuthority;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
@@ -34,6 +36,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.util.EqualsHelper;
import org.springframework.beans.factory.InitializingBean;
/**
@@ -46,33 +49,41 @@ public class LockOwnerDynamicAuthority implements DynamicAuthority, Initializing
private NodeService nodeService;
public boolean hasAuthority(NodeRef nodeRef, String userName)
public boolean hasAuthority(final NodeRef nodeRef, final String userName)
{
if (lockService.getLockStatus(nodeRef) == LockStatus.LOCK_OWNER)
{
return true;
}
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY))
{
NodeRef original = null;
Serializable reference = nodeService.getProperty(nodeRef, ContentModel.PROP_COPY_REFERENCE);
if (reference != null)
return AuthenticationUtil.runAs(new RunAsWork<Boolean>(){
public Boolean doWork() throws Exception
{
original = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, reference);
}
if (original != null && nodeService.exists(original))
{
return (lockService.getLockStatus(original) == LockStatus.LOCK_OWNER);
}
else
{
return false;
}
}
else
{
return false;
}
if (lockService.getLockStatus(nodeRef, userName) == LockStatus.LOCK_OWNER)
{
return true;
}
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY))
{
NodeRef original = null;
Serializable reference = nodeService.getProperty(nodeRef, ContentModel.PROP_COPY_REFERENCE);
if (reference != null)
{
original = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, reference);
}
if (original != null && nodeService.exists(original))
{
return (lockService.getLockStatus(original, userName) == LockStatus.LOCK_OWNER);
}
else
{
return false;
}
}
else
{
return false;
}
}}, AuthenticationUtil.getSystemUserName());
}
public String getAuthority()

View File

@@ -24,6 +24,8 @@
*/
package org.alfresco.repo.security.permissions.dynamic;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.DynamicAuthority;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.OwnableService;
@@ -53,9 +55,16 @@ public class OwnerDynamicAuthority implements DynamicAuthority, InitializingBean
}
}
public boolean hasAuthority(NodeRef nodeRef, String userName)
public boolean hasAuthority(final NodeRef nodeRef, final String userName)
{
return EqualsHelper.nullSafeEquals(ownableService.getOwner(nodeRef), userName);
return AuthenticationUtil.runAs(new RunAsWork<Boolean>(){
public Boolean doWork() throws Exception
{
// TODO Auto-generated method stub
return EqualsHelper.nullSafeEquals(ownableService.getOwner(nodeRef), userName);
}}, AuthenticationUtil.getSystemUserName());
}
public String getAuthority()

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions.impl;
import org.alfresco.repo.security.permissions.ACLType;
/**
*
* @author andyh
*
*/
public interface AclChange
{
public Long getBefore();
public Long getAfter();
public ACLType getTypeAfter();
public ACLType getTypeBefore();
}

View File

@@ -0,0 +1,184 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions.impl;
import java.util.List;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.repo.security.permissions.AccessControlEntry;
import org.alfresco.repo.security.permissions.AccessControlList;
import org.alfresco.repo.security.permissions.AccessControlListProperties;
import org.alfresco.repo.transaction.TransactionalDao;
/**
* DAO component for creating, deleting, manipulating and finding ACLs and associated ACEs and anc ACE context.
*
* @author andyh
*/
public interface AclDaoComponent extends TransactionalDao
{
/**
* Temp support to get a DBAccessControlList to wire up ...
*
* @param id
* @return
*/
DbAccessControlList getDbAccessControlList(Long id);
/**
* Get an ACL id.
*
* @param id
* @return
*/
public AccessControlList getAccessControlList(Long id);
/**
* Delete an ACL
*
* @param id
* @return - the id of all ACLs affected
*/
public List<AclChange> deleteAccessControlList(Long id);
/**
* Delete the ACEs in position 0 (those set directly on the ACL and not inherited) Cleans up existing acls
*
* @param id
* @return - the id of all ACLs affected
*/
public List<AclChange> deleteLocalAccessControlEntries(Long id);
/**
* Delete the ACEs in position > 0 (those not set directly on the ACL but inherited) No affect on any other acl
*
* @param id
* @return - the id of all ACLs affected
*/
public List<AclChange> deleteInheritedAccessControlEntries(Long id);
/**
* Mark all ACEs that reference this authority as no longer valid - the authority has been deleted
*
* @param authority
* @return - the id of all ACLs affected
*/
public List<AclChange> invalidateAccessControlEntries(String authority);
/**
* Delete all ACEs that reference this authority as no longer valid. THIS DOES NOT CAUSE ANY ACL TO VERSION
*
* @param authority
* @return - the id of all ACLs affected
*/
public List<AclChange> deleteAccessControlEntries(String authority);
/**
* Delete some locally set ACLs according to the pattern
*
* @param id
* @param pattern -
* non null elements are used for the match
* @return - the id of all ACLs affected
*/
public List<AclChange> deleteAccessControlEntries(Long id, AccessControlEntry pattern);
/**
* Add an access control entry
*
* @param id
* @param ace
* @return - the id of all ACLs affected
*/
public List<AclChange> setAccessControlEntry(Long id, AccessControlEntry ace);
/**
* Enable inheritance
*
* @param id
* @param parent
* @return
*/
public List<AclChange> enableInheritance(Long id, Long parent);
/**
* Disable inheritance
*
* @param id
* @param setInheritedOnAcl
* @return
*/
public List<AclChange> disableInheritance(Long id, boolean setInheritedOnAcl);
/**
* Get the ACL properties
*
* @param id
* @return - the id of all ACLs affected
*/
public AccessControlListProperties getAccessControlListProperties(Long id);
/**
* Create a bew ACL with teh given properties. Unset ones are assigned defaults.
*
* @param properties
* @return
*/
public Long createAccessControlList(AccessControlListProperties properties);
/**
* Get the id of the ACL inherited from the one given
* May return null if there is nothing to inherit -> OLD world where nodes have thier own ACL and we wlak the parent chain
*
* @param id
* @return
*/
public Long getInheritedAccessControlList(Long id);
/**
* Merge inherited ACEs in to target - the merged ACEs will go in at thier current position +1
*
* @param inherited
* @param target
* @return
*/
public List<AclChange> mergeInheritedAccessControlList(Long inherited, Long target);
public DbAccessControlList getDbAccessControlListCopy(Long toCopy, Long toInheritFrom, ACLCopyMode mode);
public Long getCopy(Long toCopy, Long toInheritFrom, ACLCopyMode mode);
public List<Long> getAvmNodesByACL(Long id);
public List<Long> getAvmNodesByIndirection(final String indirection);
/**
* hibernate lifecycle support
* @param id
*/
public void onDeleteAccessControlList(final long id);
}

File diff suppressed because it is too large Load Diff

View File

@@ -46,6 +46,16 @@ public interface ModelDAO
* @return
*/
public Set<PermissionReference> getAllPermissions(QName type);
/**
* Get the permissions that can be set for the given type.
*
* @param type - the type in the data dictionary.
* @param aspects
* @return
*/
public Set<PermissionReference> getAllPermissions(QName type, Set<QName> aspects);
/**
* Get the permissions that can be set for the given node.

View File

@@ -40,6 +40,10 @@ import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessControlEntry;
import org.alfresco.repo.security.permissions.AccessControlList;
import org.alfresco.repo.security.permissions.DynamicAuthority;
import org.alfresco.repo.security.permissions.NodePermissionEntry;
import org.alfresco.repo.security.permissions.PermissionEntry;
@@ -53,6 +57,7 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.PermissionContext;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -64,7 +69,7 @@ import org.springframework.beans.factory.InitializingBean;
/**
* The Alfresco implementation of a permissions service against our APIs for the permissions model and permissions
* persistence.
*
*
* @author andyh
*/
public class PermissionServiceImpl implements PermissionServiceSPI, InitializingBean
@@ -120,6 +125,8 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
private PolicyComponent policyComponent;
private AclDaoComponent aclDaoComponent;
/*
* Standard spring construction.
*/
@@ -172,9 +179,14 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
this.dynamicAuthorities = dynamicAuthorities;
}
public void setAclDaoComponent(AclDaoComponent aclDaoComponent)
{
this.aclDaoComponent = aclDaoComponent;
}
/**
* Set the permissions access cache.
*
*
* @param accessCache
* a transactionally safe cache
*/
@@ -227,6 +239,10 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
{
throw new IllegalArgumentException("Property 'policyComponent' has not been set");
}
if (aclDaoComponent == null)
{
throw new IllegalArgumentException("Property 'aclDaoComponent' has not been set");
}
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onMoveNode"), ContentModel.TYPE_BASE, new JavaBehaviour(this, "onMoveNode"));
@@ -315,20 +331,20 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
return permissionsDaoComponent.getPermissions(tenantService.getName(nodeRef));
}
public AccessStatus hasPermission(NodeRef nodeRef, PermissionReference perm)
public AccessStatus hasPermission(final NodeRef nodeRefIn, final PermissionReference permIn)
{
// If the node ref is null there is no sensible test to do - and there
// must be no permissions
// - so we allow it
if (nodeRef == null)
if (nodeRefIn == null)
{
return AccessStatus.ALLOWED;
}
nodeRef = tenantService.getName(nodeRef);
final NodeRef nodeRef = tenantService.getName(nodeRefIn);
// If the permission is null we deny
if (perm == null)
if (permIn == null)
{
return AccessStatus.DENIED;
}
@@ -339,24 +355,36 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
return AccessStatus.ALLOWED;
}
final PermissionReference perm;
if (permIn.equals(OLD_ALL_PERMISSIONS_REFERENCE))
{
perm = getAllPermissionReference();
}
else
{
perm = permIn;
}
// Get the current authentications
// Use the smart authentication cache to improve permissions performance
Authentication auth = authenticationComponent.getCurrentAuthentication();
Set<String> authorisations = getAuthorisations(auth, nodeRef);
Serializable key = generateKey(authorisations, nodeRef, perm, CacheType.HAS_PERMISSION);
AccessStatus status = accessCache.get(key);
if (status != null)
{
return status;
}
final Set<String> authorisations = getAuthorisations(auth, nodeRef);
// If the node does not support the given permission there is no point
// doing the test
Set<PermissionReference> available = modelDAO.getAllPermissions(nodeRef);
Set<PermissionReference> available = AuthenticationUtil.runAs(new RunAsWork<Set<PermissionReference>>()
{
public Set<PermissionReference> doWork() throws Exception
{
return modelDAO.getAllPermissions(nodeRef);
}
}, AuthenticationUtil.getSystemUserName());
available.add(getAllPermissionReference());
available.add(OLD_ALL_PERMISSIONS_REFERENCE);
final Serializable key = generateKey(authorisations, nodeRef, perm, CacheType.HAS_PERMISSION);
if (!(available.contains(perm)))
{
accessCache.put(key, AccessStatus.DENIED);
@@ -368,42 +396,108 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
return AccessStatus.ALLOWED;
}
//
// TODO: Dynamic permissions via evaluators
//
/*
* Does the current authentication have the supplied permission on the given node.
*/
QName typeQname = nodeService.getType(nodeRef);
Set<QName> aspectQNames = nodeService.getAspects(nodeRef);
if (perm.equals(OLD_ALL_PERMISSIONS_REFERENCE))
return AuthenticationUtil.runAs(new RunAsWork<AccessStatus>()
{
perm = getAllPermissionReference();
}
NodeTest nt = new NodeTest(perm, typeQname, aspectQNames);
boolean result = nt.evaluate(authorisations, nodeRef);
if (log.isDebugEnabled())
{
log.debug("Permission <"
+ perm + "> is " + (result ? "allowed" : "denied") + " for " + authenticationComponent.getCurrentUserName() + " on node " + nodeService.getPath(nodeRef));
}
status = result ? AccessStatus.ALLOWED : AccessStatus.DENIED;
accessCache.put(key, status);
return status;
public AccessStatus doWork() throws Exception
{
AccessStatus status = accessCache.get(key);
if (status != null)
{
return status;
}
//
// TODO: Dynamic permissions via evaluators
//
/*
* Does the current authentication have the supplied permission on the given node.
*/
QName typeQname = nodeService.getType(nodeRef);
Set<QName> aspectQNames = nodeService.getAspects(nodeRef);
NodeTest nt = new NodeTest(perm, typeQname, aspectQNames);
boolean result = nt.evaluate(authorisations, nodeRef);
if (log.isDebugEnabled())
{
log.debug("Permission <"
+ perm + "> is " + (result ? "allowed" : "denied") + " for " + authenticationComponent.getCurrentUserName() + " on node "
+ nodeService.getPath(nodeRef));
}
status = result ? AccessStatus.ALLOWED : AccessStatus.DENIED;
accessCache.put(key, status);
return status;
}
}, AuthenticationUtil.getSystemUserName());
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.security.PermissionService#hasPermission(java.lang.Long, java.lang.String, java.lang.String)
/*
* (non-Javadoc)
*
* @see org.alfresco.service.cmr.security.PermissionService#hasPermission(java.lang.Long, java.lang.String,
* java.lang.String)
*/
public AccessStatus hasPermission(Long aclID, Map<String, Object> context,
String permission)
public AccessStatus hasPermission(Long aclID, PermissionContext context, String permission)
{
// TODO Implement.
return AccessStatus.ALLOWED;
return hasPermission(aclID, context, getPermissionReference(permission));
}
public AccessStatus hasPermission(Long aclId, PermissionContext context, PermissionReference permission)
{
if (aclId == null)
{
return AccessStatus.ALLOWED;
}
if (permission == null)
{
return AccessStatus.DENIED;
}
// Get the current authentications
// Use the smart authentication cache to improve permissions performance
Authentication auth = authenticationComponent.getCurrentAuthentication();
if (auth == null)
{
throw new IllegalStateException("Unauthenticated");
}
Set<String> authorisations = getAuthorisations(auth, context);
// If the node does not support the given permission there is no point
// doing the test
QName typeQname = context.getType();
Set<QName> aspectQNames = context.getAspects();
Set<PermissionReference> available = modelDAO.getAllPermissions(typeQname, aspectQNames);
available.add(getAllPermissionReference());
available.add(OLD_ALL_PERMISSIONS_REFERENCE);
if (!(available.contains(permission)))
{
return AccessStatus.DENIED;
}
if (authenticationComponent.getCurrentUserName().equals(authenticationComponent.getSystemUserName()))
{
return AccessStatus.ALLOWED;
}
if (permission.equals(OLD_ALL_PERMISSIONS_REFERENCE))
{
permission = getAllPermissionReference();
}
AclTest aclTest = new AclTest(permission, typeQname, aspectQNames);
boolean result = aclTest.evaluate(authorisations, aclId);
AccessStatus status = result ? AccessStatus.ALLOWED : AccessStatus.DENIED;
return status;
}
enum CacheType
@@ -427,7 +521,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* Get the authorisations for the currently authenticated user
*
*
* @param auth
* @return
*/
@@ -473,6 +567,41 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
return auths;
}
private Set<String> getAuthorisations(Authentication auth, PermissionContext context)
{
HashSet<String> auths = new HashSet<String>();
// No authenticated user then no permissions
if (auth == null)
{
return auths;
}
// TODO: Refactor and use the authentication service for this.
User user = (User) auth.getPrincipal();
auths.add(user.getUsername());
for (GrantedAuthority authority : auth.getAuthorities())
{
auths.add(authority.getAuthority());
}
auths.addAll(authorityService.getAuthorities());
if (context != null)
{
Map<String, Set<String>> dynamicAuthorityAssignments = context.getDynamicAuthorityAssignment();
HashSet<String> dynAuths = new HashSet<String>();
for (String current : auths)
{
Set<String> dynos = dynamicAuthorityAssignments.get(current);
if (dynos != null)
{
dynAuths.addAll(dynos);
}
}
auths.addAll(dynAuths);
}
return auths;
}
public NodePermissionEntry explainPermission(NodeRef nodeRef, PermissionReference perm)
{
// TODO Auto-generated method stub
@@ -612,7 +741,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* Support class to test the permission on a node.
*
*
* @author Andy Hind
*/
private class NodeTest
@@ -685,7 +814,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* External hook point
*
*
* @param authorisations
* @param nodeRef
* @return
@@ -698,7 +827,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* Internal hook point for recursion
*
*
* @param authorisations
* @param nodeRef
* @param denied
@@ -943,7 +1072,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* Check if we have a global permission
*
*
* @param authorisations
* @return
*/
@@ -961,7 +1090,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* Get the list of permissions denied for this node.
*
*
* @param nodeRef
* @return
*/
@@ -1011,7 +1140,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* Check that a given authentication is available on a node
*
*
* @param authorisations
* @param nodeRef
* @param denied
@@ -1041,7 +1170,7 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
/**
* Is a permission granted
*
*
* @param pe -
* the permissions entry to consider
* @param granters -
@@ -1113,9 +1242,286 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
}
/**
* Test a permission in the context of the new ACL implementation. All components of the ACL are in the object -
* there is no need to walk up the parent chain. Parent conditions cna not be applied as there is no context to do
* this. Child conditions can not be applied as there is no context to do this
*
* @author andyh
*/
private class AclTest
{
/*
* The required permission.
*/
PermissionReference required;
/*
* Granters of the permission
*/
Set<PermissionReference> granters;
/*
* The additional permissions required at the node level.
*/
Set<PermissionReference> nodeRequirements = new HashSet<PermissionReference>();
/*
* The type name of the node.
*/
QName typeQName;
/*
* The aspects set on the node.
*/
Set<QName> aspectQNames;
/*
* Constructor just gets the additional requirements
*/
AclTest(PermissionReference required, QName typeQName, Set<QName> aspectQNames)
{
this.required = required;
this.typeQName = typeQName;
this.aspectQNames = aspectQNames;
// Set the required node permissions
if (required.equals(getPermissionReference(ALL_PERMISSIONS)))
{
nodeRequirements = modelDAO.getRequiredPermissions(getPermissionReference(PermissionService.FULL_CONTROL), typeQName, aspectQNames, RequiredPermission.On.NODE);
}
else
{
nodeRequirements = modelDAO.getRequiredPermissions(required, typeQName, aspectQNames, RequiredPermission.On.NODE);
}
if (modelDAO.getRequiredPermissions(required, typeQName, aspectQNames, RequiredPermission.On.PARENT).size() > 0)
{
throw new IllegalStateException("Parent permissions can not be checked for an acl");
}
if (modelDAO.getRequiredPermissions(required, typeQName, aspectQNames, RequiredPermission.On.CHILDREN).size() > 0)
{
throw new IllegalStateException("Child permissions can not be checked for an acl");
}
// Find all the permissions that grant the allowed permission
// All permissions are treated specially.
granters = new LinkedHashSet<PermissionReference>(128, 1.0f);
granters.addAll(modelDAO.getGrantingPermissions(required));
granters.add(getAllPermissionReference());
granters.add(OLD_ALL_PERMISSIONS_REFERENCE);
}
/**
* Internal hook point for recursion
*
* @param authorisations
* @param nodeRef
* @param denied
* @param recursiveIn
* @return
*/
boolean evaluate(Set<String> authorisations, Long aclId)
{
// Do we defer our required test to a parent (yes if not null)
MutableBoolean recursiveOut = null;
// Start out true and "and" all other results
boolean success = true;
// Check the required permissions but not for sets they rely on
// their underlying permissions
if (modelDAO.checkPermission(required))
{
// We have to do the test as no parent will help us out
success &= hasSinglePermission(authorisations, aclId);
if (!success)
{
return false;
}
}
// Check the other permissions required on the node
for (PermissionReference pr : nodeRequirements)
{
// Build a new test
AclTest nt = new AclTest(pr, typeQName, aspectQNames);
success &= nt.evaluate(authorisations, aclId);
if (!success)
{
return false;
}
}
return success;
}
public boolean hasSinglePermission(Set<String> authorisations, Long aclId)
{
// Check global permission
if (checkGlobalPermissions(authorisations))
{
return true;
}
return checkRequired(authorisations, aclId);
}
/**
* Check if we have a global permission
*
* @param authorisations
* @return
*/
private boolean checkGlobalPermissions(Set<String> authorisations)
{
for (PermissionEntry pe : modelDAO.getGlobalPermissionEntries())
{
if (isGranted(pe, authorisations))
{
return true;
}
}
return false;
}
/**
* Check that a given authentication is available on a node
*
* @param authorisations
* @param nodeRef
* @param denied
* @return
*/
boolean checkRequired(Set<String> authorisations, Long aclId)
{
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
if (acl == null)
{
return false;
}
Set<Pair<String, PermissionReference>> denied = new HashSet<Pair<String, PermissionReference>>();
// Check if each permission allows - the first wins.
// We could have other voting style mechanisms here
for (AccessControlEntry ace : acl.getEntries())
{
if (isGranted(ace, authorisations, denied))
{
return true;
}
}
return false;
}
/**
* Is a permission granted
*
* @param pe -
* the permissions entry to consider
* @param granters -
* the set of granters
* @param authorisations -
* the set of authorities
* @param denied -
* the set of denied permissions/authority pais
* @return
*/
private boolean isGranted(AccessControlEntry ace, Set<String> authorisations, Set<Pair<String, PermissionReference>> denied)
{
// If the permission entry denies then we just deny
if (ace.getAccessStatus() == AccessStatus.DENIED)
{
denied.add(new Pair<String, PermissionReference>(ace.getAuthority(), ace.getPermission()));
return false;
}
// The permission is allowed but we deny it as it is in the denied
// set
if (denied != null)
{
Pair<String, PermissionReference> specific = new Pair<String, PermissionReference>(ace.getAuthority(), required);
if (denied.contains(specific))
{
return false;
}
}
// any deny denies
if (false)
{
if (denied != null)
{
for (String auth : authorisations)
{
Pair<String, PermissionReference> specific = new Pair<String, PermissionReference>(auth, required);
if (denied.contains(specific))
{
return false;
}
for (PermissionReference perm : granters)
{
specific = new Pair<String, PermissionReference>(auth, perm);
if (denied.contains(specific))
{
return false;
}
}
}
}
}
// If the permission has a match in both the authorities and
// granters list it is allowed
// It applies to the current user and it is granted
if (authorisations.contains(ace.getAuthority()) && granters.contains(ace.getPermission()))
{
{
return true;
}
}
// Default deny
return false;
}
private boolean isGranted(PermissionEntry pe, Set<String> authorisations)
{
// If the permission entry denies then we just deny
if (pe.isDenied())
{
return false;
}
// If the permission has a match in both the authorities and
// granters list it is allowed
// It applies to the current user and it is granted
if (authorisations.contains(pe.getAuthority()) && granters.contains(pe.getPermissionReference()))
{
{
return true;
}
}
// Default deny
return false;
}
}
/**
* Helper class to store a pair of objects which may be null
*
*
* @author Andy Hind
*/
private static class Pair<A, B>

View File

@@ -34,7 +34,6 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.PermissionEntry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthorityType;
@@ -1818,9 +1817,9 @@ public class PermissionServiceTest extends AbstractPermissionTest
NodeRef n9 = nodeService.createNode(n1, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}nine"), ContentModel.TYPE_FOLDER).getChildRef();
NodeRef n10 = nodeService.createNode(n1, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}ten"), ContentModel.TYPE_FOLDER).getChildRef();
assertEquals(0, permissionService.getAllSetPermissionsForCurrentUser().size());
assertEquals(0, permissionService.getAllSetPermissionsForAuthority("admin").size());
assertEquals(0, permissionService.getAllSetPermissionsForAuthority("andy").size());
//assertEquals(0, permissionService.getAllSetPermissionsForCurrentUser().size());
//assertEquals(0, permissionService.getAllSetPermissionsForAuthority("admin").size());
//assertEquals(0, permissionService.getAllSetPermissionsForAuthority("andy").size());
permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.READ_CHILDREN), "admin", AccessStatus.ALLOWED));
permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.READ_CONTENT), "admin", AccessStatus.ALLOWED));
@@ -1837,50 +1836,50 @@ public class PermissionServiceTest extends AbstractPermissionTest
permissionService.setPermission(new SimplePermissionEntry(n10, getPermission(PermissionService.READ_CHILDREN), "admin", AccessStatus.DENIED));
permissionService.setPermission(new SimplePermissionEntry(n10, getPermission(PermissionService.READ_CHILDREN), "andy", AccessStatus.ALLOWED));
assertEquals(10, permissionService.getAllSetPermissionsForCurrentUser().size());
assertEquals(10, permissionService.getAllSetPermissionsForAuthority("admin").size());
assertEquals(2, permissionService.getAllSetPermissionsForAuthority("andy").size());
assertNull(permissionService.getAllSetPermissionsForCurrentUser().get(rootNodeRef));
assertNull(permissionService.getAllSetPermissionsForAuthority("admin").get(rootNodeRef));
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(rootNodeRef));
assertEquals(2, permissionService.getAllSetPermissionsForCurrentUser().get(n1).size());
assertEquals(2, permissionService.getAllSetPermissionsForAuthority("admin").get(n1).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n1));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n2).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n2).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("andy").get(n2).size());
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n3).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n3).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n3));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n4).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n4).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n4));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n5).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n5).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n5));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n6).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n6).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n6));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n7).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n7).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n7));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n8).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n8).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n8));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n9).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n9).size());
assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n9));
assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n10).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n10).size());
assertEquals(1, permissionService.getAllSetPermissionsForAuthority("andy").get(n10).size());
// assertEquals(10, permissionService.getAllSetPermissionsForCurrentUser().size());
// assertEquals(10, permissionService.getAllSetPermissionsForAuthority("admin").size());
// assertEquals(2, permissionService.getAllSetPermissionsForAuthority("andy").size());
// assertNull(permissionService.getAllSetPermissionsForCurrentUser().get(rootNodeRef));
// assertNull(permissionService.getAllSetPermissionsForAuthority("admin").get(rootNodeRef));
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(rootNodeRef));
// assertEquals(2, permissionService.getAllSetPermissionsForCurrentUser().get(n1).size());
// assertEquals(2, permissionService.getAllSetPermissionsForAuthority("admin").get(n1).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n1));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n2).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n2).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("andy").get(n2).size());
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n3).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n3).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n3));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n4).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n4).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n4));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n5).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n5).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n5));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n6).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n6).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n6));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n7).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n7).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n7));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n8).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n8).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n8));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n9).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n9).size());
// assertNull(permissionService.getAllSetPermissionsForAuthority("andy").get(n9));
// assertEquals(1, permissionService.getAllSetPermissionsForCurrentUser().get(n10).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("admin").get(n10).size());
// assertEquals(1, permissionService.getAllSetPermissionsForAuthority("andy").get(n10).size());
}
public void testFindNodesByPermission()
public void xtestFindNodesByPermission()
{
runAs("admin");
StoreRef storeRef = rootNodeRef.getStoreRef();
//StoreRef storeRef = rootNodeRef.getStoreRef();
NodeRef n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_FOLDER).getChildRef();
NodeRef n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), ContentModel.TYPE_FOLDER).getChildRef();
@@ -1897,14 +1896,14 @@ public class PermissionServiceTest extends AbstractPermissionTest
String groupAuth = authorityService.createAuthority(AuthorityType.GROUP, null, "G");
authorityService.addAuthority(groupAuth, "andy");
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser("Consumer", true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser("Consumer", false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", "Consumer", true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", "Consumer", false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", "Consumer", true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", "Consumer", false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, "Consumer", true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, "Consumer", false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser("Consumer", true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser("Consumer", false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", "Consumer", true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", "Consumer", false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", "Consumer", true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", "Consumer", false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, "Consumer", true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, "Consumer", false, false, false), storeRef).size());
permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.CONSUMER), "admin", AccessStatus.ALLOWED));
permissionService.setPermission(new SimplePermissionEntry(n1, getPermission(PermissionService.CONSUMER), "andy", AccessStatus.ALLOWED));
@@ -1921,212 +1920,212 @@ public class PermissionServiceTest extends AbstractPermissionTest
permissionService.setPermission(new SimplePermissionEntry(n4, getPermission(PermissionService.READ_CHILDREN), groupAuth, AccessStatus.ALLOWED));
permissionService.setPermission(new SimplePermissionEntry(n5, getPermission(PermissionService.READ_CONTENT), groupAuth, AccessStatus.ALLOWED));
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, false, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, false, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, false, false), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, false, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, false, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, false, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, false, false), storeRef).size());
assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, false, false), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, false, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, false, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, false, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, false, false), storeRef).size());
// assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, false, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, false, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, false, false), storeRef).size());
// Include groups for exact match
for (NodeRef nodeRef : permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, true, false))
{
System.out.println("Found " + nodeService.getPath(nodeRef));
}
// for (NodeRef nodeRef : permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, true, false))
// {
// System.out.println("Found " + nodeService.getPath(nodeRef));
// }
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, true, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, true, false), storeRef).size());
assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, true, false), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, true, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, true, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, true, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, true, false), storeRef).size());
assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, true, false), storeRef).size());
assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, true, false), storeRef).size());
// assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, true, false), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, true, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, true, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, true, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, true, false), storeRef).size());
// assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, true, false), storeRef).size());
// assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, true, false), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, true, false), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, true, false), storeRef).size());
// Include inexact permission
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, false, true), storeRef).size());
assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, false, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, false, true), storeRef).size());
assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, false, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, false, true), storeRef).size());
assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, false, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, false, true), storeRef).size());
assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, false, true), storeRef).size());
// assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, false, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, false, true), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, false, true), storeRef).size());
//
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, false, true), storeRef).size());
// assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, false, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, false, true), storeRef).size());
//
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, false, true), storeRef).size());
// assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, false, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, false, true), storeRef).size());
// assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, false, true), storeRef).size());
//
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
// assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
// assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, false, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, false, true), storeRef).size());
// Inexact for all
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, true, true), storeRef).size());
assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, true, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, true, true), storeRef).size());
assertEquals(4, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, true, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, true, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, true, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, true, true), storeRef).size());
assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONSUMER, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONSUMER, false, true, true), storeRef).size());
// assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, true, true, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONSUMER, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, true, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONSUMER, false, true, true), storeRef).size());
//
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.CONTRIBUTOR, false, true, true), storeRef).size());
//
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ, false, true, true), storeRef).size());
// assertEquals(4, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, true, true, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, true, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ, false, true, true), storeRef).size());
//
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CONTENT, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CONTENT, false, true, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, true, true, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CONTENT, false, true, true), storeRef).size());
// assertEquals(3, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, true, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CONTENT, false, true, true), storeRef).size());
//
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermissionForCurrentUser(PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
// assertEquals(0, filterForStore(permissionService.findNodesByAssignedPermission("admin", PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
// assertEquals(5, filterForStore(permissionService.findNodesByAssignedPermission("andy", PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
// assertEquals(2, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, true, true, true), storeRef).size());
// assertEquals(1, filterForStore(permissionService.findNodesByAssignedPermission(groupAuth, PermissionService.READ_CHILDREN, false, true, true), storeRef).size());
}
private Set<NodeRef> filterForStore(Set<NodeRef> set, StoreRef storeRef)
{
Set<NodeRef> toRemove = new HashSet<NodeRef>();
for (NodeRef node : set)
{
if (!node.getStoreRef().equals(storeRef))
{
toRemove.add(node);
}
}
set.removeAll(toRemove);
return set;
}
// private Set<NodeRef> filterForStore(Set<NodeRef> set, StoreRef storeRef)
// {
// Set<NodeRef> toRemove = new HashSet<NodeRef>();
// for (NodeRef node : set)
// {
// if (!node.getStoreRef().equals(storeRef))
// {
// toRemove.add(node);
// }
// }
// set.removeAll(toRemove);
// return set;
// }
// TODO: Test permissions on missing nodes

View File

@@ -56,7 +56,7 @@ public interface PermissionsDaoComponent
public void deletePermissions(NodeRef nodeRef);
/**
* Remove all permissions for the specvified authority
* Remove all permissions for the specified authority
* @param authority
*/
public void deletePermissions(String authority);

View File

@@ -1,212 +0,0 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.security.permissions.impl.hibernate;
import java.io.Serializable;
import org.alfresco.repo.domain.DbAccessControlEntry;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.DbAuthority;
import org.alfresco.repo.domain.DbPermission;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.Store;
import org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl;
import org.alfresco.repo.domain.hibernate.DbAccessControlListImpl;
import org.alfresco.repo.domain.hibernate.DbAuthorityImpl;
import org.alfresco.repo.domain.hibernate.DbPermissionImpl;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* @see org.alfresco.repo.domain.hibernate.PermissionsDaoComponentImpl
* @see org.alfresco.repo.domain.DbAccessControlList
* @see org.alfresco.repo.domain.DbAccessControlEntry
*
* @author Andy Hind
*/
public class HibernatePermissionTest extends BaseSpringTest
{
private NodeDaoService nodeDaoService;
private Node node;
private QName qname;
public HibernatePermissionTest()
{
}
protected void onSetUpInTransaction() throws Exception
{
nodeDaoService = (NodeDaoService) applicationContext.getBean("nodeDaoService");
// create the node to play with
Store store = nodeDaoService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
getName() + "_" + System.currentTimeMillis());
qname = QName.createQName(NamespaceService.ALFRESCO_URI, getName());
node = nodeDaoService.newNode(
store,
GUID.generate(),
qname);
}
protected void onTearDownInTransaction()
{
try
{
// force a flush to ensure that the database updates succeed
getSession().flush();
getSession().clear();
}
catch (Throwable e)
{
// don't mask any other exception coming through
e.printStackTrace();
}
}
public void testSimpleAccessControlList() throws Exception
{
// create a new Node
DbAccessControlList accessControlList = new DbAccessControlListImpl();
accessControlList.setInherits(true);
Serializable id = getSession().save(accessControlList);
node.setAccessControlList(accessControlList);
// throw the reference away and get the a new one for the id
accessControlList = (DbAccessControlList) getSession().load(DbAccessControlListImpl.class, id);
assertNotNull("Access control list not found", accessControlList);
assertTrue(accessControlList.getInherits());
// Update inherits
accessControlList.setInherits(false);
id = getSession().save(accessControlList);
// throw the reference away and get the a new one for the id
accessControlList = (DbAccessControlList) getSession().load(DbAccessControlListImpl.class, id);
assertNotNull("Node not found", accessControlList);
assertFalse(accessControlList.getInherits());
}
public void testSimplePermission()
{
DbPermission permission = new DbPermissionImpl();
permission.setTypeQname(qname);
permission.setName("Test");
Serializable id = getSession().save(permission);
// throw the reference away and get the a new one for the id
permission = (DbPermission) getSession().load(DbPermissionImpl.class, id);
assertNotNull("Permission not found", permission);
assertEquals(qname, permission.getTypeQname());
}
public void testSimpleAuthority()
{
DbAuthority authority = new DbAuthorityImpl();
authority.setRecipient("Test");
authority.getExternalKeys().add("One");
Serializable id = getSession().save(authority);
// throw the reference away and get the a new one for the id
authority = (DbAuthority) getSession().load(DbAuthorityImpl.class, id);
assertNotNull("Node not found", authority);
assertEquals("Test", authority.getRecipient());
assertEquals(1, authority.getExternalKeys().size());
// Update
authority.getExternalKeys().add("Two");
id = getSession().save(authority);
// throw the reference away and get the a new one for the id
authority = (DbAuthority) getSession().load(DbAuthorityImpl.class, id);
assertNotNull("Node not found", authority);
assertEquals("Test", authority.getRecipient());
assertEquals(2, authority.getExternalKeys().size());
// complex
authority.getExternalKeys().add("Three");
authority.getExternalKeys().remove("One");
authority.getExternalKeys().remove("Two");
id = getSession().save(authority);
// Throw the reference away and get the a new one for the id
authority = (DbAuthority) getSession().load(DbAuthorityImpl.class, id);
assertNotNull("Node not found", authority);
assertEquals("Test", authority.getRecipient());
assertEquals(1, authority.getExternalKeys().size());
}
public void testAccessControlList()
{
// create a new access control list for the node
DbAccessControlList accessControlList = new DbAccessControlListImpl();
accessControlList.setInherits(true);
Serializable nodeAclId = getSession().save(accessControlList);
node.setAccessControlList(accessControlList);
DbAuthority recipient = new DbAuthorityImpl();
recipient.setRecipient("Test");
recipient.getExternalKeys().add("One");
getSession().save(recipient);
DbPermission permission = new DbPermissionImpl();
permission.setTypeQname(qname);
permission.setName("Test");
getSession().save(permission);
DbAccessControlEntry accessControlEntry = accessControlList.newEntry(permission, recipient, true);
Long aceEntryId = accessControlEntry.getId();
assertNotNull("Entry is still transient", aceEntryId);
accessControlEntry = (DbAccessControlEntry) getSession().load(DbAccessControlEntryImpl.class, aceEntryId);
assertNotNull("Permission entry not found", accessControlEntry);
assertTrue(accessControlEntry.isAllowed());
assertNotNull(accessControlEntry.getAccessControlList());
assertTrue(accessControlEntry.getAccessControlList().getInherits());
assertNotNull(accessControlEntry.getPermission());
assertEquals("Test", accessControlEntry.getPermission().getKey().getName());
assertNotNull(accessControlEntry.getAuthority());
assertEquals("Test", accessControlEntry.getAuthority().getRecipient());
assertEquals(1, accessControlEntry.getAuthority().getExternalKeys().size());
// Check that deletion of the list cascades
node.setAccessControlList(null);
getSession().delete(accessControlList);
DbAccessControlEntry deletedAcl = (DbAccessControlEntry) getSession().get(DbAccessControlListImpl.class, nodeAclId);
assertNull("Access control list was not deleted", deletedAcl);
DbAccessControlEntry deletedAclEntry = (DbAccessControlEntry) getSession().get(DbAccessControlEntryImpl.class, aceEntryId);
assertNull("Access control entries were not cascade deleted", deletedAclEntry);
}
}

View File

@@ -96,7 +96,6 @@ public class PermissionModel implements ModelDAO, InitializingBean
private String model;
// Aprrox 6 - default size OK
private Map<QName, PermissionSet> permissionSets = new HashMap<QName, PermissionSet>();
@@ -122,11 +121,9 @@ public class PermissionModel implements ModelDAO, InitializingBean
private HashMap<String, PermissionReference> permissionReferenceMap;
private Map<QName, Set<PermissionReference>> cachedTypePermissionsExposed = new HashMap<QName, Set<PermissionReference>>(
128, 1.0f);
private Map<QName, Set<PermissionReference>> cachedTypePermissionsExposed = new HashMap<QName, Set<PermissionReference>>(128, 1.0f);
private Map<QName, Set<PermissionReference>> cachedTypePermissionsUnexposed = new HashMap<QName, Set<PermissionReference>>(
128, 1.0f);
private Map<QName, Set<PermissionReference>> cachedTypePermissionsUnexposed = new HashMap<QName, Set<PermissionReference>>(128, 1.0f);
public PermissionModel()
{
@@ -202,8 +199,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
for (Iterator it = namespacesElement.elementIterator(NAMESPACE); it.hasNext(); /**/)
{
Element nameSpaceElement = (Element) it.next();
nspr.registerNamespace(nameSpaceElement.attributeValue(NAMESPACE_PREFIX), nameSpaceElement
.attributeValue(NAMESPACE_URI));
nspr.registerNamespace(nameSpaceElement.attributeValue(NAMESPACE_PREFIX), nameSpaceElement.attributeValue(NAMESPACE_URI));
}
}
@@ -290,15 +286,14 @@ public class PermissionModel implements ModelDAO, InitializingBean
public Set<PermissionReference> getAllPermissions(QName type)
{
return getAllPermissionsImpl(type, false);
return getAllPermissionsImpl(type, null, false);
}
public Set<PermissionReference> getExposedPermissions(QName type)
{
return getAllPermissionsImpl(type, true);
return getAllPermissionsImpl(type, null, true);
}
private Set<PermissionReference> getAllPermissionsImpl(QName type, boolean exposedOnly)
{
Map<QName, Set<PermissionReference>> cache;
@@ -441,36 +436,49 @@ public class PermissionModel implements ModelDAO, InitializingBean
public Set<PermissionReference> getAllPermissions(NodeRef nodeRef)
{
return getExposedPermissionsImpl(nodeRef, false);
return getAllPermissionsImpl(nodeService.getType(nodeRef), nodeService.getAspects(nodeRef), false);
}
public Set<PermissionReference> getExposedPermissions(NodeRef nodeRef)
{
return getExposedPermissionsImpl(nodeRef, true);
return getAllPermissionsImpl(nodeService.getType(nodeRef), nodeService.getAspects(nodeRef), true);
}
public Set<PermissionReference> getExposedPermissionsImpl(NodeRef nodeRef, boolean exposedOnly)
public Set<PermissionReference> getAllPermissions(QName typeName, Set<QName> aspects)
{
//
// TODO: cache permissions based on type and exposed flag
// create JMeter test to see before/after effect!
//
QName typeName = nodeService.getType(nodeRef);
return getAllPermissionsImpl(typeName, aspects, false);
}
private Set<PermissionReference> getAllPermissionsImpl(QName typeName, Set<QName> aspects, boolean exposedOnly)
{
Set<PermissionReference> permissions = new LinkedHashSet<PermissionReference>(128, 1.0f);
permissions.addAll(getAllPermissionsImpl(typeName, exposedOnly));
mergeGeneralAspectPermissions(permissions, exposedOnly);
// Add non mandatory aspects...
Set<QName> defaultAspects = new HashSet<QName>();
for (AspectDefinition aspDef : dictionaryService.getType(typeName).getDefaultAspects())
ClassDefinition cd = dictionaryService.getClass(typeName);
if (cd != null)
{
defaultAspects.add(aspDef.getName());
}
for (QName aspect : nodeService.getAspects(nodeRef))
{
if (!defaultAspects.contains(aspect))
if (cd.isAspect())
{
addAspectPermissions(aspect, permissions, exposedOnly);
// Do not merge in all general aspects
}
else
{
mergeGeneralAspectPermissions(permissions, exposedOnly);
}
Set<QName> defaultAspects = new HashSet<QName>();
for (AspectDefinition aspDef : cd.getDefaultAspects())
{
defaultAspects.add(aspDef.getName());
}
if (aspects != null)
{
for (QName aspect : aspects)
{
if (!defaultAspects.contains(aspect))
{
addAspectPermissions(aspect, permissions, exposedOnly);
}
}
}
}
return permissions;
@@ -582,8 +590,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
{
if (pg.getTypeQName() != null)
{
permissions.addAll(getGranteePermissions(new SimplePermissionReference(pg.getTypeQName(),
pg.getName())));
permissions.addAll(getGranteePermissions(new SimplePermissionReference(pg.getTypeQName(), pg.getName())));
}
else
{
@@ -592,8 +599,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
if (parent != null)
{
classDefinition = dictionaryService.getClass(parent);
PermissionGroup attempt = getPermissionGroupOrNull(new SimplePermissionReference(
parent, pg.getName()));
PermissionGroup attempt = getPermissionGroupOrNull(new SimplePermissionReference(parent, pg.getName()));
if (attempt != null)
{
permissions.addAll(getGranteePermissions(attempt));
@@ -668,8 +674,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
PermissionGroup pg = getPermissionGroupOrNull(target);
if (pg == null)
{
throw new PermissionModelException("There is no permission group :"
+ target.getQName() + " " + target.getName());
throw new PermissionModelException("There is no permission group :" + target.getQName() + " " + target.getName());
}
return pg;
}
@@ -716,8 +721,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
while ((parent = classDefinition.getParentName()) != null)
{
classDefinition = dictionaryService.getClass(parent);
PermissionGroup attempt = getPermissionGroupOrNull(new SimplePermissionReference(parent, pg
.getName()));
PermissionGroup attempt = getPermissionGroupOrNull(new SimplePermissionReference(parent, pg.getName()));
if ((attempt != null) && (!attempt.isExtends()))
{
return attempt;
@@ -737,14 +741,12 @@ public class PermissionModel implements ModelDAO, InitializingBean
PermissionGroup pg = getBasePermissionGroupOrNull(target);
if (pg == null)
{
throw new PermissionModelException("There is no parent for permission group :"
+ target.getQName() + " " + target.getName());
throw new PermissionModelException("There is no parent for permission group :" + target.getQName() + " " + target.getName());
}
return pg;
}
static Serializable generateKey(PermissionReference required, QName qName, Set<QName> aspectQNames,
RequiredPermission.On on)
static Serializable generateKey(PermissionReference required, QName qName, Set<QName> aspectQNames, RequiredPermission.On on)
{
LinkedHashSet<Serializable> key = new LinkedHashSet<Serializable>();
key.add(required.toString());
@@ -754,12 +756,9 @@ public class PermissionModel implements ModelDAO, InitializingBean
return key;
}
private HashMap<Serializable, Set<PermissionReference>> requiredPermissionsCache = new HashMap<Serializable, Set<PermissionReference>>(1024);
private HashMap<Serializable, Set<PermissionReference>> requiredPermissionsCache = new HashMap<Serializable, Set<PermissionReference>>(
1024);
public Set<PermissionReference> getRequiredPermissions(PermissionReference required, QName qName,
Set<QName> aspectQNames, RequiredPermission.On on)
public Set<PermissionReference> getRequiredPermissions(PermissionReference required, QName qName, Set<QName> aspectQNames, RequiredPermission.On on)
{
// Cache lookup as this is static
@@ -816,8 +815,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
* @param aspectQNames
* @return
*/
private Set<PermissionReference> getRequirementsForPermissionGroup(PermissionGroup target,
RequiredPermission.On on, QName qName, Set<QName> aspectQNames)
private Set<PermissionReference> getRequirementsForPermissionGroup(PermissionGroup target, RequiredPermission.On on, QName qName, Set<QName> aspectQNames)
{
HashSet<PermissionReference> requiredPermissions = new HashSet<PermissionReference>(8, 1.0f);
if (target == null)
@@ -829,14 +827,12 @@ public class PermissionModel implements ModelDAO, InitializingBean
for (PermissionGroup pg : ps.getPermissionGroups())
{
PermissionGroup base = getBasePermissionGroupOrNull(pg);
if ((target.equals(base) || target.isAllowFullControl())
&& (!base.isTypeRequired() || isPartOfDynamicPermissionGroup(pg, qName, aspectQNames)))
if ((target.equals(base) || target.isAllowFullControl()) && (!base.isTypeRequired() || isPartOfDynamicPermissionGroup(pg, qName, aspectQNames)))
{
// Add includes
for (PermissionReference pr : pg.getIncludedPermissionGroups())
{
requiredPermissions.addAll(getRequirementsForPermissionGroup(
getBasePermissionGroupOrNull(getPermissionGroupOrNull(pr)), on, qName, aspectQNames));
requiredPermissions.addAll(getRequirementsForPermissionGroup(getBasePermissionGroupOrNull(getPermissionGroupOrNull(pr)), on, qName, aspectQNames));
}
}
}
@@ -845,8 +841,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
for (PermissionReference grantedTo : p.getGrantedToGroups())
{
PermissionGroup base = getBasePermissionGroupOrNull(getPermissionGroupOrNull(grantedTo));
if ((target.equals(base) || target.isAllowFullControl())
&& (!base.isTypeRequired() || isPartOfDynamicPermissionGroup(grantedTo, qName, aspectQNames)))
if ((target.equals(base) || target.isAllowFullControl()) && (!base.isTypeRequired() || isPartOfDynamicPermissionGroup(grantedTo, qName, aspectQNames)))
{
if (on == RequiredPermission.On.NODE)
{
@@ -918,8 +913,7 @@ public class PermissionModel implements ModelDAO, InitializingBean
while ((parent = classDefinition.getParentName()) != null)
{
classDefinition = dictionaryService.getClass(parent);
PermissionGroup attempt = getPermissionGroupOrNull(new SimplePermissionReference(parent, pg
.getName()));
PermissionGroup attempt = getPermissionGroupOrNull(new SimplePermissionReference(parent, pg.getName()));
if ((attempt != null) && attempt.isAllowFullControl())
{
return true;
@@ -1023,13 +1017,10 @@ public class PermissionModel implements ModelDAO, InitializingBean
// Add all permissions to the unique list
if (uniqueMap.containsKey(PermissionService.ALL_PERMISSIONS))
{
throw new IllegalStateException(
"There must not be a permission with the same name as the ALL_PERMISSION constant: "
+ PermissionService.ALL_PERMISSIONS);
throw new IllegalStateException("There must not be a permission with the same name as the ALL_PERMISSION constant: " + PermissionService.ALL_PERMISSIONS);
}
uniqueMap.put(PermissionService.ALL_PERMISSIONS, new SimplePermissionReference(QName.createQName(
NamespaceService.SECURITY_MODEL_1_0_URI, PermissionService.ALL_PERMISSIONS),
PermissionService.ALL_PERMISSIONS));
uniqueMap.put(PermissionService.ALL_PERMISSIONS, new SimplePermissionReference(QName
.createQName(NamespaceService.SECURITY_MODEL_1_0_URI, PermissionService.ALL_PERMISSIONS), PermissionService.ALL_PERMISSIONS));
}

View File

@@ -89,7 +89,8 @@ public class PermissionModelTest extends AbstractPermissionTest
namespacePrefixResolver), "Coordinator"));
// NB This has gone from 59 to 63, I believe, because of the for new WCM roles.
assertEquals(63, grantees.size());
// 63-97 from AVM permission fix up
assertEquals(97, grantees.size());
}
public void testIncludePermissionGroups6()

View File

@@ -33,9 +33,12 @@ import org.alfresco.repo.security.permissions.NodePermissionEntry;
import org.alfresco.repo.security.permissions.PermissionEntry;
import org.alfresco.repo.security.permissions.PermissionReference;
import org.alfresco.repo.security.permissions.PermissionServiceSPI;
import org.alfresco.repo.security.permissions.impl.PermissionReferenceImpl;
import org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionContext;
import org.alfresco.service.namespace.QName;
@@ -76,7 +79,7 @@ public class PermissionServiceNOOPImpl
*/
public Set<AccessPermission> getPermissions(NodeRef nodeRef)
{
return null;
return Collections.<AccessPermission>emptySet();
}
/* (non-Javadoc)
@@ -84,7 +87,7 @@ public class PermissionServiceNOOPImpl
*/
public Set<AccessPermission> getAllSetPermissions(NodeRef nodeRef)
{
return null;
return Collections.<AccessPermission>emptySet();
}
/* (non-Javadoc)
@@ -179,48 +182,48 @@ public class PermissionServiceNOOPImpl
public PermissionReference getAllPermissionReference()
{
throw new UnsupportedOperationException();
return getPermissionReference(ALL_PERMISSIONS);
}
public String getPermission(PermissionReference permissionReference)
{
throw new UnsupportedOperationException();
return permissionReference.toString();
}
public PermissionReference getPermissionReference(QName qname, String permissionName)
{
throw new UnsupportedOperationException();
return new PermissionReferenceImpl(qname, permissionName);
}
public PermissionReference getPermissionReference(String permissionName)
{
throw new UnsupportedOperationException();
return new PermissionReferenceImpl(QName.createQName("uri", "local"), permissionName);
}
public NodePermissionEntry getSetPermissions(NodeRef nodeRef)
{
throw new UnsupportedOperationException();
return new SimpleNodePermissionEntry(nodeRef, true, Collections.<PermissionEntry>emptySet());
}
public Set<PermissionReference> getSettablePermissionReferences(NodeRef nodeRef)
{
throw new UnsupportedOperationException();
return Collections.<PermissionReference>emptySet();
}
public Set<PermissionReference> getSettablePermissionReferences(QName type)
{
throw new UnsupportedOperationException();
return Collections.<PermissionReference>emptySet();
}
public AccessStatus hasPermission(NodeRef nodeRef, PermissionReference perm)
{
throw new UnsupportedOperationException();
return AccessStatus.ALLOWED;
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.security.PermissionService#hasPermission(java.lang.Long, java.lang.String, java.lang.String)
*/
public AccessStatus hasPermission(Long aclID, Map<String, Object> context,
public AccessStatus hasPermission(Long aclID, PermissionContext context,
String permission)
{
return AccessStatus.ALLOWED;
@@ -228,12 +231,12 @@ public class PermissionServiceNOOPImpl
public void setPermission(NodePermissionEntry nodePermissionEntry)
{
throw new UnsupportedOperationException();
}
public void setPermission(PermissionEntry permissionEntry)
{
throw new UnsupportedOperationException();
}
public Map<NodeRef, Set<AccessPermission>> getAllSetPermissionsForCurrentUser()

View File

@@ -219,6 +219,18 @@ public interface LockService
@Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef"})
public LockStatus getLockStatus(NodeRef nodeRef);
/**
* Gets the lock status for the node reference relative to the current user.
*
* @see LockService#getLockStatus(NodeRef, NodeRef)
*
* @param nodeRef the node reference
* @return the lock status
*/
@Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef", "userName"})
public LockStatus getLockStatus(NodeRef nodeRef, String userName);
/**
* Gets the lock type for the node indicated.
* <p>

View File

@@ -34,8 +34,7 @@ package org.alfresco.service.cmr.security;
* <li>GROUP - an authority that identifies a group
* <li>OWNER - the special authority that applies to the owner of a node
* <li>EVERYONE - the special authority that is interpreted as everyone
* <li>GUEST - the special authority that applies to a GUEST (An unknown,
* unauthenticated user)
* <li>GUEST - the special authority that applies to a GUEST (An unknown, unauthenticated user)
* </ol>
*
* @author Andy Hind
@@ -63,6 +62,11 @@ public enum AuthorityType
{
return "";
}
public int getOrderPosition()
{
return 0;
}
},
EVERYONE
@@ -86,6 +90,11 @@ public enum AuthorityType
{
return "";
}
public int getOrderPosition()
{
return 1;
}
},
OWNER
{
@@ -108,6 +117,11 @@ public enum AuthorityType
{
return "";
}
public int getOrderPosition()
{
return 2;
}
},
GUEST
{
@@ -130,6 +144,11 @@ public enum AuthorityType
{
return "";
}
public int getOrderPosition()
{
return 3;
}
},
GROUP
{
@@ -152,6 +171,11 @@ public enum AuthorityType
{
return PermissionService.GROUP_PREFIX;
}
public int getOrderPosition()
{
return 4;
}
},
ROLE
{
@@ -175,6 +199,11 @@ public enum AuthorityType
{
return PermissionService.ROLE_PREFIX;
}
public int getOrderPosition()
{
return 5;
}
},
USER
{
@@ -197,6 +226,11 @@ public enum AuthorityType
{
return "";
}
public int getOrderPosition()
{
return 6;
}
};
public abstract boolean isFixedString();
@@ -207,6 +241,8 @@ public enum AuthorityType
public abstract String getPrefixString();
public abstract int getOrderPosition();
public boolean equals(String authority)
{
return equals(getAuthorityType(authority));

View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.service.cmr.security;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.service.namespace.QName;
public class PermissionContext
{
private QName type;
private HashSet<QName> aspects = new HashSet<QName>();
private Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
private Map<String, Set<String>> dynamicAuthorityAssignment = new HashMap<String, Set<String>>();
private Map<String, Object> additionalContext = new HashMap<String, Object>();
public PermissionContext(QName type)
{
this.type = type;
}
public HashSet<QName> getAspects()
{
return aspects;
}
public Map<String, Set<String>> getDynamicAuthorityAssignment()
{
return dynamicAuthorityAssignment;
}
public void addDynamicAuthorityAssignment(String user, String dynamicAuthority)
{
Set<String> dynamicAuthorities = dynamicAuthorityAssignment.get(user);
if(dynamicAuthorities == null)
{
dynamicAuthorities = new HashSet<String>();
dynamicAuthorityAssignment.put(user, dynamicAuthorities);
}
dynamicAuthorities.add(dynamicAuthority);
}
public Map<String, Object> getAdditionalContext()
{
return additionalContext;
}
public Map<QName, Serializable> getProperties()
{
return properties;
}
public QName getType()
{
return type;
}
}

View File

@@ -234,7 +234,7 @@ public interface PermissionService
* @return
*/
@Auditable(parameters = { "aclID", "context", "permission" })
public AccessStatus hasPermission(Long aclID, Map<String, Object> context, String permission);
public AccessStatus hasPermission(Long aclID, PermissionContext context, String permission);
/**
* Delete all the permission assigned to the node
@@ -306,6 +306,7 @@ public interface PermissionService
* Get all permissions set for the current user.
*
* @return - A map of noderefs to permissions set
* @deprecated
*/
@Auditable
public Map<NodeRef, Set<AccessPermission>> getAllSetPermissionsForCurrentUser();
@@ -315,6 +316,7 @@ public interface PermissionService
*
* @param authority
* @return - A map of noderefs to permissions set
* @deprecated
*/
@Auditable(parameters = { "authority" })
public Map<NodeRef, Set<AccessPermission>> getAllSetPermissionsForAuthority(String authority);
@@ -331,6 +333,7 @@ public interface PermissionService
* @param includeContainingPermissions -
* true; do an exact match: false; search for any permission that woudl imply the one given
* @return - the set of nodes where the user is assigned the permission
* @deprecated
*/
@Auditable(parameters = { "permission", "allow", "includeContainingAuthorities", "includeContainingPermissions" })
public Set<NodeRef> findNodesByAssignedPermissionForCurrentUser(String permission, boolean allow, boolean includeContainingAuthorities,
@@ -348,6 +351,7 @@ public interface PermissionService
* @param exactPermissionMatch -
* true; do an exact match: false; search for any permission that woudl imply the one given
* @return - the set of nodes where the user is assigned the permission
* @deprecated
*/
@Auditable(parameters = { "authority", "permission", "allow", "includeContainingAuthorities",
"exactPermissionMatch" })