Search in sources :

Example 51 with IGroupMember

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

the class XalanGroupMembershipHelperBean method isUserDeepMemberOfGroupName.

/* (non-Javadoc)
     * @see org.apereo.portal.security.xslt.IXalanGroupMembershipHelper#isUserDeepMemberOfGroupName(java.lang.String, java.lang.String)
     *
     * groupName is case sensitive.
     */
@Override
public boolean isUserDeepMemberOfGroupName(String userName, String groupName) {
    final EntityIdentifier[] results = GroupService.searchForGroups(groupName, GroupService.SearchMethod.DISCRETE, IPerson.class);
    if (results == null || results.length == 0) {
        return false;
    }
    if (results.length > 1) {
        this.logger.warn(results.length + " groups were found for '" + groupName + "'. The first result will be used.");
    }
    final IGroupMember group = GroupService.getGroupMember(results[0]);
    final IEntity entity = GroupService.getEntity(userName, IPerson.class);
    if (entity == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("No user found for key '" + userName + "'");
        }
        return false;
    }
    return group.asGroup().deepContains(entity);
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) IEntity(org.apereo.portal.groups.IEntity) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 52 with IGroupMember

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

the class AuthorizationTester method testAlternativePermissionPolicies.

public void testAlternativePermissionPolicies() throws Exception {
    print("***** ENTERING AuthorizationTester.testAlternativePermissionPolicies() *****");
    String msg = null;
    boolean testResult = false;
    String activity = IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
    String existingTarget = "CHAN_ID.1";
    String nonExistingTarget = "CHAN_ID.9999";
    msg = "Creating a group member for everyone (" + EVERYONE_GROUP_PRINCIPAL_KEY + ").";
    print(msg);
    IGroupMember everyone = GroupService.getGroupMember(EVERYONE_GROUP_KEY, GROUP_CLASS);
    assertNotNull(msg, everyone);
    msg = "Getting principal for " + everyone;
    print(msg);
    IAuthorizationPrincipal prin = getService().newPrincipal(everyone);
    assertNotNull(msg, prin);
    msg = "Testing DEFAULT permission policy for an existing channel";
    print(msg);
    testResult = prin.hasPermission(OWNER, activity, existingTarget);
    assertTrue(msg, testResult);
    msg = "Testing POSITIVE permission policy for an existing channel";
    print(msg);
    testResult = prin.hasPermission(OWNER, activity, existingTarget, getPositivePermissionPolicy());
    assertTrue(msg, testResult);
    msg = "Testing NEGATIVE permission policy for an existing channel";
    print(msg);
    testResult = prin.hasPermission(OWNER, activity, existingTarget, getNegativePermissionPolicy());
    assertTrue(msg, !testResult);
    msg = "Testing DEFAULT permission policy for a nonexistent channel";
    print(msg);
    testResult = prin.hasPermission(OWNER, activity, nonExistingTarget);
    assertTrue(msg, !testResult);
    msg = "Testing POSITIVE permission policy for nonexistent channel";
    print(msg);
    testResult = prin.hasPermission(OWNER, activity, nonExistingTarget, getPositivePermissionPolicy());
    assertTrue(msg, testResult);
    msg = "Testing NEGATIVE permission policy for a nonexistent channel";
    print(msg);
    testResult = prin.hasPermission(OWNER, activity, nonExistingTarget, getNegativePermissionPolicy());
    assertTrue(msg, !testResult);
    print("***** LEAVING AuthorizationTester.testAlternativePermissionPolicies() *****" + CR);
}
Also used : IGroupMember(org.apereo.portal.groups.IGroupMember) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal)

Aggregations

IGroupMember (org.apereo.portal.groups.IGroupMember)52 IEntityGroup (org.apereo.portal.groups.IEntityGroup)29 HashSet (java.util.HashSet)17 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)14 ArrayList (java.util.ArrayList)12 EntityIdentifier (org.apereo.portal.EntityIdentifier)12 EntityEnum (org.apereo.portal.portlets.groupselector.EntityEnum)10 JsonEntityBean (org.apereo.portal.layout.dlm.remoting.JsonEntityBean)9 IPermission (org.apereo.portal.security.IPermission)8 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)7 GroupsException (org.apereo.portal.groups.GroupsException)6 HashMap (java.util.HashMap)4 IEntity (org.apereo.portal.groups.IEntity)4 ExternalPermissionDefinition (org.apereo.portal.io.xml.portlettype.ExternalPermissionDefinition)4 IPerson (org.apereo.portal.security.IPerson)4 Element (net.sf.ehcache.Element)3 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)3 AuthorizationServiceFacade (org.apereo.portal.services.AuthorizationServiceFacade)3 GcGetMembers (edu.internet2.middleware.grouperClient.api.GcGetMembers)2 WsGetMembersResults (edu.internet2.middleware.grouperClient.ws.beans.WsGetMembersResults)2