mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-07 18:25:23 +00:00
13218: Partial fix for ETHREEOH-1259 - the null pointer exceptions are gone to be replaced by sensible error messages. 13220: Merged V3.0 to V3.1 13219: Build Fix for error in hand merge of r13141 from V2.2 to V3.0 13226: Clearer debugging of exceptions during NodeService cleanup 13228: ETHREEOH-1250 13229: Fix for ETHREEOH-1184: Share webscript configuration does not support international chars as values 13235: Add support to exclude admin and guest from person permission fix ups. Tidy up for ETHREEOH-1239 13239: Build Fix 13243: ETHREEOH-1308: Update AMPs to indicate unsupported status 13247: Build fix - do not delete admin :-) 13248: Fix build 13254: Fix for ETHREEOH-1351: Schemas containing an enumeration with an empty string ... ___________________________________________________________________ Modified: svn:mergeinfo Merged /alfresco/BRANCHES/V3.0:r13219 Merged /alfresco/BRANCHES/V3.1:r13218-13220,13224,13226-13229,13231-13232,13234-13237,13239,13241,13243-13248,13250,13252-13254 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13612 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
265 lines
7.7 KiB
Java
265 lines
7.7 KiB
Java
/*
|
|
* 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.person;
|
|
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
import org.alfresco.repo.security.permissions.impl.AccessPermissionImpl;
|
|
import org.alfresco.service.ServiceRegistry;
|
|
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.OwnableService;
|
|
import org.alfresco.service.cmr.security.PermissionService;
|
|
|
|
public class PermissionsManagerImpl implements PermissionsManager
|
|
{
|
|
|
|
/**
|
|
* Set if permissions are inherited when nodes are created.
|
|
*/
|
|
private Boolean inheritPermissions;
|
|
|
|
/**
|
|
* A set of permissions to set for the owner when a home folder is created
|
|
*/
|
|
private Set<String> ownerPermissions;
|
|
|
|
/**
|
|
* General permissions to set on the node Map<(String)uid, Set<(String)permission>>.
|
|
*/
|
|
private Map<String, Set<String>> permissions;
|
|
|
|
/**
|
|
* Permissions to set for the user - on create and reference.
|
|
*/
|
|
private Set<String> userPermissions;
|
|
|
|
/**
|
|
* Clear existing permissions on new home folders (useful of created from a template.
|
|
*/
|
|
private Boolean clearExistingPermissions;
|
|
|
|
private OwnableService ownableService;
|
|
|
|
private PermissionService permissionService;
|
|
|
|
public boolean getInheritPermissions()
|
|
{
|
|
return inheritPermissions;
|
|
}
|
|
|
|
public void setInheritPermissions(boolean inheritPermissions)
|
|
{
|
|
this.inheritPermissions = inheritPermissions;
|
|
}
|
|
|
|
public Set<String> getOwnerPermissions()
|
|
{
|
|
return ownerPermissions;
|
|
}
|
|
|
|
public void setOwnerPermissions(Set<String> ownerPermissions)
|
|
{
|
|
this.ownerPermissions = ownerPermissions;
|
|
}
|
|
|
|
public Map<String, Set<String>> getPermissions()
|
|
{
|
|
return permissions;
|
|
}
|
|
|
|
public void setPermissions(Map<String, Set<String>> permissions)
|
|
{
|
|
this.permissions = permissions;
|
|
}
|
|
|
|
public Set<String> getUserPermissions()
|
|
{
|
|
return userPermissions;
|
|
}
|
|
|
|
public void setUserPermissions(Set<String> userPermissions)
|
|
{
|
|
this.userPermissions = userPermissions;
|
|
}
|
|
|
|
public boolean getClearExistingPermissions()
|
|
{
|
|
return clearExistingPermissions;
|
|
}
|
|
|
|
public void setClearExistingPermissions(boolean clearExistingPermissions)
|
|
{
|
|
this.clearExistingPermissions = clearExistingPermissions;
|
|
}
|
|
|
|
public void setOwnableService(OwnableService ownableService)
|
|
{
|
|
this.ownableService = ownableService;
|
|
}
|
|
|
|
public void setPermissionService(PermissionService permissionService)
|
|
{
|
|
this.permissionService = permissionService;
|
|
}
|
|
|
|
public void setPermissions(NodeRef nodeRef, String owner, String user)
|
|
{
|
|
// Set to a specified owner
|
|
if (owner != null)
|
|
{
|
|
ownableService.setOwner(nodeRef, owner);
|
|
}
|
|
|
|
// clear permissions - useful of not required from a template
|
|
|
|
if ((clearExistingPermissions != null) && clearExistingPermissions.booleanValue())
|
|
{
|
|
permissionService.deletePermissions(nodeRef);
|
|
}
|
|
|
|
// inherit permissions
|
|
|
|
if (inheritPermissions != null)
|
|
{
|
|
permissionService.setInheritParentPermissions(nodeRef, inheritPermissions.booleanValue());
|
|
}
|
|
|
|
// Set owner permissions
|
|
|
|
if (ownerPermissions != null)
|
|
{
|
|
for (String permission : ownerPermissions)
|
|
{
|
|
permissionService.setPermission(nodeRef, PermissionService.OWNER_AUTHORITY, permission, true);
|
|
}
|
|
}
|
|
|
|
// Add other permissions
|
|
|
|
if (permissions != null)
|
|
{
|
|
for (String userForPermission : permissions.keySet())
|
|
{
|
|
Set<String> set = permissions.get(user);
|
|
if (set != null)
|
|
{
|
|
for (String permission : set)
|
|
{
|
|
permissionService.setPermission(nodeRef, userForPermission, permission, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add user permissions on create and reference
|
|
|
|
if (userPermissions != null)
|
|
{
|
|
for (String permission : userPermissions)
|
|
{
|
|
permissionService.setPermission(nodeRef, user, permission, true);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public boolean validatePermissions(NodeRef nodeRef, String owner, String user)
|
|
{
|
|
if (owner != null)
|
|
{
|
|
String setOwner = ownableService.getOwner(nodeRef);
|
|
if (!owner.equals(setOwner))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// inherit permissions
|
|
|
|
if (inheritPermissions != null)
|
|
{
|
|
if (inheritPermissions != permissionService.getInheritParentPermissions(nodeRef))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Set<AccessPermission> setPermissions = permissionService.getAllSetPermissions(nodeRef);
|
|
|
|
if (ownerPermissions != null)
|
|
{
|
|
for (String permission : ownerPermissions)
|
|
{
|
|
AccessPermission required = new AccessPermissionImpl(permission, AccessStatus.ALLOWED, PermissionService.OWNER_AUTHORITY, 0);
|
|
if (!setPermissions.contains(required))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add other permissions
|
|
|
|
if (permissions != null)
|
|
{
|
|
for (String userForPermission : permissions.keySet())
|
|
{
|
|
Set<String> set = permissions.get(user);
|
|
if (set != null)
|
|
{
|
|
for (String permission : set)
|
|
{
|
|
AccessPermission required = new AccessPermissionImpl(permission, AccessStatus.ALLOWED, userForPermission, 0);
|
|
if (!setPermissions.contains(required))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (userPermissions != null)
|
|
{
|
|
for (String permission : userPermissions)
|
|
{
|
|
AccessPermission required = new AccessPermissionImpl(permission, AccessStatus.ALLOWED, user, 0);
|
|
if (!setPermissions.contains(required))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: Check we have no extras if we should have cleared permissions ... ??
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|