Search in sources :

Example 71 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class ImportExportController method importEntity.

@RequestMapping(value = "/import", method = RequestMethod.POST)
public void importEntity(@RequestParam("file") MultipartFile entityFile, HttpServletRequest request, HttpServletResponse response) throws IOException, XMLStreamException {
    // Get a StAX reader for the source to determine info about the data to import
    final BufferedXMLEventReader bufferedXmlEventReader = createSourceXmlEventReader(entityFile);
    final PortalDataKey portalDataKey = getPortalDataKey(bufferedXmlEventReader);
    final IPerson person = personManager.getPerson(request);
    final EntityIdentifier ei = person.getEntityIdentifier();
    final IAuthorizationPrincipal ap = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    if (!ap.hasPermission("UP_SYSTEM", "IMPORT_ENTITY", portalDataKey.getName().getLocalPart())) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }
    portalDataHandlerService.importData(new StAXSource(bufferedXmlEventReader));
    response.setStatus(HttpServletResponse.SC_OK);
}
Also used : BufferedXMLEventReader(org.apereo.portal.xml.stream.BufferedXMLEventReader) IPerson(org.apereo.portal.security.IPerson) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortalDataKey(org.apereo.portal.io.xml.PortalDataKey) EntityIdentifier(org.apereo.portal.EntityIdentifier) StAXSource(javax.xml.transform.stax.StAXSource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 72 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class PagsRESTController method createPagsGroup.

// Parent group name is expected to be case sensitive.
@RequestMapping(value = "/v4-3/pags/{parentGroupName}.json", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public String createPagsGroup(HttpServletRequest request, HttpServletResponse res, @PathVariable("parentGroupName") String parentGroupName, @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(parentGroupName, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "{ 'error': '" + e.getMessage() + "' }";
    }
    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.getMessage() + "' }";
    }
    // Obtain a real reference to the parent group
    EntityIdentifier[] eids = GroupService.searchForGroups(name, IGroupConstants.SearchMethod.DISCRETE, IPerson.class);
    if (eids.length == 0) {
        res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "{ 'error': 'Parent group does not exist: " + name + "' }";
    }
    IEntityGroup parentGroup = // Names must be unique
    (IEntityGroup) GroupService.getGroupMember(eids[0]);
    IPerson person = personManager.getPerson(request);
    IPersonAttributesGroupDefinition rslt;
    try {
        // A little weird that we need to do both;
        // need some PAGS DAO/Service refactoring
        rslt = pagsService.createPagsDefinition(person, parentGroup, inpt.getName(), inpt.getDescription());
        // little purpose and could be removed.
        for (IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt.getTestGroups()) {
            // NOTE:  The deserializer handles testDef --> testGroupDef
            testGroupDef.setGroup(rslt);
        }
        rslt.setTestGroups(inpt.getTestGroups());
        rslt.setMembers(inpt.getMembers());
        pagsService.updatePagsDefinition(person, rslt);
    } catch (RuntimeAuthorizationException rae) {
        res.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return "{ 'error': 'not authorized' }";
    } catch (IllegalArgumentException iae) {
        res.setStatus(HttpServletResponse.SC_CONFLICT);
        return "{ 'error': '" + iae.getMessage() + "' }";
    } catch (Exception e) {
        e.printStackTrace();
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "{ 'error': '" + e.getMessage() + "' }";
    }
    return respondPagsGroupJson(res, rslt, person, HttpServletResponse.SC_CREATED);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) 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) EntityIdentifier(org.apereo.portal.EntityIdentifier) 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 73 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class PortletsRESTController method getAuthorizationPrincipal.

/*
     * Implementation
     */
private IAuthorizationPrincipal getAuthorizationPrincipal(HttpServletRequest req) {
    IPerson user = personManager.getPerson(req);
    EntityIdentifier ei = user.getEntityIdentifier();
    IAuthorizationPrincipal rslt = AuthorizationServiceFacade.instance().newPrincipal(ei.getKey(), ei.getType());
    return rslt;
}
Also used : IPerson(org.apereo.portal.security.IPerson) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 74 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class EntityGroupImpl method primAddMember.

/**
 * Adds the <code>IGroupMember</code> key to the appropriate member key cache by copying the
 * cache, adding to the copy, and then replacing the original with the copy. At this point,
 * <code>gm</code> does not yet have <code>this</code> in its containing group cache. That cache
 * entry is not added until update(), when changes are committed to the store.
 *
 * @param gm org.apereo.portal.groups.IGroupMember
 */
private void primAddMember(IGroupMember gm) throws GroupsException {
    final EntityIdentifier cacheKey = getUnderlyingEntityIdentifier();
    Element element = childrenCache.get(cacheKey);
    @SuppressWarnings("unchecked") final Set<IGroupMember> set = element != null ? (Set<IGroupMember>) element.getObjectValue() : buildChildrenSet();
    final Set<IGroupMember> children = new HashSet<>(set);
    children.add(gm);
    childrenCache.put(new Element(cacheKey, children));
}
Also used : Element(net.sf.ehcache.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 75 with EntityIdentifier

use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.

the class ReferenceCompositeGroupService method searchForGroups.

/**
 * Find EntityIdentifiers for groups whose name matches the query string according to the
 * specified method, has the provided leaf type and descends from the specified group
 */
@Override
public EntityIdentifier[] searchForGroups(String query, IGroupConstants.SearchMethod method, Class leaftype, IEntityGroup ancestor) throws GroupsException {
    Set allIds = new HashSet();
    for (Iterator services = getComponentServices().values().iterator(); services.hasNext(); ) {
        IIndividualGroupService service = (IIndividualGroupService) services.next();
        EntityIdentifier[] ids = service.searchForGroups(query, method, leaftype, ancestor);
        for (int i = 0; i < ids.length; i++) {
            try {
                CompositeEntityIdentifier cei = new CompositeEntityIdentifier(ids[i].getKey(), ids[i].getType());
                cei.setServiceName(service.getServiceName());
                allIds.add(cei);
            } catch (javax.naming.InvalidNameException ine) {
            }
        }
    }
    return (EntityIdentifier[]) allIds.toArray(new EntityIdentifier[allIds.size()]);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InvalidNameException(javax.naming.InvalidNameException) Iterator(java.util.Iterator) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Aggregations

EntityIdentifier (org.apereo.portal.EntityIdentifier)93 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)31 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)24 IPerson (org.apereo.portal.security.IPerson)17 GroupsException (org.apereo.portal.groups.GroupsException)16 IEntityGroup (org.apereo.portal.groups.IEntityGroup)16 Set (java.util.Set)14 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)13 Iterator (java.util.Iterator)12 IGroupMember (org.apereo.portal.groups.IGroupMember)12 List (java.util.List)6 Element (net.sf.ehcache.Element)6 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)6 HashMap (java.util.HashMap)5 InvalidNameException (javax.naming.InvalidNameException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 GcFindGroups (edu.internet2.middleware.grouperClient.api.GcFindGroups)2