use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.
the class GroupsImpl method createGroupMember.
@Override
public GroupMember createGroupMember(String groupId, GroupMember groupMember) {
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);
AuthorityType authorityType = getAuthorityType(groupMember.getMemberType());
if (!authorityService.authorityExists(groupMember.getId())) {
throw new EntityNotFoundException(groupMember.getId());
}
AuthorityType existingAuthorityType = AuthorityType.getAuthorityType(groupMember.getId());
if (existingAuthorityType != authorityType) {
throw new IllegalArgumentException("Incorrect group member type, " + (AuthorityType.USER.equals(existingAuthorityType) ? Groups.PARAM_MEMBER_TYPE_PERSON : existingAuthorityType) + " exists with the given id");
}
authorityService.addAuthority(groupId, groupMember.getId());
String authority = authorityService.getName(authorityType, groupMember.getId());
return getGroupMember(authority);
}
use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.
the class GroupsImpl method deleteGroupMembership.
public void deleteGroupMembership(String groupId, String groupMemberId) {
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);
// Verify if groupMemberId is member of groupId
AuthorityType authorityType = AuthorityType.getAuthorityType(groupMemberId);
Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, groupMemberId, true);
if (!parents.contains(groupId)) {
throw new NotFoundException(groupMemberId + " is not member of " + groupId);
}
authorityService.removeAuthority(groupId, groupMemberId);
}
use of org.alfresco.service.cmr.security.AuthorityType 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.service.cmr.security.AuthorityType in project acs-community-packaging by Alfresco.
the class EmailSpaceUsersDialog method finishImpl.
/**
* @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
// get the space ref this mail applies to
NodeRef spaceRef = getSpace().getNodeRef();
// calculate the 'from' email address
User user = Application.getCurrentUser(context);
String from = (String) this.getNodeService().getProperty(user.getPerson(), ContentModel.PROP_EMAIL);
if (from == null || from.length() == 0) {
// if the user does not have an email address get the default one from the config service
from = Application.getClientConfig(context).getFromEmailAddress();
}
Set<String> mailedAuthorities = new HashSet<String>(usersGroups.size());
// walk the list of users/groups to notify - handle duplicates along the way
for (Map node : usersGroups) {
String authority = (String) node.get(PROP_USERNAME);
boolean selected = (Boolean) node.get(PROP_SELECTED);
// if User, email then, else if Group get all members and email them
AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType.equals(AuthorityType.USER)) {
if (selected == true && this.getPersonService().personExists(authority)) {
if (mailedAuthorities.contains(authority) == false) {
this.mailHelper.notifyUser(this.getPersonService().getPerson(authority), spaceRef, from, (String) node.get(PROP_ROLES));
mailedAuthorities.add(authority);
}
}
} else if (authType.equals(AuthorityType.GROUP)) {
// is the group expanded? if so we'll deal with the child authorities instead
boolean expanded = (Boolean) node.get(PROP_EXPANDED);
if (expanded == false && selected == true) {
// notify all members of the group
Set<String> users = this.getAuthorityService().getContainedAuthorities(AuthorityType.USER, authority, false);
for (String userAuth : users) {
if (this.getPersonService().personExists(userAuth) == true) {
if (mailedAuthorities.contains(userAuth) == false) {
this.mailHelper.notifyUser(this.getPersonService().getPerson(userAuth), spaceRef, from, (String) node.get(PROP_ROLES));
mailedAuthorities.add(userAuth);
}
}
}
}
}
}
return outcome;
}
use of org.alfresco.service.cmr.security.AuthorityType in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard method addAuthorityWithRole.
/**
* Add an authority with the specified role to the list managed by this wizard.
*
* @param authority Authority to add (cannot be null)
* @param role Role for the authorities (cannot be null)
*/
public void addAuthorityWithRole(String authority, String role) {
// only add if authority not already present in the list with same role
boolean foundExisting = false;
for (int n = 0; n < this.userGroupRoles.size(); n++) {
UserGroupRole wrapper = this.userGroupRoles.get(n);
if (authority.equals(wrapper.getAuthority()) && (!this.allowDuplicateAuthorities || role.equals(wrapper.getRole()))) {
foundExisting = true;
break;
}
}
if (foundExisting == false) {
StringBuilder label = new StringBuilder(64);
// build a display label showing the user and their role for the space
AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType == AuthorityType.GUEST || authType == AuthorityType.USER) {
if (authType == AuthorityType.GUEST || getPersonService().personExists(authority) == true) {
// found a User authority
label.append(buildLabelForUserAuthorityRole(authority, role));
}
} else {
// found a group authority
label.append(buildLabelForGroupAuthorityRole(authority, role));
}
this.userGroupRoles.add(new UserGroupRole(authority, role, label.toString()));
}
}
Aggregations