mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-3074: Initial refactoring of the extended security service implementation
This commit is contained in:
@@ -360,8 +360,6 @@ public class FilePlanServiceImpl extends ServiceBaseImpl
|
||||
// set inheritance to false
|
||||
getPermissionService().setInheritParentPermissions(container, false);
|
||||
getPermissionService().setPermission(container, allRoles, RMPermissionModel.READ_RECORDS, true);
|
||||
getPermissionService().setPermission(container, ExtendedReaderDynamicAuthority.EXTENDED_READER, RMPermissionModel.READ_RECORDS, true);
|
||||
getPermissionService().setPermission(container, ExtendedWriterDynamicAuthority.EXTENDED_WRITER, RMPermissionModel.FILING, true);
|
||||
|
||||
// prevent inheritance of rules
|
||||
nodeService.addAspect(container, RuleModel.ASPECT_IGNORE_INHERITED_RULES, null);
|
||||
|
@@ -253,9 +253,10 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel
|
||||
QName PROP_LOADED_DATA_SET_IDS = QName.createQName(RM_URI, "loadedDataSetIds");
|
||||
|
||||
// Extended security aspect
|
||||
QName ASPECT_EXTENDED_SECURITY = QName.createQName(RM_URI, "extendedSecurity");
|
||||
QName PROP_READERS = QName.createQName(RM_URI, "readers");
|
||||
QName PROP_WRITERS = QName.createQName(RM_URI, "writers");
|
||||
// @deprecated as of 2.5, because of performance issues
|
||||
@Deprecated QName ASPECT_EXTENDED_SECURITY = QName.createQName(RM_URI, "extendedSecurity");
|
||||
@Deprecated QName PROP_READERS = QName.createQName(RM_URI, "readers");
|
||||
@Deprecated QName PROP_WRITERS = QName.createQName(RM_URI, "writers");
|
||||
|
||||
// Originating details of a record
|
||||
QName ASPECT_RECORD_ORIGINATING_DETAILS = QName.createQName(RM_URI, "recordOriginatingDetails");
|
||||
|
@@ -164,10 +164,6 @@ public class RMv21InPlacePatch extends RMv21PatchComponent
|
||||
ruleService.disableRules();
|
||||
try
|
||||
{
|
||||
// set permissions
|
||||
filePlanPermissionService.setPermission(filePlan, ExtendedReaderDynamicAuthority.EXTENDED_READER, RMPermissionModel.READ_RECORDS);
|
||||
filePlanPermissionService.setPermission(filePlan, ExtendedWriterDynamicAuthority.EXTENDED_WRITER, RMPermissionModel.FILING);
|
||||
|
||||
// create fileplan containers
|
||||
filePlanService.createHoldContainer(filePlan);
|
||||
filePlanService.createTransferContainer(filePlan);
|
||||
|
@@ -609,7 +609,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
nodeService.getType(childAssocRef.getParentRef()).equals(ContentModel.TYPE_FOLDER))
|
||||
{
|
||||
// ..then remove the extended readers and writers up the tree for this remaining node
|
||||
extendedSecurityService.removeExtendedSecurity(childAssocRef.getChildRef(), extendedSecurityService.getExtendedReaders(childAssocRef.getChildRef()), extendedSecurityService.getExtendedWriters(childAssocRef.getChildRef()), true);
|
||||
extendedSecurityService.removeAllExtendedSecurity(childAssocRef.getChildRef());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -195,8 +195,6 @@ public class FilePlanRoleServiceImpl implements FilePlanRoleService,
|
||||
// Set the permissions
|
||||
permissionService.setInheritParentPermissions(filePlan, false);
|
||||
permissionService.setPermission(filePlan, allRoles, RMPermissionModel.READ_RECORDS, true);
|
||||
permissionService.setPermission(filePlan, ExtendedReaderDynamicAuthority.EXTENDED_READER, RMPermissionModel.READ_RECORDS, true);
|
||||
permissionService.setPermission(filePlan, ExtendedWriterDynamicAuthority.EXTENDED_WRITER, RMPermissionModel.FILING, true);
|
||||
|
||||
// Create the transfer and hold containers
|
||||
systemContainers.add(filePlanService.createHoldContainer(filePlan));
|
||||
|
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.security;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.repo.security.permissions.PermissionReference;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Extended readers dynamic authority implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedReaderDynamicAuthority extends ExtendedSecurityBaseDynamicAuthority
|
||||
{
|
||||
/** Extended reader role */
|
||||
public static final String EXTENDED_READER = "ROLE_EXTENDED_READER";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.DynamicAuthority#getAuthority()
|
||||
*/
|
||||
@Override
|
||||
public String getAuthority()
|
||||
{
|
||||
return EXTENDED_READER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.DynamicAuthority#requiredFor()
|
||||
*/
|
||||
@Override
|
||||
public Set<PermissionReference> requiredFor()
|
||||
{
|
||||
if (requiredFor == null)
|
||||
{
|
||||
requiredFor = Collections.singleton(getModelDAO().getPermissionReference(null, RMPermissionModel.READ_RECORDS));
|
||||
}
|
||||
|
||||
return requiredFor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityBaseDynamicAuthority#getAuthorites(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<String> getAuthorites(NodeRef nodeRef)
|
||||
{
|
||||
Set<String> result = null;
|
||||
|
||||
Map<String, Integer> readerMap = (Map<String, Integer>)getNodeService().getProperty(nodeRef, PROP_READERS);
|
||||
if (readerMap != null)
|
||||
{
|
||||
result = readerMap.keySet();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityBaseDynamicAuthority#getTransactionCacheName()
|
||||
*/
|
||||
@Override
|
||||
protected String getTransactionCacheName()
|
||||
{
|
||||
return "rm.extendedreaderdynamicauthority";
|
||||
}
|
||||
}
|
@@ -1,191 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.security;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.repo.security.permissions.DynamicAuthority;
|
||||
import org.alfresco.repo.security.permissions.PermissionReference;
|
||||
import org.alfresco.repo.security.permissions.impl.ModelDAO;
|
||||
import org.alfresco.repo.transaction.TransactionalResourceHelper;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* Extended readers dynamic authority implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public abstract class ExtendedSecurityBaseDynamicAuthority implements DynamicAuthority,
|
||||
RecordsManagementModel,
|
||||
ApplicationContextAware
|
||||
{
|
||||
/** Authority service */
|
||||
private AuthorityService authorityService;
|
||||
|
||||
/** Extended security service */
|
||||
private ExtendedSecurityService extendedSecurityService;
|
||||
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Application context */
|
||||
protected ApplicationContext applicationContext;
|
||||
|
||||
/** model DAO */
|
||||
protected ModelDAO modelDAO;
|
||||
|
||||
/** permission reference */
|
||||
protected Set<PermissionReference> requiredFor;
|
||||
|
||||
// NOTE: we get the services directly from the application context in this way to avoid
|
||||
// cyclic relationships and issues when loading the application context
|
||||
|
||||
/**
|
||||
* @return authority service
|
||||
*/
|
||||
protected AuthorityService getAuthorityService()
|
||||
{
|
||||
if (authorityService == null)
|
||||
{
|
||||
authorityService = (AuthorityService)applicationContext.getBean("authorityService");
|
||||
}
|
||||
return authorityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return extended security service
|
||||
*/
|
||||
protected ExtendedSecurityService getExtendedSecurityService()
|
||||
{
|
||||
if (extendedSecurityService == null)
|
||||
{
|
||||
extendedSecurityService = (ExtendedSecurityService)applicationContext.getBean("extendedSecurityService");
|
||||
}
|
||||
return extendedSecurityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return node service
|
||||
*/
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
if (nodeService == null)
|
||||
{
|
||||
nodeService = (NodeService)applicationContext.getBean("dbNodeService");
|
||||
}
|
||||
return nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return model DAO
|
||||
*/
|
||||
protected ModelDAO getModelDAO()
|
||||
{
|
||||
if (modelDAO == null)
|
||||
{
|
||||
modelDAO = (ModelDAO)applicationContext.getBean("permissionsModelDAO");
|
||||
}
|
||||
return modelDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String transaction cache name
|
||||
*/
|
||||
protected abstract String getTransactionCacheName();
|
||||
|
||||
/**
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
{
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of the authorities from the extended security aspect that this dynamic
|
||||
* authority is checking against.
|
||||
*
|
||||
* @param nodeRef
|
||||
* @return
|
||||
*/
|
||||
protected abstract Set<String> getAuthorites(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.DynamicAuthority#hasAuthority(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasAuthority(NodeRef nodeRef, String userName)
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
Map<Pair<NodeRef, String>, Boolean> transactionCache = TransactionalResourceHelper.getMap(getTransactionCacheName());
|
||||
Pair<NodeRef, String> key = new Pair<NodeRef, String>(nodeRef, userName);
|
||||
|
||||
if (transactionCache.containsKey(key))
|
||||
{
|
||||
result = transactionCache.get(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getNodeService().hasAspect(nodeRef, ASPECT_EXTENDED_SECURITY))
|
||||
{
|
||||
Set<String> authorities = getAuthorites(nodeRef);
|
||||
if (authorities != null)
|
||||
{
|
||||
// check for everyone or the user
|
||||
if (authorities.contains("GROUP_EVEYONE") ||
|
||||
authorities.contains(userName))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine whether any of the users groups are in the extended security
|
||||
Set<String> contained = getAuthorityService().getAuthoritiesForUser(userName);
|
||||
authorities.retainAll(contained);
|
||||
result = (authorities.size() != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cache result
|
||||
transactionCache.put(key, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -41,11 +41,13 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@AlfrescoPublicApi
|
||||
public interface ExtendedSecurityService
|
||||
{
|
||||
static final String IPR_GROUP_PREFIX = "IPR_";
|
||||
|
||||
/**
|
||||
* Indicates whether a node has extended security.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @return boolean true if the node has extedned security, false otherwise
|
||||
* @return boolean true if the node has extended security, false otherwise
|
||||
*/
|
||||
boolean hasExtendedSecurity(NodeRef nodeRef);
|
||||
|
||||
@@ -67,13 +69,25 @@ public interface ExtendedSecurityService
|
||||
|
||||
/**
|
||||
* Add extended security for the specified authorities to a node.
|
||||
*
|
||||
* As of, 2.5 this method no longer applies the extended security to parents.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @param readers set of authorities to add extended read permissions
|
||||
* @param writers set of authorities to add extended write permissions
|
||||
*
|
||||
*/
|
||||
// TODO rename to setExtendedSecurity to reflect that this doesn't update the extended security any more
|
||||
void addExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers);
|
||||
|
||||
/**
|
||||
* Remove all extended readers and writers from the given node reference.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
*/
|
||||
// TODO rename to removeExtendedSecurity
|
||||
void removeAllExtendedSecurity(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Add extended security for the specified authorities to a node.
|
||||
* <p>
|
||||
@@ -84,17 +98,27 @@ public interface ExtendedSecurityService
|
||||
* @param readers set of authorities to add extended read permissions
|
||||
* @param writers set of authorities to add extended write permissions
|
||||
* @param applyToParents true if extended security applied to parents (read only) false otherwise.
|
||||
*
|
||||
* @deprecated as of 2.5, because extended security is no longer applied to parents. Note that calling this method will
|
||||
* only apply the exetended securiyt to the node and the applyToParents parameter value will be ignored.
|
||||
*
|
||||
* @see #addExtendedSecurity(NodeRef, Set, Set)
|
||||
*/
|
||||
void addExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers, boolean applyToParents);
|
||||
|
||||
@Deprecated void addExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers, boolean applyToParents);
|
||||
|
||||
/**
|
||||
* Remove the extended security for the specified authorities from a node.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @param readers set of authorities to remove as extended readers
|
||||
* @param writers set of authorities to remove as extended writers
|
||||
*
|
||||
* @deprecated as of 2.5, because partial removal of readers and writers from node or parents is no longer supported.
|
||||
* Note that calling this method will now remove all extended security from the node and never applied to parents.
|
||||
*
|
||||
* @see #removeAllExtendedSecurity(NodeRef)
|
||||
*/
|
||||
void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers);
|
||||
@Deprecated void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers);
|
||||
|
||||
/**
|
||||
* Remove the extended security for the specified authorities from a node.
|
||||
@@ -108,21 +132,24 @@ public interface ExtendedSecurityService
|
||||
* @param writers set of authorities to remove as extedned writers
|
||||
* @param applyToParents true if removal of extended security is applied to parent hierarchy (read only), false
|
||||
* otherwise
|
||||
*
|
||||
* @deprecated as of 2.5, because partial removal of readers and writers from node or parents is no longer supported.
|
||||
* Note that calling this method will now remove all extended security from the node and never applied to parents.
|
||||
*
|
||||
* @see #removeAllExtendedSecurity(NodeRef)
|
||||
*/
|
||||
void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers, boolean applyToParents);
|
||||
|
||||
/**
|
||||
* Remove all extended readers and writers from the given node reference.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
*/
|
||||
void removeAllExtendedSecurity(NodeRef nodeRef);
|
||||
@Deprecated void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers, boolean applyToParents);
|
||||
|
||||
/**
|
||||
* Remove all extended readers and writers from the given node reference.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @param applyToParents if true then apply removal to parent hierarchy (read only) false otherwise.
|
||||
*
|
||||
* @deprecated as of 2.5, because partial removal of readers and writers from node or parents is no longer supported.
|
||||
* Note that calling this method will now remove all extended security from the node and never applied to parents.
|
||||
*
|
||||
* @see #removeAllExtendedSecurity(NodeRef)
|
||||
*/
|
||||
void removeAllExtendedSecurity(NodeRef nodeRef, boolean applyToParents);
|
||||
@Deprecated void removeAllExtendedSecurity(NodeRef nodeRef, boolean applyToParents);
|
||||
}
|
||||
|
@@ -27,23 +27,28 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.security;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.RenditionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessPermission;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.springframework.extensions.webscripts.ui.common.StringUtils;
|
||||
|
||||
import com.google.gdata.util.common.base.Pair;
|
||||
|
||||
/**
|
||||
* Extended security service implementation.
|
||||
@@ -55,11 +60,20 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
implements ExtendedSecurityService,
|
||||
RecordsManagementModel
|
||||
{
|
||||
private static final String READER_GROUP_PREFIX = ExtendedSecurityService.IPR_GROUP_PREFIX + "R_";
|
||||
private static final String WRITER_GROUP_PREFIX = ExtendedSecurityService.IPR_GROUP_PREFIX + "W_";
|
||||
|
||||
/** File plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
/** File plan role service */
|
||||
private FilePlanRoleService filePlanRoleService;
|
||||
|
||||
/** authority service */
|
||||
private AuthorityService authorityService;
|
||||
|
||||
/** permission service */
|
||||
private PermissionService permissionService;
|
||||
|
||||
/**
|
||||
* @param filePlanService file plan service
|
||||
@@ -76,13 +90,29 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
{
|
||||
this.filePlanRoleService = filePlanRoleService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authorityService authority service
|
||||
*/
|
||||
public void setAuthorityService(AuthorityService authorityService)
|
||||
{
|
||||
this.authorityService = authorityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permissionService permission service
|
||||
*/
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#hasExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public boolean hasExtendedSecurity(NodeRef nodeRef)
|
||||
{
|
||||
return nodeService.hasAspect(nodeRef, ASPECT_EXTENDED_SECURITY);
|
||||
return (getIPRGroups(nodeRef) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,13 +123,18 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
public Set<String> getExtendedReaders(NodeRef nodeRef)
|
||||
{
|
||||
Set<String> result = null;
|
||||
|
||||
Map<String, Integer> readerMap = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_READERS);
|
||||
if (readerMap != null)
|
||||
|
||||
Pair<String, String> iprGroups = getIPRGroups(nodeRef);
|
||||
if (iprGroups != null)
|
||||
{
|
||||
result = readerMap.keySet();
|
||||
result = authorityService.getContainedAuthorities(null, iprGroups.first, true);
|
||||
result.remove(iprGroups.second);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
result = Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -111,14 +146,19 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
public Set<String> getExtendedWriters(NodeRef nodeRef)
|
||||
{
|
||||
Set<String> result = null;
|
||||
|
||||
Map<String, Integer> map = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_WRITERS);
|
||||
if (map != null)
|
||||
|
||||
Pair<String, String> iprGroups = getIPRGroups(nodeRef);
|
||||
if (iprGroups != null)
|
||||
{
|
||||
result = map.keySet();
|
||||
result = authorityService.getContainedAuthorities(null, iprGroups.second, true);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
result = Collections.EMPTY_SET;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,25 +166,15 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
*/
|
||||
@Override
|
||||
public void addExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers)
|
||||
{
|
||||
addExtendedSecurity(nodeRef, readers, writers, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#addExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void addExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers, boolean applyToParents)
|
||||
{
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
ParameterCheck.mandatory("applyToParents", applyToParents);
|
||||
|
||||
if (nodeRef != null)
|
||||
{
|
||||
addExtendedSecurityImpl(nodeRef, readers, writers, applyToParents);
|
||||
addExtendedSecurityImpl(nodeRef, readers, writers);
|
||||
|
||||
// add to the extended security roles
|
||||
addExtendedSecurityRoles(nodeRef, readers, writers);
|
||||
addExtendedSecurityRoles(nodeRef, readers, writers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,38 +186,16 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
* @param writers
|
||||
* @param applyToParents
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addExtendedSecurityImpl(final NodeRef nodeRef, Set<String> readers, Set<String> writers, boolean applyToParents)
|
||||
private void addExtendedSecurityImpl(final NodeRef nodeRef, Set<String> readers, Set<String> writers)
|
||||
{
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
ParameterCheck.mandatory("applyToParents", applyToParents);
|
||||
|
||||
// get the properties
|
||||
final Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
||||
|
||||
// update the readers map
|
||||
if (readers != null && readers.size() != 0)
|
||||
{
|
||||
// get reader map
|
||||
Map<String, Integer> readersMap = (Map<String, Integer>)properties.get(PROP_READERS);
|
||||
|
||||
// set the readers property (this will in turn apply the aspect if required)
|
||||
properties.put(PROP_READERS, (Serializable)addToMap(readersMap, readers));
|
||||
}
|
||||
|
||||
// update the writers map
|
||||
if (writers != null && writers.size() != 0)
|
||||
{
|
||||
// get writer map
|
||||
Map<String, Integer> writersMap = (Map<String, Integer>)properties.get(PROP_WRITERS);
|
||||
|
||||
// set the writers property (this will in turn apply the aspect if required)
|
||||
properties.put(PROP_WRITERS, (Serializable)addToMap(writersMap, writers));
|
||||
}
|
||||
|
||||
// set properties
|
||||
nodeService.setProperties(nodeRef, properties);
|
||||
|
||||
|
||||
// find groups
|
||||
Pair<String, String> iprGroups = getIPRGroups(readers, writers);
|
||||
|
||||
// assign groups to node
|
||||
assignIPRGroupsToNode(iprGroups, nodeRef);
|
||||
|
||||
// apply the readers to any renditions of the content
|
||||
if (isRecord(nodeRef))
|
||||
{
|
||||
@@ -195,10 +203,188 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
for (ChildAssociationRef assoc : assocs)
|
||||
{
|
||||
NodeRef child = assoc.getChildRef();
|
||||
addExtendedSecurityImpl(child, readers, writers, false);
|
||||
assignIPRGroupsToNode(iprGroups, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nodeRef
|
||||
* @return
|
||||
*/
|
||||
private Pair<String, String> getIPRGroups(NodeRef nodeRef)
|
||||
{
|
||||
Pair<String, String> result = null;
|
||||
String iprReaderGroup = null;
|
||||
String iprWriterGroup = null;
|
||||
|
||||
Set<AccessPermission> permissions = permissionService.getAllSetPermissions(nodeRef);
|
||||
for (AccessPermission permission : permissions)
|
||||
{
|
||||
if (permission.getAuthority().startsWith(PermissionService.GROUP_PREFIX + READER_GROUP_PREFIX))
|
||||
{
|
||||
iprReaderGroup = permission.getAuthority();
|
||||
}
|
||||
else if (permission.getAuthority().startsWith(PermissionService.GROUP_PREFIX + WRITER_GROUP_PREFIX))
|
||||
{
|
||||
iprWriterGroup = permission.getAuthority();
|
||||
}
|
||||
}
|
||||
|
||||
if (iprReaderGroup != null && iprWriterGroup != null)
|
||||
{
|
||||
result = new Pair<String, String>(iprReaderGroup, iprWriterGroup);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param readers
|
||||
* @param writers
|
||||
* @return
|
||||
*/
|
||||
private Pair<String, String> getIPRGroups(Set<String> readers, Set<String> writers)
|
||||
{
|
||||
Pair<String, String> result = null;
|
||||
|
||||
// see if the groups already exists or not
|
||||
String readerGroupName = getIPRGroupName(READER_GROUP_PREFIX, readers, writers, false);
|
||||
String writerGroupName = getIPRGroupName(WRITER_GROUP_PREFIX, readers, writers, false);
|
||||
if (authorityService.authorityExists(readerGroupName) &&
|
||||
authorityService.authorityExists(writerGroupName))
|
||||
{
|
||||
// check that the groups are a true match
|
||||
if (authorityService.getContainingAuthorities(AuthorityType.GROUP, writerGroupName, true).contains(readerGroupName) &&
|
||||
isIPRGroupTrueMatch(readers, readerGroupName) &&
|
||||
isIPRGroupTrueMatch(writers, writerGroupName))
|
||||
{
|
||||
// reuse the existing groups
|
||||
result = new Pair<String, String>(readerGroupName, writerGroupName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO - CLASH
|
||||
throw new AlfrescoRuntimeException("IPR Group Name Clash!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// create inplace record reader and writer groups
|
||||
result = createIPRGroups(readers, writers);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param authorities
|
||||
* @param group
|
||||
* @return
|
||||
*/
|
||||
private boolean isIPRGroupTrueMatch(Set<String> authorities, String group)
|
||||
{
|
||||
// TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param prefix
|
||||
* @param authorities
|
||||
* @param shortName
|
||||
* @return
|
||||
*/
|
||||
private String getIPRGroupName(String prefix, Set<String> readers, Set<String> writers, boolean shortName)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(128);
|
||||
|
||||
if (!shortName)
|
||||
{
|
||||
builder.append(PermissionService.GROUP_PREFIX);
|
||||
}
|
||||
|
||||
builder.append(prefix)
|
||||
.append(getAuthoritySetHashCode(readers))
|
||||
.append("-")
|
||||
.append(getAuthoritySetHashCode(writers));
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param authorities
|
||||
* @return
|
||||
*/
|
||||
private int getAuthoritySetHashCode(Set<String> authorities)
|
||||
{
|
||||
int result = 0;
|
||||
if (authorities != null && !authorities.isEmpty())
|
||||
{
|
||||
result = StringUtils.join(authorities.toArray(), "").hashCode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param readers
|
||||
* @param writers
|
||||
* @return
|
||||
*/
|
||||
private Pair<String, String> createIPRGroups(Set<String> readers, Set<String> writers)
|
||||
{
|
||||
String iprReaderGroup = createIPRGroup(getIPRGroupName(READER_GROUP_PREFIX, readers, writers, true), null, readers);
|
||||
String iprWriterGroup = createIPRGroup(getIPRGroupName(WRITER_GROUP_PREFIX, readers, writers, true), iprReaderGroup, writers);
|
||||
return new Pair<String, String>(iprReaderGroup, iprWriterGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupShortName
|
||||
* @param parent
|
||||
* @param children
|
||||
* @return
|
||||
*/
|
||||
private String createIPRGroup(String groupShortName, String parent, Set<String> children)
|
||||
{
|
||||
ParameterCheck.mandatory("groupShortName", groupShortName);
|
||||
|
||||
String group = authorityService.createAuthority(AuthorityType.GROUP, groupShortName); // TODO set appropriate zone
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
authorityService.addAuthority(parent, group);
|
||||
}
|
||||
|
||||
if (children != null)
|
||||
{
|
||||
for (String child : children)
|
||||
{
|
||||
if (!PermissionService.ALL_AUTHORITIES.equals(child))
|
||||
{
|
||||
authorityService.addAuthority(group, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param iprGroups
|
||||
* @param nodeRef
|
||||
*/
|
||||
private void assignIPRGroupsToNode(Pair<String, String> iprGroups, NodeRef nodeRef)
|
||||
{
|
||||
permissionService.setPermission(nodeRef, iprGroups.first, RMPermissionModel.READ_RECORDS, true);
|
||||
permissionService.setPermission(nodeRef, iprGroups.second, RMPermissionModel.FILING, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -235,60 +421,16 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param map
|
||||
* @param keys
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Integer> addToMap(Map<String, Integer> map, Set<String> keys)
|
||||
{
|
||||
if (map == null)
|
||||
{
|
||||
// create map
|
||||
map = new HashMap<String, Integer>(7);
|
||||
}
|
||||
|
||||
for (String key : keys)
|
||||
{
|
||||
if (!key.equals(PermissionService.ALL_AUTHORITIES))
|
||||
{
|
||||
if (map.containsKey(key))
|
||||
{
|
||||
// increment reference count
|
||||
Integer count = map.get(key);
|
||||
map.put(key, Integer.valueOf(count.intValue()+1));
|
||||
}
|
||||
else
|
||||
{
|
||||
// add key with initial count
|
||||
map.put(key, Integer.valueOf(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set)
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeAllExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers)
|
||||
{
|
||||
removeExtendedSecurity(nodeRef, readers, writers, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String>writers, boolean applyToParents)
|
||||
public void removeAllExtendedSecurity(NodeRef nodeRef)
|
||||
{
|
||||
if (hasExtendedSecurity(nodeRef))
|
||||
{
|
||||
removeExtendedSecurityImpl(nodeRef, readers, writers);
|
||||
removeExtendedSecurityImpl(nodeRef);
|
||||
|
||||
// remove the readers from any renditions of the content
|
||||
if (isRecord(nodeRef))
|
||||
@@ -297,110 +439,62 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl
|
||||
for (ChildAssociationRef assoc : assocs)
|
||||
{
|
||||
NodeRef child = assoc.getChildRef();
|
||||
removeExtendedSecurityImpl(child, readers, writers);
|
||||
}
|
||||
}
|
||||
|
||||
if (applyToParents)
|
||||
{
|
||||
// apply the extended readers up the file plan primary hierarchy
|
||||
NodeRef parent = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||
if (parent != null &&
|
||||
filePlanService.isFilePlanComponent(parent))
|
||||
{
|
||||
removeExtendedSecurity(parent, readers, null, applyToParents);
|
||||
removeExtendedSecurity(parent, writers, null, applyToParents);
|
||||
removeExtendedSecurityImpl(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a set of readers and writers from a node reference.
|
||||
* <p>
|
||||
* Removes the aspect and resets the property to null if all readers and writers are removed.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
* @param readers {@link Set} of readers
|
||||
* @param writers {@link Set} of writers
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param readers
|
||||
* @param writers
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void removeExtendedSecurityImpl(NodeRef nodeRef, Set<String> readers, Set<String> writers)
|
||||
private void removeExtendedSecurityImpl(NodeRef nodeRef)
|
||||
{
|
||||
Map<String, Integer> readersMap = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_READERS);
|
||||
nodeService.setProperty(nodeRef, PROP_READERS, (Serializable)removeFromMap(readersMap, readers));
|
||||
|
||||
Map<String, Integer> writersMap = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_WRITERS);
|
||||
nodeService.setProperty(nodeRef, PROP_WRITERS, (Serializable)removeFromMap(writersMap, writers));
|
||||
|
||||
if (readersMap == null && writersMap == null)
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
|
||||
Pair<String, String> iprGroups = getIPRGroups(nodeRef);
|
||||
if (iprGroups != null)
|
||||
{
|
||||
// remove the aspect
|
||||
nodeService.removeAspect(nodeRef, ASPECT_EXTENDED_SECURITY);
|
||||
// remove group permissions from node
|
||||
permissionService.clearPermission(nodeRef, iprGroups.first);
|
||||
permissionService.clearPermission(nodeRef, iprGroups.second);
|
||||
|
||||
// TODO delete the groups if they are no longer in use (easier said than done perhaps!)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#addExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set, boolean)
|
||||
*/
|
||||
@Override @Deprecated public void addExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers, boolean applyToParents)
|
||||
{
|
||||
addExtendedSecurity(nodeRef, readers, writers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set)
|
||||
*/
|
||||
@Override @Deprecated public void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String> writers)
|
||||
{
|
||||
removeAllExtendedSecurity(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to remove items from map or reduce reference count
|
||||
*
|
||||
* @param map ref count map
|
||||
* @param keys keys
|
||||
* @return Map<String, Integer> ref count map
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set, boolean)
|
||||
*/
|
||||
private Map<String, Integer> removeFromMap(Map<String, Integer> map, Set<String> keys)
|
||||
@Override @Deprecated public void removeExtendedSecurity(NodeRef nodeRef, Set<String> readers, Set<String>writers, boolean applyToParents)
|
||||
{
|
||||
if (map != null && keys != null && keys.size() != 0)
|
||||
{
|
||||
// remove the keys
|
||||
for (String key : keys)
|
||||
{
|
||||
if (!key.equals(PermissionService.ALL_AUTHORITIES))
|
||||
{
|
||||
Integer count = map.get(key);
|
||||
if (count != null)
|
||||
{
|
||||
if (count == 1)
|
||||
{
|
||||
// remove entry all together if the reference count is now 0
|
||||
map.remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
// decrement the reference count by 1
|
||||
map.put(key, Integer.valueOf(count.intValue()-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reset the map to null if now empty
|
||||
if (map != null && map.isEmpty())
|
||||
{
|
||||
map = null;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeAllExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void removeAllExtendedSecurity(NodeRef nodeRef)
|
||||
{
|
||||
removeAllExtendedSecurity(nodeRef, true);
|
||||
removeAllExtendedSecurity(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeAllExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void removeAllExtendedSecurity(NodeRef nodeRef, boolean applyToParents)
|
||||
@Override @Deprecated public void removeAllExtendedSecurity(NodeRef nodeRef, boolean applyToParents)
|
||||
{
|
||||
if (hasExtendedSecurity(nodeRef))
|
||||
{
|
||||
removeExtendedSecurity(nodeRef, getExtendedReaders(nodeRef), getExtendedWriters(nodeRef));
|
||||
}
|
||||
removeAllExtendedSecurity(nodeRef);
|
||||
}
|
||||
}
|
||||
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.security;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.repo.security.permissions.PermissionReference;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Extended writers dynamic authority implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedWriterDynamicAuthority extends ExtendedSecurityBaseDynamicAuthority
|
||||
{
|
||||
/** Extended writer role */
|
||||
public static final String EXTENDED_WRITER = "ROLE_EXTENDED_WRITER";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.DynamicAuthority#getAuthority()
|
||||
*/
|
||||
@Override
|
||||
public String getAuthority()
|
||||
{
|
||||
return EXTENDED_WRITER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.DynamicAuthority#requiredFor()
|
||||
*/
|
||||
@Override
|
||||
public Set<PermissionReference> requiredFor()
|
||||
{
|
||||
if (requiredFor == null)
|
||||
{
|
||||
requiredFor = new HashSet<PermissionReference>(3);
|
||||
Collections.addAll(requiredFor,
|
||||
getModelDAO().getPermissionReference(null, RMPermissionModel.READ_RECORDS),
|
||||
getModelDAO().getPermissionReference(null, RMPermissionModel.FILING),
|
||||
getModelDAO().getPermissionReference(null, RMPermissionModel.FILE_RECORDS));
|
||||
}
|
||||
|
||||
return requiredFor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityBaseDynamicAuthority#getAuthorites(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<String> getAuthorites(NodeRef nodeRef)
|
||||
{
|
||||
Set<String> result = null;
|
||||
|
||||
Map<String, Integer> map = (Map<String, Integer>)getNodeService().getProperty(nodeRef, PROP_WRITERS);
|
||||
if (map != null)
|
||||
{
|
||||
result = map.keySet();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityBaseDynamicAuthority#getTransactionCacheName()
|
||||
*/
|
||||
@Override
|
||||
protected String getTransactionCacheName()
|
||||
{
|
||||
return "rm.extendedwriterdynamicauthority";
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.security;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
|
||||
/**
|
||||
* File plan authentication service.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
* @deprecated as of 2.2, use {@link AuthenticationUtil}.
|
||||
*/
|
||||
public interface FilePlanAuthenticationService
|
||||
{
|
||||
/**
|
||||
* @return rm admin user name
|
||||
*
|
||||
* @deprecated as of 2.2, use {@link AuthenticationUtil#getAdminUserName()}
|
||||
*/
|
||||
String getRmAdminUserName();
|
||||
|
||||
/**
|
||||
* Run provided work as the global rm admin user.
|
||||
*
|
||||
* @param <R> return type
|
||||
* @param runAsWork work to execute as the rm admin user
|
||||
* @return R result of work execution
|
||||
*
|
||||
* @deprecated as of 2.2, use {@link AuthenticationUtil#runAs(RunAsWork, AuthenticationUtil#getAdminUserName())}
|
||||
*/
|
||||
<R> R runAsRmAdmin(RunAsWork<R> runAsWork);
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* -
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
* -
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.security;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class FilePlanAuthenticationServiceImpl implements FilePlanAuthenticationService
|
||||
{
|
||||
/** Default rm admin user values */
|
||||
@Deprecated
|
||||
public static final String DEFAULT_RM_ADMIN_USER = "rmadmin";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.FilePlanAuthenticationService#getRMAdminUserName()
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public String getRmAdminUserName()
|
||||
{
|
||||
return AuthenticationUtil.getAdminUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.security.FilePlanAuthenticationService#runAsRMAdmin(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public <R> R runAsRmAdmin(RunAsWork<R> runAsWork)
|
||||
{
|
||||
return AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getAdminUserName());
|
||||
}
|
||||
}
|
@@ -27,8 +27,6 @@
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.security;
|
||||
|
||||
import static org.alfresco.module.org_alfresco_module_rm.security.ExtendedReaderDynamicAuthority.EXTENDED_READER;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.security.ExtendedWriterDynamicAuthority.EXTENDED_WRITER;
|
||||
import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.TRANSACTION_COMMIT;
|
||||
import static org.alfresco.repo.policy.annotation.BehaviourKind.CLASS;
|
||||
import static org.alfresco.repo.security.authentication.AuthenticationUtil.getSystemUserName;
|
||||
@@ -383,13 +381,29 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl
|
||||
boolean inheritanceAllowed = isInheritanceAllowed(nodeRef, isParentNodeFilePlan);
|
||||
getPermissionService().setInheritParentPermissions(nodeRef, inheritanceAllowed);
|
||||
|
||||
// clear all existing permissions
|
||||
Set<AccessPermission> keepPerms = new HashSet<AccessPermission>(5);
|
||||
Set<AccessPermission> origionalPerms= getPermissionService().getAllSetPermissions(nodeRef);
|
||||
|
||||
for (AccessPermission perm : origionalPerms)
|
||||
{
|
||||
if (perm.getAuthority().startsWith(PermissionService.GROUP_PREFIX + ExtendedSecurityService.IPR_GROUP_PREFIX))
|
||||
{
|
||||
// then we can assume this is a permission we want to preserve
|
||||
keepPerms.add(perm);
|
||||
}
|
||||
}
|
||||
|
||||
// clear all existing permissions and start again
|
||||
getPermissionService().clearPermission(nodeRef, null);
|
||||
|
||||
// re-add keep'er permissions
|
||||
for (AccessPermission keeper : keepPerms)
|
||||
{
|
||||
setPermission(nodeRef, keeper.getAuthority(), keeper.getPermission());
|
||||
}
|
||||
|
||||
if (!inheritanceAllowed)
|
||||
{
|
||||
getPermissionService().setPermission(nodeRef, EXTENDED_READER, READ_RECORDS, true);
|
||||
getPermissionService().setPermission(nodeRef, EXTENDED_WRITER, FILING, true);
|
||||
String adminRole = getAdminRole(nodeRef);
|
||||
getPermissionService().setPermission(nodeRef, adminRole, RMPermissionModel.FILING, true);
|
||||
}
|
||||
@@ -494,11 +508,8 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl
|
||||
for (AccessPermission recordPermission : origionalRecordPerms)
|
||||
{
|
||||
String permission = recordPermission.getPermission();
|
||||
String authority = recordPermission.getAuthority();
|
||||
if ((RMPermissionModel.FILING.equals(permission) || RMPermissionModel.READ_RECORDS.equals(permission)) &&
|
||||
recordPermission.isSetDirectly() &&
|
||||
!ExtendedReaderDynamicAuthority.EXTENDED_READER.equals(authority) &&
|
||||
!ExtendedWriterDynamicAuthority.EXTENDED_WRITER.equals(authority))
|
||||
recordPermission.isSetDirectly())
|
||||
{
|
||||
// then we can assume this is a permission we want to preserve
|
||||
keepPerms.add(recordPermission);
|
||||
@@ -506,7 +517,7 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl
|
||||
}
|
||||
|
||||
// clear all existing permissions and start again
|
||||
permissionService.deletePermissions(record);
|
||||
// permissionService.deletePermissions(record);
|
||||
|
||||
// re-setup the records permissions
|
||||
setupPermissions(destinationAssocRef.getParentRef(), record);
|
||||
|
@@ -337,9 +337,6 @@ public class ExtendedPermissionServiceImpl extends PermissionServiceImpl impleme
|
||||
if (nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) && isNotBlank(adminRole)
|
||||
&& !inheritParentPermissions)
|
||||
{
|
||||
setPermission(nodeRef, ExtendedReaderDynamicAuthority.EXTENDED_READER, RMPermissionModel.READ_RECORDS,
|
||||
true);
|
||||
setPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER, RMPermissionModel.FILING, true);
|
||||
setPermission(nodeRef, adminRole, RMPermissionModel.FILING, true);
|
||||
}
|
||||
super.setInheritParentPermissions(nodeRef, inheritParentPermissions);
|
||||
|
Reference in New Issue
Block a user