use of org.alfresco.service.cmr.security.AccessPermission in project alfresco-remote-api by Alfresco.
the class NodeApiTest method validatePermissionsAfterUpdate.
private void validatePermissionsAfterUpdate(NodeRef nodeRef, List<NodePermissions.NodePermission> expectedPermissions) {
Set<AccessPermission> permissions = permissionService.getAllSetPermissions(nodeRef);
for (NodePermissions.NodePermission permission : expectedPermissions) {
String authority = permission.getAuthorityId();
AccessPermission ap = getPermission(permissions, authority);
assertNotNull("Permission " + authority + " missing", ap);
assertEquals(authority, ap.getAuthority());
comparePermissions(authority, permission, ap);
}
}
use of org.alfresco.service.cmr.security.AccessPermission in project acs-community-packaging by Alfresco.
the class EmailSpaceUsersDialog method getUsersGroups.
/**
* Return the List of objects representing the Users and Groups invited to this space.
* The picker is then responsible for rendering a view to represent those users and groups
* which allows the users to select and deselect users and groups, also to expand groups
* to show sub-groups and users.
*
* @return List of Map objects representing the users/groups assigned to the current space
*/
public List<Map> getUsersGroups() {
if (this.usersGroups == null) {
FacesContext context = FacesContext.getCurrentInstance();
UserTransaction tx = null;
try {
tx = Repository.getUserTransaction(context, true);
tx.begin();
// Return all the permissions set against the current node for any authentication
// instance (user/group), walking the parent space inheritance chain.
// Then combine them into a single list for each authentication found.
final String currentAuthority = Application.getCurrentUser(context).getUserName();
Map<String, List<String>> permissionMap = AuthenticationUtil.runAs(new RunAsWork<Map<String, List<String>>>() {
public Map<String, List<String>> doWork() throws Exception {
NodeRef spaceRef = getSpace().getNodeRef();
Map<String, List<String>> permissionMap = new HashMap<String, List<String>>(8, 1.0f);
while (spaceRef != null) {
Set<AccessPermission> permissions = getPermissionService().getAllSetPermissions(spaceRef);
for (AccessPermission permission : permissions) {
// we are only interested in Allow and not Guest/Everyone/owner
if (permission.getAccessStatus() == AccessStatus.ALLOWED && (permission.getAuthorityType() == AuthorityType.USER || permission.getAuthorityType() == AuthorityType.GROUP)) {
String authority = permission.getAuthority();
if (currentAuthority.equals(authority) == false) {
List<String> userPermissions = permissionMap.get(authority);
if (userPermissions == null) {
// create for first time
userPermissions = new ArrayList<String>(4);
permissionMap.put(authority, userPermissions);
}
// add the permission name for this authority
userPermissions.add(permission.getPermission());
}
}
}
// walk parent inheritance chain until root or no longer inherits
if (getPermissionService().getInheritParentPermissions(spaceRef)) {
spaceRef = getNodeService().getPrimaryParent(spaceRef).getParentRef();
} else {
spaceRef = null;
}
}
return permissionMap;
}
}, AuthenticationUtil.SYSTEM_USER_NAME);
// create the structure as a linked list for fast insert/removal of items
this.usersGroups = new LinkedList<Map>();
// node represented by it and use that for our list databinding object
for (String authority : permissionMap.keySet()) {
Map node = buildAuthorityMap(authority, UserMembersBean.roleListToString(context, permissionMap.get(authority)));
if (node != null) {
this.usersGroups.add(node);
}
}
// commit the transaction
tx.commit();
} catch (InvalidNodeRefException refErr) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }));
this.usersGroups = Collections.<Map>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), err.getMessage()), err);
this.usersGroups = Collections.<Map>emptyList();
try {
if (tx != null) {
tx.rollback();
}
} catch (Exception tex) {
}
}
}
return this.usersGroups;
}
use of org.alfresco.service.cmr.security.AccessPermission in project records-management by Alfresco.
the class FilePlanRoleServiceImpl method getCapabilitiesImpl.
/**
* @param rmRootNode
* @param roleAuthority
* @return
*/
private Set<Capability> getCapabilitiesImpl(NodeRef rmRootNode, String roleAuthority) {
Set<AccessPermission> permissions = permissionService.getAllSetPermissions(rmRootNode);
Set<Capability> capabilities = new HashSet<Capability>(52);
for (AccessPermission permission : permissions) {
if (permission.getAuthority().equals(roleAuthority)) {
String capabilityName = permission.getPermission();
Capability capability = capabilityService.getCapability(capabilityName);
if (capability != null && !capability.isPrivate()) {
capabilities.add(capability);
}
}
}
return capabilities;
}
use of org.alfresco.service.cmr.security.AccessPermission in project records-management by Alfresco.
the class ExtendedSecurityServiceImplUnitTest method removeAllExtendedSecurity.
/**
* Given that a node has extended security
* When I remove the extended security
* Then the inplace groups permissions are removed
*/
@Test
public void removeAllExtendedSecurity() {
// group names
String readGroup = extendedSecurityService.getIPRGroupShortName(READER_GROUP_FULL_PREFIX, READERS, 0);
String writeGroup = extendedSecurityService.getIPRGroupShortName(WRITER_GROUP_FULL_PREFIX, WRITERS, 0);
// setup permissions
Set<AccessPermission> permissions = Stream.of(new AccessPermissionImpl(AlfMock.generateText(), AccessStatus.ALLOWED, readGroup, 0), new AccessPermissionImpl(AlfMock.generateText(), AccessStatus.ALLOWED, AlfMock.generateText(), 1), new AccessPermissionImpl(AlfMock.generateText(), AccessStatus.ALLOWED, writeGroup, 2)).collect(Collectors.toSet());
when(mockedPermissionService.getAllSetPermissions(nodeRef)).thenReturn(permissions);
// remove extended security
extendedSecurityService.remove(nodeRef);
// verify that the groups permissions have been removed
verify(mockedPermissionService).clearPermission(nodeRef, readGroup);
verify(mockedPermissionService).clearPermission(nodeRef, writeGroup);
}
use of org.alfresco.service.cmr.security.AccessPermission in project records-management by Alfresco.
the class FilePlanPermissionServiceImplTest method assertExistenceOfSpecialRolesAndPermissions.
private void assertExistenceOfSpecialRolesAndPermissions(NodeRef node) {
Map<String, String> accessPermissions = new HashMap<String, String>();
Set<AccessPermission> permissions = permissionService.getAllSetPermissions(node);
for (AccessPermission permission : permissions) {
accessPermissions.put(permission.getAuthority(), permission.getPermission());
}
String adminRole = authorityService.getName(AuthorityType.GROUP, FilePlanRoleService.ROLE_ADMIN + filePlan.getId());
assertTrue(accessPermissions.containsKey(adminRole));
assertEquals(RMPermissionModel.FILING, accessPermissions.get(adminRole));
}
Aggregations