org.apache.shiro.authz.permission.WildcardPermission Java Examples

The following examples show how to use org.apache.shiro.authz.permission.WildcardPermission. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: nexus-public   Author: sonatype   File: AuthorizingRealmImplTest.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAuthorization() throws Exception {
  buildTestAuthorizationConfig();

  // Fails because the configuration requirement in nexus authorizing realm isn't initialized
  // thus NPE
  SimplePrincipalCollection principal = new SimplePrincipalCollection("username", realm.getName());

  Assert.assertTrue(realm.hasRole(principal, "role"));

  // Verify the permission
  Assert.assertTrue(realm.isPermitted(principal, new WildcardPermission("app:config:read")));
  // Verify other method not allowed
  Assert.assertFalse(realm.isPermitted(principal, new WildcardPermission("app:config:create")));
  Assert.assertFalse(realm.isPermitted(principal, new WildcardPermission("app:config:update")));
  Assert.assertFalse(realm.isPermitted(principal, new WildcardPermission("app:config:delete")));

  // Verify other permission not allowed
  Assert.assertFalse(realm.isPermitted(principal, new WildcardPermission("app:ui:read")));
  Assert.assertFalse(realm.isPermitted(principal, new WildcardPermission("app:ui:create")));
  Assert.assertFalse(realm.isPermitted(principal, new WildcardPermission("app:ui:update")));
  Assert.assertFalse(realm.isPermitted(principal, new WildcardPermission("app:ui:delete")));
}
 
Example #2
Source Project: es   Author: zhangkaitao   File: ResourceService.java    License: Apache License 2.0 6 votes vote down vote up
private boolean hasPermission(String permission, String actualResourceIdentity) {

        //得到权限字符串中的 资源部分,如a:b:create --->资源是a:b
        String permissionResourceIdentity = permission.substring(0, permission.lastIndexOf(":"));

        //如果权限字符串中的资源 是 以资源为前缀 则有权限 如a:b 具有a:b的权限
        if(permissionResourceIdentity.startsWith(actualResourceIdentity)) {
            return true;
        }


        //模式匹配
        WildcardPermission p1 = new WildcardPermission(permissionResourceIdentity);
        WildcardPermission p2 = new WildcardPermission(actualResourceIdentity);

        return p1.implies(p2) || p2.implies(p1);
    }
 
Example #3
Source Project: wetech-admin   Author: cjbi   File: PermissionServiceImpl.java    License: MIT License 5 votes vote down vote up
private boolean hasPermission(Set<String> permissions, Permission resource) {
    if (StringUtils.isEmpty(resource.getPermission())) {
        return true;
    }
    for (String permission : permissions) {
        WildcardPermission p1 = new WildcardPermission(permission);
        WildcardPermission p2 = new WildcardPermission(resource.getPermission());
        if (p1.implies(p2) || p2.implies(p1)) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source Project: airpal   Author: airbnb   File: UserGroup.java    License: Apache License 2.0 5 votes vote down vote up
public void setPermissions(Set<String> permissions)
{
    ImmutableSet.Builder<Permission> builder = ImmutableSet.builder();
    for (String permission : permissions) {
        builder.add(new WildcardPermission(permission));
    }

    this.permissions = builder.build();
}
 
Example #5
Source Project: arcusplatform   Author: arcus-smart-home   File: PermissionFactory.java    License: Apache License 2.0 4 votes vote down vote up
public static Permission createPermission(String permission) {
   if(InstancePermission.isInstancePermission(permission)) {
      return new InstancePermission(permission);
   }
   return new WildcardPermission(permission);
}
 
Example #6
Source Project: arcusplatform   Author: arcus-smart-home   File: TestPermissionFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testCreatesWildcardPermission() {
   Permission permission = PermissionFactory.createPermission("swit:*:*");
   assertTrue(permission instanceof WildcardPermission);
}
 
Example #7
Source Project: seed   Author: seedstack   File: ScopePermission.java    License: Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Constructor with a permission
 *
 * @param permission the permission
 */
public ScopePermission(String permission) {
    this.permission = new WildcardPermission(permission);
    this.scope = null;
}
 
Example #8
Source Project: seed   Author: seedstack   File: ScopePermission.java    License: Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Constructor with permissions and scope.
 *
 * @param permission the permission
 * @param scope      the scope
 */
public ScopePermission(String permission, Scope scope) {
    this.permission = new WildcardPermission(permission);
    this.scope = scope;
}