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);
}
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);
}
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;
}
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));
}
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()]);
}
Aggregations