Search in sources :

Example 16 with AuthorizationEntity

use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity 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 17 with AuthorizationEntity

use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity 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 18 with AuthorizationEntity

use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity in project camunda-bpm-platform by camunda.

the class AuthorizationServiceAuthorizationsTest method testCreateAuthorization.

public void testCreateAuthorization() {
    // add base permission which allows nobody to create authorizations
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(AUTHORIZATION);
    basePerms.setResourceId(ANY);
    // add all then remove 'create'
    basePerms.addPermission(ALL);
    basePerms.removePermission(CREATE);
    authorizationService.saveAuthorization(basePerms);
    // now enable authorizations:
    processEngineConfiguration.setAuthorizationEnabled(true);
    identityService.setAuthenticatedUserId(jonny2);
    try {
        // we cannot create another authorization
        authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
        fail("exception expected");
    } catch (AuthorizationException e) {
        assertEquals(1, e.getMissingAuthorizations().size());
        MissingAuthorization info = e.getMissingAuthorizations().get(0);
        assertEquals(jonny2, e.getUserId());
        assertExceptionInfo(CREATE.getName(), AUTHORIZATION.resourceName(), null, info);
    }
    // circumvent auth check to get new transient object
    Authorization authorization = new AuthorizationEntity(AUTH_TYPE_REVOKE);
    authorization.setUserId("someUserId");
    authorization.setResource(Resources.APPLICATION);
    try {
        authorizationService.saveAuthorization(authorization);
        fail("exception expected");
    } catch (AuthorizationException e) {
        assertEquals(1, e.getMissingAuthorizations().size());
        MissingAuthorization info = e.getMissingAuthorizations().get(0);
        assertEquals(jonny2, e.getUserId());
        assertExceptionInfo(CREATE.getName(), AUTHORIZATION.resourceName(), null, info);
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) AuthorizationEntity(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity)

Example 19 with AuthorizationEntity

use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity in project camunda-bpm-platform by camunda.

the class DeleteAuthorizationCmd method execute.

public Void execute(CommandContext commandContext) {
    final AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
    AuthorizationEntity authorization = (AuthorizationEntity) new AuthorizationQueryImpl().authorizationId(authorizationId).singleResult();
    ensureNotNull("Authorization for Id '" + authorizationId + "' does not exist", "authorization", authorization);
    authorizationManager.delete(authorization);
    return null;
}
Also used : AuthorizationQueryImpl(org.camunda.bpm.engine.impl.AuthorizationQueryImpl) AuthorizationEntity(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity) AuthorizationManager(org.camunda.bpm.engine.impl.persistence.entity.AuthorizationManager)

Aggregations

AuthorizationEntity (org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity)19 Permission (org.camunda.bpm.engine.authorization.Permission)4 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)2 IdentityService (org.camunda.bpm.engine.IdentityService)2 Authorization (org.camunda.bpm.engine.authorization.Authorization)2 Resource (org.camunda.bpm.engine.authorization.Resource)2 ResourceAuthorizationProvider (org.camunda.bpm.engine.impl.cfg.auth.ResourceAuthorizationProvider)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 FilterService (org.camunda.bpm.engine.FilterService)1 TaskService (org.camunda.bpm.engine.TaskService)1 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)1 Filter (org.camunda.bpm.engine.filter.Filter)1 Group (org.camunda.bpm.engine.identity.Group)1 User (org.camunda.bpm.engine.identity.User)1 AuthorizationQueryImpl (org.camunda.bpm.engine.impl.AuthorizationQueryImpl)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)1