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