Search in sources :

Example 36 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.

the class GrouperEntityGroupStore method findMemberGroupKeys.

/* (non-Javadoc)
     * @see org.apereo.portal.groups.IEntityGroupStore#findMemberGroupKeys(org.apereo.portal.groups.IEntityGroup)
     */
@SuppressWarnings("unchecked")
public String[] findMemberGroupKeys(IEntityGroup group) throws GroupsException {
    // first the get an iterator for the member groups
    final Iterator<IEntityGroup> it = findMemberGroups(group);
    // construct a list of group keys from this iterator
    List<String> keys = new ArrayList<String>();
    while (it.hasNext()) {
        IEntityGroup eg = it.next();
        keys.add(eg.getKey());
    }
    // return an iterator over the assembled list
    return keys.toArray(new String[keys.size()]);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) ArrayList(java.util.ArrayList)

Example 37 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.

the class GrouperEntityGroupStore method findMemberGroups.

@SuppressWarnings("unchecked")
public Iterator findMemberGroups(IEntityGroup group) throws GroupsException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Searching for group-type members of group with key: " + group.getKey());
    }
    try {
        if (!validKey(group.getLocalKey())) {
            return Collections.<IEntityGroup>emptyList().iterator();
        }
        GcGetMembers gcGetMembers = new GcGetMembers();
        gcGetMembers.addGroupName(group.getLocalKey());
        gcGetMembers.assignIncludeSubjectDetail(true);
        gcGetMembers.addSourceId("g:gsa");
        WsGetMembersResults results = gcGetMembers.execute();
        if (results == null || results.getResults() == null || results.getResults().length == 0 || results.getResults()[0].getWsSubjects() == null) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("No group-type members found for group with key " + group.getKey());
            }
            return Collections.<IEntityGroup>emptyList().iterator();
        }
        final List<IEntityGroup> members = new ArrayList<IEntityGroup>();
        WsSubject[] subjects = results.getResults()[0].getWsSubjects();
        for (WsSubject wsSubject : subjects) {
            if (validKey(wsSubject.getName())) {
                WsGroup wsGroup = findGroupFromKey(wsSubject.getName());
                if (wsGroup != null) {
                    IEntityGroup member = createUportalGroupFromGrouperGroup(wsGroup);
                    members.add(member);
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("found IEntityGroup member: " + member);
                    }
                }
            }
        }
        return members.iterator();
    } catch (Exception e) {
        LOGGER.warn("Exception while attempting to retrieve " + "member groups of group with key " + group.getKey() + " from Grouper web services: " + e.getMessage());
        return Collections.<IGroupMember>emptyList().iterator();
    }
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IGroupMember(org.apereo.portal.groups.IGroupMember) ArrayList(java.util.ArrayList) WsGroup(edu.internet2.middleware.grouperClient.ws.beans.WsGroup) WsSubject(edu.internet2.middleware.grouperClient.ws.beans.WsSubject) GcGetMembers(edu.internet2.middleware.grouperClient.api.GcGetMembers) WsGetMembersResults(edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults) GroupsException(org.apereo.portal.groups.GroupsException)

Example 38 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.

the class PortletCategoryRegistryImpl method getPortletCategory.

/* (non-Javadoc)
     * @see org.apereo.portal.portlet.registry.IPortletCategoryRegistry#getPortletCategory(java.lang.String)
     */
@Override
public PortletCategory getPortletCategory(String portletCategoryId) {
    IEntityGroup categoryGroup = GroupService.findGroup(portletCategoryId);
    if (categoryGroup == null) {
        return null;
    }
    PortletCategory category = new PortletCategory(portletCategoryId);
    category.setName(categoryGroup.getName());
    category.setDescription(categoryGroup.getDescription());
    category.setCreatorId(categoryGroup.getCreatorID());
    return category;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) PortletCategory(org.apereo.portal.portlet.om.PortletCategory)

Example 39 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.

the class SimpleAttributesMapper method mapFromAttributes.

/*
     * Public API.
     */
