Search in sources :

Example 16 with Permission

use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.

the class DefaultAuthorizationProvider method updateAuthorization.

protected AuthorizationEntity updateAuthorization(AuthorizationEntity authorization, String userId, String groupId, Resource resource, String resourceId, Permission... permissions) {
    if (authorization == null) {
        authorization = createGrantAuthorization(userId, groupId, resource, resourceId);
        updateAuthorizationBasedOnCacheEntries(authorization, userId, groupId, resource, resourceId);
    }
    if (permissions != null) {
        for (Permission permission : permissions) {
            authorization.addPermission(permission);
        }
    }
    return authorization;
}
Also used : Permission(org.camunda.bpm.engine.authorization.Permission)

Example 17 with Permission

use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.

the class AuthorizationServiceTest method testGlobalAuthPermissions.

public void testGlobalAuthPermissions() {
    AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_GRANT);
    assertFalse(authorization.isPermissionGranted(ALL));
    assertTrue(authorization.isPermissionGranted(NONE));
    List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
    assertTrue(perms.contains(NONE));
    assertEquals(1, perms.size());
    authorization.addPermission(READ);
    perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
    assertTrue(perms.contains(NONE));
    assertTrue(perms.contains(READ));
    assertEquals(2, perms.size());
    assertTrue(authorization.isPermissionGranted(READ));
    // (none is always granted => you are always authorized to do nothing)
    assertTrue(authorization.isPermissionGranted(NONE));
    try {
        authorization.isPermissionRevoked(READ);
        fail("Exception expected");
    } catch (IllegalStateException e) {
        assertTextPresent("ENGINE-03026 Method 'isPermissionRevoked' cannot be used for authorization with type 'GRANT'.", e.getMessage());
    }
}
Also used : AuthorizationEntity(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity) Permission(org.camunda.bpm.engine.authorization.Permission)

Example 18 with Permission

use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.

the class AuthorizationServiceTest method testRevokeAuthPermissions.

public void testRevokeAuthPermissions() {
    AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_REVOKE);
    assertFalse(authorization.isPermissionRevoked(ALL));
    List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
    assertEquals(0, perms.size());
    authorization.removePermission(READ);
    perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
    assertTrue(perms.contains(READ));
    assertTrue(perms.contains(ALL));
    assertEquals(2, perms.size());
    try {
        authorization.isPermissionGranted(READ);
        fail("Exception expected");
    } catch (IllegalStateException e) {
        assertTextPresent("ENGINE-03026 Method 'isPermissionGranted' cannot be used for authorization with type 'REVOKE'.", e.getMessage());
    }
}
Also used : AuthorizationEntity(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity) Permission(org.camunda.bpm.engine.authorization.Permission)

Example 19 with Permission

use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.

the class AuthorizationServiceTest method testGrantAuthPermissions.

public void testGrantAuthPermissions() {
    AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_GRANT);
    assertFalse(authorization.isPermissionGranted(ALL));
    assertTrue(authorization.isPermissionGranted(NONE));
    List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
    assertTrue(perms.contains(NONE));
    assertEquals(1, perms.size());
    authorization.addPermission(READ);
    perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
    assertTrue(perms.contains(NONE));
    assertTrue(perms.contains(READ));
    assertEquals(2, perms.size());
    assertTrue(authorization.isPermissionGranted(READ));
    // (none is always granted => you are always authorized to do nothing)
    assertTrue(authorization.isPermissionGranted(NONE));
    try {
        authorization.isPermissionRevoked(READ);
        fail("Exception expected");
    } catch (IllegalStateException e) {
        assertTextPresent("ENGINE-03026 Method 'isPermissionRevoked' cannot be used for authorization with type 'GRANT'.", e.getMessage());
    }
}
Also used : AuthorizationEntity(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity) Permission(org.camunda.bpm.engine.authorization.Permission)

Example 20 with Permission

use of org.camunda.bpm.engine.authorization.Permission in project camunda-bpm-platform by camunda.

the class AuthorizationTest method createGrantAuthorization.

// authorization ///////////////////////////////////////////////////////
protected void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
    Authorization authorization = createGrantAuthorization(resource, resourceId);
    authorization.setUserId(userId);
    for (Permission permission : permissions) {
        authorization.addPermission(permission);
    }
    saveAuthorization(authorization);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) Permission(org.camunda.bpm.engine.authorization.Permission)

Aggregations

Permission (org.camunda.bpm.engine.authorization.Permission)20 Authorization (org.camunda.bpm.engine.authorization.Authorization)12 AuthorizationEntity (org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity)4 ArrayList (java.util.ArrayList)2 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)2 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)2 Resource (org.camunda.bpm.engine.authorization.Resource)2