org.springframework.security.acls.domain.CumulativePermission Java Examples

The following examples show how to use org.springframework.security.acls.domain.CumulativePermission. 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 File: PropertyAclServiceConfigurer.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
private static Permission parsePerms(String perms) {

        final int length = perms.length();
        if(length > 32) {
            throw new IllegalArgumentException("Too long permission expression: " + perms + " it must be shortest than 32 chars.");
        }
        Permission perm;
        if(length == 1) {
            perm = parseLetter(perms.charAt(0));
        } else {
            CumulativePermission cp = new CumulativePermission();
            for(int i = 0; i < length; ++i) {
                cp.set(parseLetter(perms.charAt(i)));
            }
            perm = cp;
        }
        return perm;
    }
 
Example #2
Source File: NextServerPermission.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
public static Permission buildFromMask(int mask) {
    if (permissionsByInteger.containsKey(mask)) {
        return permissionsByInteger.get(mask);
    }

    // to get this far, we have to use a CumulativePermission
    CumulativePermission cumulativePermission = new CumulativePermission();
    for (int i = 0; i < 32; i++) {
        int permissionToCheck = 1 << i;
        if ((mask & permissionToCheck) == permissionToCheck) {
            Permission permission = permissionsByInteger.get(permissionToCheck);
            if (permission == null) {
            	System.out.println("Mask " + permissionToCheck + " does not have a corresponding static NextServerPermission");
            	continue;
            }
            cumulativePermission.set(permission);
        }
    }

    return cumulativePermission;
}
 
Example #3
Source File: BitMaskPermissionGrantingStrategyTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
static Object[][] permissionsDontMatchProvider() {
  return new Object[][] {
    {READ, WRITE},
    {COUNT, new CumulativePermission().set(READ).set(WRITE).set(WRITEMETA)},
    {WRITE, new CumulativePermission().set(READ).set(WRITEMETA)}
  };
}
 
Example #4
Source File: UserPermissionEvaluatorImplTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@WithMockUser(username = "USER")
@Test
void hasPermissionOnEntityTypeTrue() {
  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  when(permissionRegistry.getPermissions(READ_DATA))
      .thenReturn(ImmutableSet.of(READ, WRITE, WRITEMETA));
  CumulativePermission permissionToCheck =
      new CumulativePermission().set(READ).set(WRITE).set(WRITEMETA);
  when(permissionEvaluator.hasPermission(
          authentication, "entityType0", "entityType", permissionToCheck))
      .thenReturn(true);
  assertTrue(
      userPermissionEvaluator.hasPermission(new EntityTypeIdentity("entityType0"), READ_DATA));
}
 
Example #5
Source File: UserPermissionEvaluatorImplTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@WithMockUser(username = "USER")
@Test
void hasPermissionOnPluginTrue() {
  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  when(permissionRegistry.getPermissions(VIEW_PLUGIN)).thenReturn(ImmutableSet.of(READ));
  when(permissionEvaluator.hasPermission(
          authentication, "plugin1", "plugin", new CumulativePermission().set(READ)))
      .thenReturn(true);
  assertTrue(userPermissionEvaluator.hasPermission(new PluginIdentity("plugin1"), VIEW_PLUGIN));
}
 
Example #6
Source File: UserPermissionEvaluatorImpl.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
private CumulativePermission getCumulativePermissionToCheck(Permission permission) {
  CumulativePermission result = new CumulativePermission();
  Set<PermissionSet> permissionSets = permissionRegistry.getPermissions(permission);
  permissionSets.forEach(result::set);
  return result;
}
 
Example #7
Source File: BitMaskPermissionGrantingStrategyTest.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
static Object[][] permissionsMatchProvider() {
  return new Object[][] {{READ, new CumulativePermission().set(READ).set(WRITE)}, {READ, READ}};
}