mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.2) to HEAD (5.2)
134828 cturlica: REPO-1878: Support GROUP_EVERYONE in all endpoints - initial commit git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@137370 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -59,6 +59,7 @@ import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
|||||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||||
|
import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException;
|
||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
@@ -84,6 +85,7 @@ public class GroupsImpl implements Groups
|
|||||||
private static final int MAX_ZONES = 1;
|
private static final int MAX_ZONES = 1;
|
||||||
private static final String DISPLAY_NAME = "displayName";
|
private static final String DISPLAY_NAME = "displayName";
|
||||||
private static final String AUTHORITY_NAME = "authorityName";
|
private static final String AUTHORITY_NAME = "authorityName";
|
||||||
|
private static final String ERR_MSG_MODIFY_FIXED_AUTHORITY = "Trying to modify a fixed authority";
|
||||||
|
|
||||||
private final static Map<String, String> SORT_PARAMS_TO_NAMES;
|
private final static Map<String, String> SORT_PARAMS_TO_NAMES;
|
||||||
static
|
static
|
||||||
@@ -154,7 +156,14 @@ public class GroupsImpl implements Groups
|
|||||||
validateGroupId(groupId, false);
|
validateGroupId(groupId, false);
|
||||||
validateGroup(group, true);
|
validateGroup(group, true);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
authorityService.setAuthorityDisplayName(groupId, group.getDisplayName());
|
authorityService.setAuthorityDisplayName(groupId, group.getDisplayName());
|
||||||
|
}
|
||||||
|
catch (AuthorityException ae)
|
||||||
|
{
|
||||||
|
handleAuthorityException(ae);
|
||||||
|
}
|
||||||
|
|
||||||
return getGroup(groupId, parameters);
|
return getGroup(groupId, parameters);
|
||||||
}
|
}
|
||||||
@@ -685,22 +694,33 @@ public class GroupsImpl implements Groups
|
|||||||
authorityService.deleteAuthority(groupId, cascade);
|
authorityService.deleteAuthority(groupId, cascade);
|
||||||
}
|
}
|
||||||
catch (AuthorityException ae)
|
catch (AuthorityException ae)
|
||||||
|
{
|
||||||
|
handleAuthorityException(ae);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAuthorityException(AuthorityException ae)
|
||||||
{
|
{
|
||||||
if (ae.getMsgId().equals("Trying to modify a fixed authority"))
|
if (ae.getMsgId().equals("Trying to modify a fixed authority"))
|
||||||
{
|
{
|
||||||
throw new ConstraintViolatedException("Trying to modify a fixed authority");
|
throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw ae;
|
throw ae;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters)
|
public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters)
|
||||||
{
|
{
|
||||||
validateGroupId(groupId, false);
|
validateGroupId(groupId, false);
|
||||||
|
|
||||||
|
// Not allowed to list all members.
|
||||||
|
if (PermissionService.ALL_AUTHORITIES.equals(groupId))
|
||||||
|
{
|
||||||
|
throw new UnsupportedResourceOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
Paging paging = parameters.getPaging();
|
Paging paging = parameters.getPaging();
|
||||||
|
|
||||||
// Retrieve sort column. This is limited for now to sort column due to
|
// Retrieve sort column. This is limited for now to sort column due to
|
||||||
@@ -748,6 +768,13 @@ public class GroupsImpl implements Groups
|
|||||||
public GroupMember createGroupMember(String groupId, GroupMember groupMember)
|
public GroupMember createGroupMember(String groupId, GroupMember groupMember)
|
||||||
{
|
{
|
||||||
validateGroupId(groupId, false);
|
validateGroupId(groupId, false);
|
||||||
|
|
||||||
|
// Not allowed to modify a GROUP_EVERYONE member.
|
||||||
|
if (PermissionService.ALL_AUTHORITIES.equals(groupId))
|
||||||
|
{
|
||||||
|
throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
|
||||||
|
}
|
||||||
|
|
||||||
validateGroupMember(groupMember);
|
validateGroupMember(groupMember);
|
||||||
|
|
||||||
AuthorityType authorityType = getAuthorityType(groupMember.getMemberType());
|
AuthorityType authorityType = getAuthorityType(groupMember.getMemberType());
|
||||||
@@ -773,6 +800,13 @@ public class GroupsImpl implements Groups
|
|||||||
public void deleteGroupMembership(String groupId, String groupMemberId)
|
public void deleteGroupMembership(String groupId, String groupMemberId)
|
||||||
{
|
{
|
||||||
validateGroupId(groupId, false);
|
validateGroupId(groupId, false);
|
||||||
|
|
||||||
|
// Not allowed to modify a GROUP_EVERYONE member.
|
||||||
|
if (PermissionService.ALL_AUTHORITIES.equals(groupId))
|
||||||
|
{
|
||||||
|
throw new ConstraintViolatedException(ERR_MSG_MODIFY_FIXED_AUTHORITY);
|
||||||
|
}
|
||||||
|
|
||||||
validateGroupMemberId(groupMemberId);
|
validateGroupMemberId(groupMemberId);
|
||||||
// TODO: Verify if groupMemberId is member of groupId
|
// TODO: Verify if groupMemberId is member of groupId
|
||||||
authorityService.removeAuthority(groupId, groupMemberId);
|
authorityService.removeAuthority(groupId, groupMemberId);
|
||||||
@@ -872,7 +906,7 @@ public class GroupsImpl implements Groups
|
|||||||
throw new InvalidArgumentException("groupId is null or empty");
|
throw new InvalidArgumentException("groupId is null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!groupAuthorityExists(groupId, inferPrefix))
|
if (!PermissionService.ALL_AUTHORITIES.equals(groupId) && !groupAuthorityExists(groupId, inferPrefix))
|
||||||
{
|
{
|
||||||
throw new EntityNotFoundException(groupId);
|
throw new EntityNotFoundException(groupId);
|
||||||
}
|
}
|
||||||
|
@@ -1168,6 +1168,7 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest
|
|||||||
|
|
||||||
getGroupMembers("", paging, null, "", HttpServletResponse.SC_BAD_REQUEST);
|
getGroupMembers("", paging, null, "", HttpServletResponse.SC_BAD_REQUEST);
|
||||||
getGroupMembers("invalidGroupId", paging, null, "", HttpServletResponse.SC_NOT_FOUND);
|
getGroupMembers("invalidGroupId", paging, null, "", HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
getGroupMembers(GROUP_EVERYONE, paging, null, "", HttpServletResponse.SC_METHOD_NOT_ALLOWED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testGetGroupMembersSorting() throws Exception
|
private void testGetGroupMembersSorting() throws Exception
|
||||||
@@ -1346,6 +1347,14 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest
|
|||||||
assertNull(group.getParentIds());
|
assertNull(group.getParentIds());
|
||||||
assertNotNull(group.getZones());
|
assertNotNull(group.getZones());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Support GROUP_EVERYONE
|
||||||
|
{
|
||||||
|
Group group = groupsProxy.getGroup(GROUP_EVERYONE, null, HttpServletResponse.SC_OK);
|
||||||
|
assertNotNull(group);
|
||||||
|
assertNotNull(group.getId());
|
||||||
|
assertNotNull(group.getIsRoot());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -1488,6 +1497,11 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest
|
|||||||
groupsProxy.createGroupMember(groupB.getId(), groupMemberA, HttpServletResponse.SC_CONFLICT);
|
groupsProxy.createGroupMember(groupB.getId(), groupMemberA, HttpServletResponse.SC_CONFLICT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not allowed to modify a GROUP_EVERYONE member.
|
||||||
|
{
|
||||||
|
groupsProxy.createGroupMember(GROUP_EVERYONE, groupMemberA, HttpServletResponse.SC_CONFLICT);
|
||||||
|
}
|
||||||
|
|
||||||
// Person or group with given id does not exists
|
// Person or group with given id does not exists
|
||||||
{
|
{
|
||||||
GroupMember invalidIdGroupMember = new GroupMember();
|
GroupMember invalidIdGroupMember = new GroupMember();
|
||||||
@@ -1622,6 +1636,16 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest
|
|||||||
|
|
||||||
groupsProxy.updateGroup("invalidId", group, null, HttpServletResponse.SC_NOT_FOUND);
|
groupsProxy.updateGroup("invalidId", group, null, HttpServletResponse.SC_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It isn't allowed to update GROUP_EVERYONE.
|
||||||
|
{
|
||||||
|
setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD);
|
||||||
|
|
||||||
|
Group myGroup = new Group();
|
||||||
|
myGroup.setDisplayName("newDisplayName");
|
||||||
|
|
||||||
|
groupsProxy.updateGroup(GROUP_EVERYONE, myGroup, null, HttpServletResponse.SC_CONFLICT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1744,6 +1768,11 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest
|
|||||||
groupsProxy.deleteGroupMembership(groupA.getId(), "invalidGroupMemberId", HttpServletResponse.SC_NOT_FOUND);
|
groupsProxy.deleteGroupMembership(groupA.getId(), "invalidGroupMemberId", HttpServletResponse.SC_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not allowed to delete member of GROUP_EVERYONE.
|
||||||
|
{
|
||||||
|
groupsProxy.deleteGroupMembership(GROUP_EVERYONE, groupMemberA.getId(), HttpServletResponse.SC_CONFLICT);
|
||||||
|
}
|
||||||
|
|
||||||
// Authentication failed
|
// Authentication failed
|
||||||
{
|
{
|
||||||
setRequestContext(networkOne.getId(), GUID.generate(), "password");
|
setRequestContext(networkOne.getId(), GUID.generate(), "password");
|
||||||
|
Reference in New Issue
Block a user