public Object mapFromAttributes(Attributes attr) {
    // Assertions.
    if (keyAttributeName == null) {
        String msg = "The property 'keyAttributeName' must be set.";
        throw new IllegalStateException(msg);
    }
    if (groupNameAttributeName == null) {
        String msg = "The property 'groupNameAttributeName' must be set.";
        throw new IllegalStateException(msg);
    }
    if (membershipAttributeName == null) {
        String msg = "The property 'membershipAttributeName' must be set.";
        throw new IllegalStateException(msg);
    }
    if (log.isDebugEnabled()) {
        String msg = "SimpleAttributesMapper.mapFromAttributes() :: settings:  keyAttributeName='" + keyAttributeName + "', groupNameAttributeName='" + groupNameAttributeName + "', groupNameAttributeName='" + groupNameAttributeName + "'";
        log.debug(msg);
    }
    LdapRecord rslt;
    try {
        String key = (String) attr.get(keyAttributeName).get();
        String groupName = (String) attr.get(groupNameAttributeName).get();
        IEntityGroup g = new EntityTestingGroupImpl(key, IPerson.class);
        g.setCreatorID("System");
        g.setName(groupName);
        g.setDescription(GROUP_DESCRIPTION);
        List<String> membership = new LinkedList<String>();
        Attribute m = attr.get(membershipAttributeName);
        if (m != null) {
            for (Enumeration<?> en = m.getAll(); en.hasMoreElements(); ) {
                membership.add((String) en.nextElement());
            }
        }
        rslt = new LdapRecord(g, membership);
        if (log.isDebugEnabled()) {
            StringBuilder msg = new StringBuilder();
            msg.append("Record Details:").append("\n\tkey=").append(key).append("\n\tgroupName=").append(groupName).append("\n\tmembers:");
            for (String s : membership) {
                msg.append("\n\t\t").append(s);
            }
            log.debug(msg.toString());
        }
    } catch (Throwable t) {
        log.error("Error in SimpleAttributesMapper", t);
        String msg = "SimpleAttributesMapper failed to create a LdapRecord " + "from the specified Attributes:  " + attr;
        throw new RuntimeException(msg, t);
    }
    return rslt;
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) Attribute(javax.naming.directory.Attribute) EntityTestingGroupImpl(org.apereo.portal.groups.EntityTestingGroupImpl) LinkedList(java.util.LinkedList)

Example 40 with IEntityGroup

use of org.apereo.portal.groups.IEntityGroup in project uPortal by Jasig.

the class JpaEventAggregationManagementDaoTest method testAggregatedGroupConfig.

@Test
public void testAggregatedGroupConfig() throws Exception {
    final IEntityGroup everyoneGroup = mock(IEntityGroup.class);
    when(everyoneGroup.getServiceName()).thenReturn(new CompositeName("local"));
    when(everyoneGroup.getName()).thenReturn("Everyone");
    when(compositeGroupService.findGroup("local.0")).thenReturn(everyoneGroup);
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
            assertNotNull(defaultAggregatedGroupConfig);
            assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, defaultAggregatedGroupConfig.getIncluded().size());
            AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNull(loginAggregatedGroupConfig);
            loginAggregatedGroupConfig = eventAggregationManagementDao.createAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNotNull(loginAggregatedGroupConfig);
            assertEquals(0, loginAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, loginAggregatedGroupConfig.getIncluded().size());
            final AggregatedGroupMapping group = aggregatedGroupLookupDao.getGroupMapping("local.0");
            defaultAggregatedGroupConfig.getIncluded().add(group);
            loginAggregatedGroupConfig.getExcluded().add(group);
            eventAggregationManagementDao.updateAggregatedGroupConfig(defaultAggregatedGroupConfig);
            eventAggregationManagementDao.updateAggregatedGroupConfig(loginAggregatedGroupConfig);
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
            assertNotNull(defaultAggregatedGroupConfig);
            assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
            assertEquals(1, defaultAggregatedGroupConfig.getIncluded().size());
            AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNotNull(loginAggregatedGroupConfig);
            assertEquals(1, loginAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, loginAggregatedGroupConfig.getIncluded().size());
            eventAggregationManagementDao.deleteAggregatedGroupConfig(defaultAggregatedGroupConfig);
            eventAggregationManagementDao.deleteAggregatedGroupConfig(loginAggregatedGroupConfig);
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final AggregatedGroupConfig defaultAggregatedGroupConfig = eventAggregationManagementDao.getDefaultAggregatedGroupConfig();
            assertNotNull(defaultAggregatedGroupConfig);
            assertEquals(0, defaultAggregatedGroupConfig.getExcluded().size());
            assertEquals(0, defaultAggregatedGroupConfig.getIncluded().size());
            AggregatedGroupConfig loginAggregatedGroupConfig = eventAggregationManagementDao.getAggregatedGroupConfig(LoginPortalEventAggregator.class);
            assertNull(loginAggregatedGroupConfig);
        }
    });
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) AggregatedGroupConfig(org.apereo.portal.events.aggr.AggregatedGroupConfig) CompositeName(javax.naming.CompositeName) LoginPortalEventAggregator(org.apereo.portal.events.aggr.login.LoginPortalEventAggregator) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Aggregations

IEntityGroup (org.apereo.portal.groups.IEntityGroup)77 IGroupMember (org.apereo.portal.groups.IGroupMember)29 ArrayList (java.util.ArrayList)21 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)16 EntityIdentifier (org.apereo.portal.EntityIdentifier)14 HashSet (java.util.HashSet)11 HashMap (java.util.HashMap)10 LinkedList (java.util.LinkedList)9 GroupsException (org.apereo.portal.groups.GroupsException)9 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)9 IPermission (org.apereo.portal.security.IPermission)9 AggregatedGroupMapping (org.apereo.portal.events.aggr.groups.AggregatedGroupMapping)8 List (java.util.List)7 CompositeName (javax.naming.CompositeName)7 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 IPerson (org.apereo.portal.security.IPerson)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 DateTime (org.joda.time.DateTime)7