use of org.alfresco.repo.security.authority.AuthorityInfo in project alfresco-remote-api by Alfresco.
the class GroupsImpl method getGroupsByPersonId.
@Override
public CollectionWithPagingInfo<Group> getGroupsByPersonId(String requestedPersonId, Parameters parameters) {
// Canonicalize the person ID, performing -me- alias substitution.
final String personId = people.validatePerson(requestedPersonId);
// Non-admins can only access their own data
// TODO: this is also in PeopleImpl.update(personId,personInfo) - refactor?
boolean isAdmin = authorityService.hasAdminAuthority();
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
if (!isAdmin && !currentUserId.equalsIgnoreCase(personId)) {
// The user is not an admin user and is not attempting to retrieve *their own* details.
throw new PermissionDeniedException();
}
Query q = parameters.getQuery();
Boolean isRootParam = null;
String zoneFilter = null;
if (q != null) {
GroupsQueryWalker propertyWalker = new GroupsQueryWalker();
QueryHelper.walk(q, propertyWalker);
isRootParam = propertyWalker.getIsRoot();
List<String> zonesParam = propertyWalker.getZones();
if (zonesParam != null) {
validateZonesParam(zonesParam);
zoneFilter = zonesParam.get(0);
}
}
final List<String> includeParam = parameters.getInclude();
Paging paging = parameters.getPaging();
// Retrieve sort column. This is limited for now to sort column due to
// v0 api implementation. Should be improved in the future.
Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
// Get all the authorities for a user, including but not limited to, groups.
Set<String> userAuthorities = runAsSystem(() -> authorityService.getAuthoritiesForUser(personId));
final Set<String> rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP);
// Filter, transform and sort the list of user authorities into
// a suitable list of AuthorityInfo objects.
final String finalZoneFilter = zoneFilter;
final Boolean finalIsRootParam = isRootParam;
List<AuthorityInfo> groupAuthorities = userAuthorities.stream().filter(a -> a.startsWith(AuthorityType.GROUP.getPrefixString())).filter(a -> isRootPredicate(finalIsRootParam, rootAuthorities, a)).filter(a -> zonePredicate(a, finalZoneFilter)).map(this::getAuthorityInfo).sorted(new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond())).collect(Collectors.toList());
PagingResults<AuthorityInfo> pagingResult = Util.wrapPagingResults(paging, groupAuthorities);
// Create response.
final List<AuthorityInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
// Transform the page of results into Group objects
List<Group> groups = page.stream().map(authority -> getGroup(authority, includeParam, rootAuthorities)).collect(Collectors.toList());
return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
use of org.alfresco.repo.security.authority.AuthorityInfo in project alfresco-remote-api by Alfresco.
the class GroupsImpl method getGroupMembers.
public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters) {
validateGroupId(groupId, false);
// Not allowed to list all members.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new UnsupportedResourceOperationException();
}
Paging paging = parameters.getPaging();
// Retrieve sort column. This is limited for now to sort column due to
// v0 api implementation. Should be improved in the future.
Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
AuthorityType authorityType = null;
// Parse where clause properties.
Query q = parameters.getQuery();
if (q != null) {
MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_GROUP_MEMBERS_QUERY_PROPERTIES, null);
QueryHelper.walk(q, propertyWalker);
String memberTypeStr = propertyWalker.getProperty(PARAM_MEMBER_TYPE, WhereClauseParser.EQUALS, String.class);
authorityType = getAuthorityType(memberTypeStr);
}
PagingResults<AuthorityInfo> pagingResult = getAuthoritiesInfo(authorityType, groupId, sortProp, paging);
// Create response.
final List<AuthorityInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
List<GroupMember> groupMembers = new AbstractList<GroupMember>() {
@Override
public GroupMember get(int index) {
AuthorityInfo authorityInfo = page.get(index);
return getGroupMember(authorityInfo);
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, groupMembers, pagingResult.hasMoreItems(), totalItems);
}
use of org.alfresco.repo.security.authority.AuthorityInfo in project alfresco-remote-api by Alfresco.
the class GroupsFilter method getAuthoritiesInfo.
private PagingResults<AuthorityInfo> getAuthoritiesInfo(AuthorityType authorityType, GroupsFilter groupsFilter, Set<String> rootAuthorities, Pair<String, Boolean> sortProp, Paging paging) {
Boolean isRootParam = groupsFilter.getIsRoot();
String zoneFilter = groupsFilter.getZoneFilter();
String displayNameFilter = groupsFilter.getDisplayNameFilter();
PagingResults<AuthorityInfo> pagingResult;
if (isRootParam != null || displayNameFilter != null) {
List<AuthorityInfo> groupList;
if (isRootParam != null && isRootParam) {
// Limit the post processing work by using the already loaded
// list of root authorities.
List<AuthorityInfo> authorities = rootAuthorities.stream().map(this::getAuthorityInfo).filter(auth -> zonePredicate(auth.getAuthorityName(), zoneFilter)).filter(auth -> displayNamePredicate(auth.getAuthorityDisplayName(), displayNameFilter)).collect(Collectors.toList());
groupList = new ArrayList<>(rootAuthorities.size());
groupList.addAll(authorities);
// Post process sorting - this should be moved to service
// layer. It is done here because sorting is not supported at
// service layer.
AuthorityInfoComparator authorityComparator = new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond());
Collections.sort(groupList, authorityComparator);
} else {
PagingRequest pagingNoMaxItems = new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE);
// Get authorities using canned query but without using
// the requested paginating now because we need to filter out
// the root authorities.
PagingResults<AuthorityInfo> nonPagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingNoMaxItems);
// Post process filtering - this should be moved to service
// layer. It is done here because filtering by "isRoot" is not
// supported at service layer.
groupList = nonPagingResult.getPage();
if (groupList != null) {
groupList = groupList.stream().filter(auth -> isRootPredicate(isRootParam, rootAuthorities, auth.getAuthorityName())).filter(auth -> displayNamePredicate(auth.getAuthorityDisplayName(), displayNameFilter)).collect(Collectors.toList());
}
}
// Post process paging - this should be moved to service layer.
pagingResult = Util.wrapPagingResults(paging, groupList);
} else {
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// Get authorities using canned query.
pagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingRequest);
}
return pagingResult;
}
use of org.alfresco.repo.security.authority.AuthorityInfo in project alfresco-remote-api by Alfresco.
the class GroupsFilter method getGroupsByPersonId.
@Override
public CollectionWithPagingInfo<Group> getGroupsByPersonId(String requestedPersonId, Parameters parameters) {
// Canonicalize the person ID, performing -me- alias substitution.
final String personId = people.validatePerson(requestedPersonId);
// Non-admins can only access their own data
// TODO: this is also in PeopleImpl.update(personId,personInfo) - refactor?
boolean isAdmin = authorityService.hasAdminAuthority();
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
if (!isAdmin && !currentUserId.equalsIgnoreCase(personId)) {
// The user is not an admin user and is not attempting to retrieve *their own* details.
throw new PermissionDeniedException();
}
Query q = parameters.getQuery();
Boolean isRootParam = null;
String zoneFilter = null;
if (q != null) {
GroupsQueryWalker propertyWalker = new GroupsQueryWalker();
QueryHelper.walk(q, propertyWalker);
isRootParam = propertyWalker.getIsRoot();
List<String> zonesParam = propertyWalker.getZones();
if (zonesParam != null) {
validateListParam(zonesParam, ZONE, MAX_ZONES);
zoneFilter = zonesParam.get(0);
}
}
final List<String> includeParam = parameters.getInclude();
Paging paging = parameters.getPaging();
// Retrieve sort column. This is limited for now to sort column due to
// v0 api implementation. Should be improved in the future.
Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
// Get all the authorities for a user, including but not limited to, groups.
Set<String> userAuthorities = runAsSystem(() -> authorityService.getAuthoritiesForUser(personId));
final Set<String> rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP);
// Filter, transform and sort the list of user authorities into
// a suitable list of AuthorityInfo objects.
final String finalZoneFilter = zoneFilter;
final Boolean finalIsRootParam = isRootParam;
List<AuthorityInfo> groupAuthorities = userAuthorities.stream().filter(a -> a.startsWith(AuthorityType.GROUP.getPrefixString())).filter(a -> isRootPredicate(finalIsRootParam, rootAuthorities, a)).filter(a -> zonePredicate(a, finalZoneFilter)).map(this::getAuthorityInfo).sorted(new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond())).collect(Collectors.toList());
PagingResults<AuthorityInfo> pagingResult = Util.wrapPagingResults(paging, groupAuthorities);
// Create response.
final List<AuthorityInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
// Transform the page of results into Group objects
List<Group> groups = page.stream().map(authority -> getGroup(authority, includeParam, rootAuthorities)).collect(Collectors.toList());
return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
use of org.alfresco.repo.security.authority.AuthorityInfo in project alfresco-remote-api by Alfresco.
the class GroupsFilter method getGroupMembers.
public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters) {
validateGroupId(groupId, false);
// Not allowed to list all members.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new UnsupportedResourceOperationException();
}
Paging paging = parameters.getPaging();
// Retrieve sort column. This is limited for now to sort column due to
// v0 api implementation. Should be improved in the future.
Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
AuthorityType authorityType = null;
// Parse where clause properties.
Query q = parameters.getQuery();
if (q != null) {
MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_GROUP_MEMBERS_QUERY_PROPERTIES, null);
QueryHelper.walk(q, propertyWalker);
String memberTypeStr = propertyWalker.getProperty(PARAM_MEMBER_TYPE, WhereClauseParser.EQUALS, String.class);
authorityType = getAuthorityType(memberTypeStr);
}
PagingResults<AuthorityInfo> pagingResult = getAuthoritiesInfo(authorityType, groupId, sortProp, paging);
// Create response.
final List<AuthorityInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
List<GroupMember> groupMembers = new AbstractList<GroupMember>() {
@Override
public GroupMember get(int index) {
AuthorityInfo authorityInfo = page.get(index);
return getGroupMember(authorityInfo);
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, groupMembers, pagingResult.hasMoreItems(), totalItems);
}
Aggregations