Search in sources :

Example 41 with EntityIdentifier

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;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 42 with EntityIdentifier

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);
}
Also used : Element(net.sf.ehcache.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier) Test(org.junit.Test)

Example 43 with EntityIdentifier

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();
}
Also used : EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 44 with EntityIdentifier

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;
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 45 with EntityIdentifier

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;
}
Also used : AuthorizationService(org.apereo.portal.services.AuthorizationService) Element(org.w3c.dom.Element) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) EntityIdentifier(org.apereo.portal.EntityIdentifier) Document(org.w3c.dom.Document)

Aggregations

EntityIdentifier (org.apereo.portal.EntityIdentifier)79 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)31 HashSet (java.util.HashSet)20 IPerson (org.apereo.portal.security.IPerson)17 ArrayList (java.util.ArrayList)15 IEntityGroup (org.apereo.portal.groups.IEntityGroup)13 IGroupMember (org.apereo.portal.groups.IGroupMember)12 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)12 Set (java.util.Set)9 GroupsException (org.apereo.portal.groups.GroupsException)9 Iterator (java.util.Iterator)7 Element (net.sf.ehcache.Element)6 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)6 HashMap (java.util.HashMap)4 List (java.util.List)4 LinkedHashSet (java.util.LinkedHashSet)3 LinkedList (java.util.LinkedList)2 Locale (java.util.Locale)2 Map (java.util.Map)2 SortedSet (java.util.SortedSet)2