Search in sources :

Example 31 with SimpleAuthorizationInfo

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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo)

Example 32 with SimpleAuthorizationInfo

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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) AuthorizationException(org.apache.shiro.authz.AuthorizationException) Permission(org.apache.shiro.authz.Permission)

Example 33 with SimpleAuthorizationInfo

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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo)

Example 34 with SimpleAuthorizationInfo

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;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) KeyValuePermissionImpl(ddf.security.permission.impl.KeyValuePermissionImpl) CollectionPermission(ddf.security.permission.CollectionPermission) KeyValuePermission(ddf.security.permission.KeyValuePermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) KeyValuePermission(ddf.security.permission.KeyValuePermission) HashSet(java.util.HashSet)

Example 35 with SimpleAuthorizationInfo

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));
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) CollectionPermission(ddf.security.permission.CollectionPermission) KeyValuePermission(ddf.security.permission.KeyValuePermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) KeyValueCollectionPermissionImpl(ddf.security.permission.impl.KeyValueCollectionPermissionImpl) RequestType(oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType) Test(org.junit.Test)

Aggregations

SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)48 Permission (org.apache.shiro.authz.Permission)8 AuthorizationException (org.apache.shiro.authz.AuthorizationException)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 KeyValuePermission (ddf.security.permission.KeyValuePermission)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 AuthenticationException (org.apache.shiro.authc.AuthenticationException)5 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)5 KeyValuePermissionImpl (ddf.security.permission.impl.KeyValuePermissionImpl)4 CollectionPermission (ddf.security.permission.CollectionPermission)3 HashMap (java.util.HashMap)3 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 Group (com.ganster.cms.core.pojo.Group)2 Permission (com.ganster.cms.core.pojo.Permission)2 User (com.ganster.cms.core.pojo.User)2 UserExample (com.ganster.cms.core.pojo.UserExample)2 TbRolePermission (com.netsteadfast.greenstep.po.hbm.TbRolePermission)2 TbUserRole (com.netsteadfast.greenstep.po.hbm.TbUserRole)2 Set (java.util.Set)2