use of org.apache.shiro.authz.SimpleAuthorizationInfo in project mica2 by obiba.
the class MicaAuthorizingRealm method doGetAuthorizationInfo.
//
// AuthorizingRealm
//
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
List<String> perms = loadUserPermissions(principals);
if (perms == null || perms.isEmpty())
return null;
SimpleAuthorizationInfo sai = new SimpleAuthorizationInfo();
sai.setStringPermissions(ImmutableSet.copyOf(perms));
return sai;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project airpal by airbnb.
the class ExampleLDAPRealm method doGetAuthorizationInfo.
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Set<String> roles = Sets.newHashSet("user");
Set<Permission> permissions = Sets.newHashSet();
Collection<AllowAllUser> principalsCollection = principals.byType(AllowAllUser.class);
if (principalsCollection.isEmpty()) {
throw new AuthorizationException("No principals!");
}
for (AllowAllUser user : principalsCollection) {
for (UserGroup userGroup : groups) {
if (userGroup.representedByGroupStrings(user.getGroups())) {
permissions.addAll(userGroup.getPermissions());
break;
}
}
}
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(roles);
authorizationInfo.setObjectPermissions(permissions);
return authorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project xmall by Exrick.
the class MyRealm method doGetAuthorizationInfo.
/**
* 返回权限信息
* @param principal
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {
// 获取用户名
String username = principal.getPrimaryPrincipal().toString();
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
// 获得授权角色
authorizationInfo.setRoles(userService.getRoles(username));
// 获得授权权限
authorizationInfo.setStringPermissions(userService.getPermissions(username));
return authorizationInfo;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project ddf by codice.
the class XacmlPdpTest method generateSubjectInfo.
private AuthorizationInfo generateSubjectInfo(String country) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Set<Permission> permissions = new HashSet<Permission>();
Set<String> roles = new HashSet<String>();
// add roles
roles.add("users");
roles.add("admin");
// add permissions
KeyValuePermission citizenshipPermission = new KeyValuePermissionImpl(COUNTRY);
citizenshipPermission.addValue(country);
permissions.add(citizenshipPermission);
KeyValuePermission typePermission = new KeyValuePermissionImpl(SUBJECT_ACCESS);
typePermission.addValue(ACCESS_TYPE_A);
typePermission.addValue(ACCESS_TYPE_B);
KeyValuePermission nameIdentPermission = new KeyValuePermissionImpl(NAME_IDENTIFIER);
nameIdentPermission.addValue("testuser1");
KeyValuePermission givenNamePermission = new KeyValuePermissionImpl(GIVEN_NAME);
givenNamePermission.addValue("Test User");
permissions.add(typePermission);
permissions.add(nameIdentPermission);
permissions.add(givenNamePermission);
info.setRoles(roles);
info.setObjectPermissions(permissions);
return info;
}
use of org.apache.shiro.authz.SimpleAuthorizationInfo in project ddf by codice.
the class XacmlPdpTest method testActionGoodSiteName.
@Test
public void testActionGoodSiteName() {
SimpleAuthorizationInfo blankUserInfo = new SimpleAuthorizationInfo(new HashSet<String>());
blankUserInfo.setObjectPermissions(new HashSet<Permission>());
RequestType request = testRealm.createXACMLRequest(USER_NAME, blankUserInfo, new KeyValueCollectionPermissionImpl(SITE_NAME_ACTION));
assertThat(testRealm.isPermitted(request), equalTo(true));
}
Aggregations