use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class PagsService method createPagsDefinition.
/** Verifies permissions and that the group doesn't already exist */
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.IS, IPerson.class);
EntityIdentifier[] portlets = GroupService.searchForGroups(groupName, IGroupConstants.IS, 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.EntityIdentifier in project uPortal by Jasig.
the class EhcacheMemberIdAttributeExtractorTest method testAttributeFor.
@Test
public void testAttributeFor() {
final EntityIdentifier parentEntityIdentifier = new EntityIdentifier("mock.group", IPerson.class);
final String memberId = "mock.user";
final EntityIdentifier childEntityIdentifier = new EntityIdentifier(memberId, IPerson.class);
final MembershipCacheKey membershipCacheKey = new MembershipCacheKey(parentEntityIdentifier, childEntityIdentifier);
final Element element = new Element(membershipCacheKey, new Object());
final EhcacheMemberIdAttributeExtractor attributeExtractor = new EhcacheMemberIdAttributeExtractor();
Assert.assertEquals(attributeExtractor.attributeFor(element, null), memberId);
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class EhcacheMemberIdAttributeExtractor method attributeFor.
@Override
public Object attributeFor(Element element, String attributeName) throws AttributeExtractorException {
final MembershipCacheKey membershipCacheKey = (MembershipCacheKey) element.getObjectKey();
final EntityIdentifier ei = membershipCacheKey.getMemberId();
return ei.getKey();
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class PortletDefinitionImporterExporter method toGroupMembers.
/**
* Convert a list of group names to a list of groups.
*
* @param groupNames the list of group names
* @return the list of groups.
*/
private Set<IGroupMember> toGroupMembers(List<String> groupNames, String fname) {
final Set<IGroupMember> groups = new HashSet<>();
for (String groupName : groupNames) {
EntityIdentifier[] gs = GroupService.searchForGroups(groupName, IGroupConstants.IS, IPerson.class);
IGroupMember group;
if (gs != null && gs.length > 0) {
group = GroupService.findGroup(gs[0].getKey());
} else {
// An actual group key might be specified, so try looking up group directly
group = GroupService.findGroup(groupName);
}
if (group == null) {
throw new IllegalArgumentException("No group '" + groupName + "' found when importing portlet: " + fname);
}
groups.add(group);
}
return groups;
}
use of org.apereo.portal.EntityIdentifier in project uPortal by Jasig.
the class ILFBuilder method constructILF.
public static Document constructILF(Document PLF, List<Document> sequence, IPerson person) {
if (LOG.isDebugEnabled()) {
LOG.debug("Constructing ILF for IPerson='" + person + "'");
}
// first construct the destination document and root element. The root
// element should be a complete copy of the PLF's root including its
// node identifier in the new document. This requires the use of
// the implementation class to set the identifier for that node
// in the document.
Document result = DocumentFactory.getThreadDocument();
Element plfLayout = PLF.getDocumentElement();
Element ilfLayout = (Element) result.importNode(plfLayout, false);
result.appendChild(ilfLayout);
Element plfRoot = (Element) plfLayout.getFirstChild();
Element ilfRoot = (Element) result.importNode(plfRoot, false);
ilfLayout.appendChild(ilfRoot);
if (ilfRoot.getAttribute(Constants.ATT_ID) != null)
ilfRoot.setIdAttribute(Constants.ATT_ID, true);
// build the auth principal for determining if pushed channels can be
// used by this user
EntityIdentifier ei = person.getEntityIdentifier();
AuthorizationService authS = AuthorizationService.instance();
IAuthorizationPrincipal ap = authS.newPrincipal(ei.getKey(), ei.getType());
for (final Document document : sequence) {
mergeFragment(document, result, ap);
}
return result;
}
Aggregations