use of org.apereo.portal.security.RuntimeAuthorizationException in project uPortal by Jasig.
the class GroupAdministrationHelper method updateGroupMembers.
/**
* Update the members of an existing group in the group store.
*
* @param groupForm Form representing the new group configuration
* @param updater Updating user
*/
public void updateGroupMembers(GroupForm groupForm, IPerson updater) {
if (!canEditGroup(updater, groupForm.getKey())) {
throw new RuntimeAuthorizationException(updater, IPermission.EDIT_GROUP_ACTIVITY, groupForm.getKey());
}
if (log.isDebugEnabled()) {
log.debug("Updating group members for group form [" + groupForm.toString() + "]");
}
// find the current version of this group entity
IEntityGroup group = GroupService.findGroup(groupForm.getKey());
// clear the current group membership list
for (IGroupMember child : group.getChildren()) {
group.removeChild(child);
}
// to the group
for (JsonEntityBean child : groupForm.getMembers()) {
EntityEnum type = EntityEnum.getEntityEnum(child.getEntityTypeAsString());
if (type.isGroup()) {
IEntityGroup member = GroupService.findGroup(child.getId());
group.addChild(member);
} else {
IGroupMember member = GroupService.getGroupMember(child.getId(), type.getClazz());
group.addChild(member);
}
}
// save the group, updating both its basic information and group
// membership
group.updateMembers();
}
use of org.apereo.portal.security.RuntimeAuthorizationException in project uPortal by Jasig.
the class PagsRESTController method updatePagsGroup.
@RequestMapping(value = "/v4-3/pags/{pagsGroupName}.json", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT)
@ResponseBody
public String updatePagsGroup(HttpServletRequest req, HttpServletResponse res, @PathVariable("pagsGroupName") String pagsGroupName, @RequestBody String json) {
res.setContentType(MediaType.APPLICATION_JSON_VALUE);
/*
* This step is necessary; the incoming URLs will sometimes have '+'
* characters for spaces, and the @PathVariable magic doesn't convert them.
*/
String name;
try {
name = URLDecoder.decode(pagsGroupName, "UTF-8");
} catch (UnsupportedEncodingException e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return "{ 'error': '" + e.toString() + "' }";
}
IPersonAttributesGroupDefinition inpt;
try {
inpt = objectMapper.readValue(json, PersonAttributesGroupDefinitionImpl.class);
} catch (Exception e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
// should be escaped
return "{ 'error': '" + e.toString() + "' }";
}
if (inpt == null) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "{ 'error': 'Not found' }";
}
if (!name.equals(inpt.getName())) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return "{ 'error': 'Group name in URL parameter must match name in JSON payload' }";
}
IPerson person = personManager.getPerson(req);
IPersonAttributesGroupDefinition rslt;
try {
IPersonAttributesGroupDefinition currentDef = pagsService.getPagsDefinitionByName(person, name);
if (currentDef == null) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "{ 'error': 'Not found' }";
}
/*
* Copy over the information being passed in to the JPA-managed
* instance; the following do not support updates (currently):
* - Name
* - Members
*/
currentDef.setDescription(inpt.getDescription());
// little purpose and could be removed.
for (IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt.getTestGroups()) {
// NOTE: The deserializer handles testDef --> testGroupDef
testGroupDef.setGroup(currentDef);
}
currentDef.setTestGroups(inpt.getTestGroups());
rslt = pagsService.updatePagsDefinition(person, currentDef);
} catch (IllegalArgumentException iae) {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
// should be escaped
return "{ 'error': '" + iae.getMessage() + "' }";
} catch (RuntimeAuthorizationException rae) {
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
return "{ 'error': 'not authorized' }";
} catch (Exception e) {
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return "{ 'error': '" + e.toString() + "' }";
}
return respondPagsGroupJson(res, rslt, person, HttpServletResponse.SC_ACCEPTED);
}
use of org.apereo.portal.security.RuntimeAuthorizationException in project uPortal by Jasig.
the class PagsService method createPagsDefinition.
/**
* Verifies permissions and that the group doesn't already exist (case insensitive)
*/
public IPersonAttributesGroupDefinition createPagsDefinition(IPerson person, IEntityGroup parent, String groupName, String description) {
// What's the target of the upcoming permissions check?
String target = parent != null ? parent.getEntityIdentifier().getKey() : IPermission.ALL_GROUPS_TARGET;
// Verify permission
if (!hasPermission(person, IPermission.CREATE_GROUP_ACTIVITY, target)) {
throw new RuntimeAuthorizationException(person, IPermission.CREATE_GROUP_ACTIVITY, target);
}
// VALIDATION STEP: The group name & description are allowable
if (StringUtils.isBlank(groupName)) {
throw new IllegalArgumentException("Specified groupName is blank: " + groupName);
}
if (!GROUP_NAME_VALIDATOR_PATTERN.matcher(groupName).matches()) {
throw new IllegalArgumentException("Specified groupName is too long, too short, or contains invalid characters: " + groupName);
}
if (!StringUtils.isBlank(description)) {
// Blank description is allowable
if (!GROUP_DESC_VALIDATOR_PATTERN.matcher(description).matches()) {
throw new IllegalArgumentException("Specified description is too long or contains invalid characters: " + description);
}
}
// VALIDATION STEP: We don't have a group by that name already
EntityIdentifier[] people = GroupService.searchForGroups(groupName, IGroupConstants.SearchMethod.DISCRETE_CI, IPerson.class);
EntityIdentifier[] portlets = GroupService.searchForGroups(groupName, IGroupConstants.SearchMethod.DISCRETE_CI, IPortletDefinition.class);
if (people.length != 0 || portlets.length != 0) {
throw new IllegalArgumentException("Specified groupName already in use: " + groupName);
}
IPersonAttributesGroupDefinition rslt = pagsGroupDefDao.createPersonAttributesGroupDefinition(groupName, description);
if (parent != null) {
// Should refactor this switch to instead choose a service and invoke a method on it
switch(parent.getServiceName().toString()) {
case SERVICE_NAME_LOCAL:
IEntityGroup member = GroupService.findGroup(rslt.getCompositeEntityIdentifierForGroup().getKey());
if (member == null) {
String msg = "The specified group was created, but is not present in the store: " + rslt.getName();
throw new RuntimeException(msg);
}
parent.addChild(member);
parent.updateMembers();
break;
case SERVICE_NAME_PAGS:
IPersonAttributesGroupDefinition parentDef = getPagsGroupDefByName(parent.getName());
Set<IPersonAttributesGroupDefinition> members = new HashSet<>(parentDef.getMembers());
members.add(rslt);
parentDef.setMembers(members);
pagsGroupDefDao.updatePersonAttributesGroupDefinition(parentDef);
break;
default:
String msg = "The specified group service does not support adding members: " + parent.getServiceName();
throw new UnsupportedOperationException(msg);
}
}
return rslt;
}
use of org.apereo.portal.security.RuntimeAuthorizationException in project uPortal by Jasig.
the class GroupAdministrationHelper method deleteGroup.
/**
* Delete a group from the group store
*
* @param key key of the group to be deleted
* @param user performing the delete operation
*/
public void deleteGroup(String key, IPerson deleter) {
if (!canDeleteGroup(deleter, key)) {
throw new RuntimeAuthorizationException(deleter, IPermission.DELETE_GROUP_ACTIVITY, key);
}
log.info("Deleting group with key " + key);
// find the current version of this group entity
IEntityGroup group = GroupService.findGroup(key);
// groups
for (IEntityGroup parent : group.getParentGroups()) {
parent.removeChild(group);
parent.updateMembers();
}
// delete the group
group.delete();
}
use of org.apereo.portal.security.RuntimeAuthorizationException in project uPortal by Jasig.
the class GroupAdministrationHelper method updateGroupDetails.
/**
* Update the title and description of an existing group in the group store.
*
* @param groupForm Form representing the new group configuration
* @param updater Updating user
*/
public void updateGroupDetails(GroupForm groupForm, IPerson updater) {
if (!canEditGroup(updater, groupForm.getKey())) {
throw new RuntimeAuthorizationException(updater, IPermission.EDIT_GROUP_ACTIVITY, groupForm.getKey());
}
if (log.isDebugEnabled()) {
log.debug("Updating group for group form [" + groupForm.toString() + "]");
}
// find the current version of this group entity
IEntityGroup group = GroupService.findGroup(groupForm.getKey());
group.setName(groupForm.getName());
group.setDescription(groupForm.getDescription());
// save the group, updating both its basic information and group
// membership
group.update();
}
Aggregations