use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.
the class GroupsImpl method getGroups.
public CollectionWithPagingInfo<Group> getGroups(final Parameters parameters) {
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);
// Parse where clause properties.
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 AuthorityType authorityType = AuthorityType.GROUP;
final Set<String> rootAuthorities = getAllRootAuthorities(authorityType);
PagingResults<AuthorityInfo> pagingResult;
try {
pagingResult = getAuthoritiesInfo(authorityType, isRootParam, zoneFilter, rootAuthorities, sortProp, paging);
} catch (UnknownAuthorityException e) {
// Non-existent zone
pagingResult = new EmptyPagingResults<>();
}
// Create response.
final List<AuthorityInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
List<Group> groups = new AbstractList<Group>() {
@Override
public Group get(int index) {
AuthorityInfo authorityInfo = page.get(index);
return getGroup(authorityInfo, includeParam, rootAuthorities);
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.
the class SiteMembershipRequestsImpl method approveSiteMembershipRequest.
@Override
public void approveSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval) {
SiteInfo siteInfo = sites.validateSite(siteId);
if (siteInfo == null) {
throw new EntityNotFoundException(siteId);
}
// Set the site id to the short name (to deal with case sensitivity issues with
// using the siteId from the url)
siteId = siteInfo.getShortName();
// Validate invitation.
Invitation invitation = getSiteInvitation(inviteeId, siteId);
if (invitation == null || !(invitation instanceof ModeratedInvitation)) {
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
}
ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
ResourceType resourceType = moderatedInvitation.getResourceType();
if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility())) {
// note: security, no indication that this has a different visibility
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
}
try {
invitationService.approve(invitation.getInviteId(), "");
} catch (InvitationExceptionForbidden ex) {
throw new PermissionDeniedException();
}
// approval role differs from default one.
if (siteMembershipApproval != null && !(siteMembershipApproval.getRole() == null || siteMembershipApproval.getRole().isEmpty())) {
String role = siteMembershipApproval.getRole();
// Check if role chosen by moderator differs from the invite role.
if (!moderatedInvitation.getRoleName().equals(role)) {
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
// Update invitation with new role.
try {
addSiteMembership(invitation.getInviteeUserName(), siteId, role, currentUserId);
} catch (UnknownAuthorityException e) {
logger.debug("addSiteMember: UnknownAuthorityException " + siteId + " person " + invitation.getInviteId() + " role " + role);
throw new InvalidArgumentException("Unknown role '" + role + "'");
}
}
}
}
use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.
the class SitesImpl method addSiteMember.
public SiteMember addSiteMember(String siteId, SiteMember siteMember) {
String personId = people.validatePerson(siteMember.getPersonId());
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
logger.debug("addSiteMember: site does not exist " + siteId + " person " + personId);
throw new EntityNotFoundException(siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
String role = siteMember.getRole();
if (role == null) {
logger.debug("addSiteMember: Must provide a role " + siteMember);
throw new InvalidArgumentException("Must provide a role");
}
if (siteService.isMember(siteId, personId)) {
logger.debug("addSiteMember: " + personId + " is already a member of site " + siteId);
throw new ConstraintViolatedException(personId + " is already a member of site " + siteId);
}
if (!siteService.canAddMember(siteId, personId, role)) {
logger.debug("addSiteMember: PermissionDeniedException " + siteId + " person " + personId + " role " + role);
throw new PermissionDeniedException();
}
try {
siteService.setMembership(siteId, personId, role);
} catch (UnknownAuthorityException e) {
logger.debug("addSiteMember: UnknownAuthorityException " + siteId + " person " + personId + " role " + role);
throw new InvalidArgumentException("Unknown role '" + role + "'");
}
return siteMember;
}
use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.
the class SitesImpl method updateSiteMember.
public SiteMember updateSiteMember(String siteId, SiteMember siteMember) {
String siteMemberId = siteMember.getPersonId();
if (siteMemberId == null) {
throw new InvalidArgumentException("Member id is null");
}
siteMemberId = people.validatePerson(siteMemberId);
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
siteId = siteInfo.getShortName();
String siteRole = siteMember.getRole();
if (siteRole == null) {
throw new InvalidArgumentException("Must provide a role");
}
/* MNT-10551 : fix */
if (!siteService.isMember(siteId, siteMember.getPersonId())) {
throw new InvalidArgumentException("User is not a member of the site");
}
try {
siteService.setMembership(siteId, siteMember.getPersonId(), siteRole);
} catch (UnknownAuthorityException e) {
throw new InvalidArgumentException("Unknown role '" + siteRole + "'");
}
return siteMember;
}
use of org.alfresco.repo.security.authority.UnknownAuthorityException in project alfresco-remote-api by Alfresco.
the class GroupsFilter method getGroups.
public CollectionWithPagingInfo<Group> getGroups(final Parameters parameters) {
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);
// Parse where clause properties.
GroupsFilter groupsFilters = getGroupsFilterFromQueryParameters(parameters.getQuery());
final AuthorityType authorityType = AuthorityType.GROUP;
final Set<String> rootAuthorities = getAllRootAuthorities(authorityType);
PagingResults<AuthorityInfo> pagingResult;
try {
pagingResult = getAuthoritiesInfo(authorityType, groupsFilters, rootAuthorities, sortProp, paging);
} catch (UnknownAuthorityException e) {
// Non-existent zone
pagingResult = new EmptyPagingResults<>();
}
List<Group> groups = createGroupsResponse(pagingResult.getPage(), parameters.getInclude(), rootAuthorities);
int totalItems = pagingResult.getTotalResultCount().getFirst();
return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Aggregations