Search in sources :

Example 36 with IPerson

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);
}
Also used : IPerson(org.apereo.portal.security.IPerson) IMarketplaceRating(org.apereo.portal.portlet.marketplace.IMarketplaceRating) MarketplaceEntryRating(org.apereo.portal.rest.layout.MarketplaceEntryRating) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with IPerson

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);
}
Also used : IPerson(org.apereo.portal.security.IPerson) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition) IPersonAttributesGroupTestGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PersonAttributesGroupDefinitionImpl(org.apereo.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 38 with IPerson

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;
}
Also used : IPerson(org.apereo.portal.security.IPerson) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with IPerson

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;
}
Also used : IPerson(org.apereo.portal.security.IPerson) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 40 with IPerson

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;
}
Also used : IPerson(org.apereo.portal.security.IPerson) JsonEntityBean(org.apereo.portal.layout.dlm.remoting.JsonEntityBean) IPermission(org.apereo.portal.security.IPermission) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IPerson (org.apereo.portal.security.IPerson)177 Test (org.junit.Test)46 PersonImpl (org.apereo.portal.security.provider.PersonImpl)41 ModelAndView (org.springframework.web.servlet.ModelAndView)41 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 HttpServletRequest (javax.servlet.http.HttpServletRequest)26 IUserInstance (org.apereo.portal.user.IUserInstance)26 ArrayList (java.util.ArrayList)22 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)22 HashMap (java.util.HashMap)20 IPersonAttributes (org.apereo.services.persondir.IPersonAttributes)16 EntityIdentifier (org.apereo.portal.EntityIdentifier)15 HttpSession (javax.servlet.http.HttpSession)14 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)14 PortalException (org.apereo.portal.PortalException)11 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 List (java.util.List)10 IUserProfile (org.apereo.portal.IUserProfile)9 ISecurityContext (org.apereo.portal.security.ISecurityContext)9