use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class MarketplaceRESTController method getPortletRatings.
/**
* @since 5.0
*/
@RequestMapping(value = "/v5-0/marketplace/{fname}/ratings", method = RequestMethod.GET)
public ModelAndView getPortletRatings(HttpServletRequest request, @PathVariable String fname) {
// TODO: This method should send 404 or 403 in appropriate circumstances
Validate.notNull(fname, "Please supply a portlet to get rating for - should not be null");
IPortletDefinition marketplacePortletDefinition = (IPortletDefinition) marketplaceService.getOrCreateMarketplacePortletDefinitionIfTheFnameExists(fname);
final IPerson user = personManager.getPerson(request);
final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
if (principal.canManage(marketplacePortletDefinition.getPortletDefinitionId().getStringId())) {
Set<IMarketplaceRating> portletRatings = marketplaceRatingDAO.getRatingsByFname(fname);
if (portletRatings != null) {
List<MarketplaceEntryRating> ratingResults = new ArrayList<>();
for (IMarketplaceRating imr : portletRatings) {
ratingResults.add(new MarketplaceEntryRating(imr.getRating(), imr.getReview()));
}
return new ModelAndView("json", "ratings", ratingResults);
}
}
return new ModelAndView("json", "ratings", null);
}
use of org.apereo.portal.security.IPerson 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.IPerson in project uPortal by Jasig.
the class PeopleRESTController method getPerson.
@RequestMapping(value = "/people/{username}.json", method = RequestMethod.GET)
public ModelAndView getPerson(@PathVariable String username, HttpServletRequest request, HttpServletResponse response) {
final IPerson searcher = personManager.getPerson((HttpServletRequest) request);
if (searcher == null) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return null;
}
final IPersonAttributes person = lookupHelper.findPerson(searcher, username);
final ModelAndView mv = new ModelAndView();
mv.addObject("person", person);
mv.setViewName("json");
return mv;
}
use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class PeopleSearchStrategy method search.
@Override
public List<?> search(String query, HttpServletRequest request) {
final List<Object> rslt = new ArrayList<>();
final IPerson user = personManager.getPerson(request);
final Map<String, Object> queryPplAttrMap = new HashMap<>();
for (String attr : directoryQueryAttributes) {
queryPplAttrMap.put(attr, query);
}
final List<IPersonAttributes> people = lookupHelper.searchForPeople(user, queryPplAttrMap);
if (people != null) {
for (IPersonAttributes p : people) {
rslt.add(p.getAttributes());
}
}
return rslt;
}
use of org.apereo.portal.security.IPerson in project uPortal by Jasig.
the class PermissionAssignmentMapController method deletePermission.
/**
* Deletes a specific permission
*
* @param principal
* @param assignment
* @param owner
* @param activity
* @param target
* @param request
* @param response
* @throws Exception
*/
@RequestMapping(value = "/deletePermission", method = RequestMethod.POST)
public void deletePermission(@RequestParam("principal") String principal, @RequestParam("owner") String owner, @RequestParam("activity") String activity, @RequestParam("target") String target, HttpServletRequest request, HttpServletResponse response) throws Exception {
// ensure the current user is authorized to update and view permissions
final IPerson currentUser = personManager.getPerson((HttpServletRequest) request);
if (!permissionAdministrationHelper.canEditPermission(currentUser, target) || !permissionAdministrationHelper.canViewPermission(currentUser, target)) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
JsonEntityBean bean = groupListHelper.getEntityForPrincipal(principal);
if (bean != null) {
IAuthorizationPrincipal p = groupListHelper.getPrincipalForEntity(bean);
IPermission[] directPermissions = permissionStore.select(owner, p.getPrincipalString(), activity, target, null);
this.authorizationService.removePermissions(directPermissions);
} else {
log.warn("Unable to resolve the following principal (will " + "be omitted from the list of assignments): " + principal);
}
response.setStatus(HttpServletResponse.SC_OK);
return;
}
Aggregations