Search in sources :

Example 86 with Authorization

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

the class AuthorizationServiceTest method testUpdateNewAuthorization.

public void testUpdateNewAuthorization() {
    TestResource resource1 = new TestResource("resource1", 100);
    TestResource resource2 = new TestResource("resource1", 101);
    Authorization authorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    authorization.setUserId("aUserId");
    authorization.setResource(resource1);
    authorization.setResourceId("aResourceId");
    authorization.addPermission(ACCESS);
    // save the authorization
    authorizationService.saveAuthorization(authorization);
    // validate authorization
    Authorization savedAuthorization = authorizationService.createAuthorizationQuery().singleResult();
    assertEquals("aUserId", savedAuthorization.getUserId());
    assertEquals(resource1.resourceType(), savedAuthorization.getResourceType());
    assertEquals("aResourceId", savedAuthorization.getResourceId());
    assertTrue(savedAuthorization.isPermissionGranted(ACCESS));
    // update authorization
    authorization.setUserId("anotherUserId");
    authorization.setResource(resource2);
    authorization.setResourceId("anotherResourceId");
    authorization.addPermission(DELETE);
    authorizationService.saveAuthorization(authorization);
    // validate authorization updated
    savedAuthorization = authorizationService.createAuthorizationQuery().singleResult();
    assertEquals("anotherUserId", savedAuthorization.getUserId());
    assertEquals(resource2.resourceType(), savedAuthorization.getResourceType());
    assertEquals("anotherResourceId", savedAuthorization.getResourceId());
    assertTrue(savedAuthorization.isPermissionGranted(ACCESS));
    assertTrue(savedAuthorization.isPermissionGranted(DELETE));
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization)

Example 87 with Authorization

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

the class AuthorizationServiceTest method testCreateAuthorizationWithGroupId.

public void testCreateAuthorizationWithGroupId() {
    TestResource resource1 = new TestResource("resource1", 100);
    // initially, no authorization exists:
    assertEquals(0, authorizationService.createAuthorizationQuery().count());
    // simple create / delete with userId
    Authorization authorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    authorization.setGroupId("aGroupId");
    authorization.setResource(resource1);
    // save the authorization
    authorizationService.saveAuthorization(authorization);
    // authorization exists
    assertEquals(1, authorizationService.createAuthorizationQuery().count());
    // delete the authorization
    authorizationService.deleteAuthorization(authorization.getId());
    // it's gone
    assertEquals(0, authorizationService.createAuthorizationQuery().count());
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization)

Example 88 with Authorization

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

the class AuthorizationServiceTest method testUniqueUserConstraints.

public void testUniqueUserConstraints() {
    TestResource resource1 = new TestResource("resource1", 100);
    Authorization authorization1 = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    Authorization authorization2 = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    authorization1.setResource(resource1);
    authorization1.setResourceId("someId");
    authorization1.setUserId("someUser");
    authorization2.setResource(resource1);
    authorization2.setResourceId("someId");
    authorization2.setUserId("someUser");
    // the first one can be saved
    authorizationService.saveAuthorization(authorization1);
    // the second one cannot
    try {
        authorizationService.saveAuthorization(authorization2);
        fail("exception expected");
    } catch (ProcessEngineException e) {
    // expected
    }
    // but I can add a AUTH_TYPE_REVOKE auth
    Authorization authorization3 = authorizationService.createNewAuthorization(AUTH_TYPE_REVOKE);
    authorization3.setResource(resource1);
    authorization3.setResourceId("someId");
    authorization3.setUserId("someUser");
    authorizationService.saveAuthorization(authorization3);
    // but not a second
    Authorization authorization4 = authorizationService.createNewAuthorization(AUTH_TYPE_REVOKE);
    authorization4.setResource(resource1);
    authorization4.setResourceId("someId");
    authorization4.setUserId("someUser");
    try {
        authorizationService.saveAuthorization(authorization4);
        fail("exception expected");
    } catch (Exception e) {
    // expected
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 89 with Authorization

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

the class AuthorizationServiceTest method testGlobalUniqueConstraints.

public void testGlobalUniqueConstraints() {
    TestResource resource1 = new TestResource("resource1", 100);
    Authorization authorization1 = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    Authorization authorization2 = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    authorization1.setResource(resource1);
    authorization1.setResourceId("someId");
    authorization2.setResource(resource1);
    authorization2.setResourceId("someId");
    // the first one can be saved
    authorizationService.saveAuthorization(authorization1);
    // the second one cannot
    try {
        authorizationService.saveAuthorization(authorization2);
        fail("exception expected");
    } catch (Exception e) {
    // expected
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 90 with Authorization

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

the class AuthorizationServiceAuthorizationsTest method testDeleteAuthorization.

public void testDeleteAuthorization() {
    // create global auth
    Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    basePerms.setResource(AUTHORIZATION);
    basePerms.setResourceId(ANY);
    basePerms.addPermission(ALL);
    // revoke delete
    basePerms.removePermission(DELETE);
    authorizationService.saveAuthorization(basePerms);
    // turn on authorization
    processEngineConfiguration.setAuthorizationEnabled(true);
    identityService.setAuthenticatedUserId(jonny2);
    try {
        // try to delete authorization
        authorizationService.deleteAuthorization(basePerms.getId());
        fail("exception expected");
    } catch (AuthorizationException e) {
        assertEquals(1, e.getMissingAuthorizations().size());
        MissingAuthorization info = e.getMissingAuthorizations().get(0);
        assertEquals(jonny2, e.getUserId());
        assertExceptionInfo(DELETE.getName(), AUTHORIZATION.resourceName(), basePerms.getId(), 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)

Aggregations

Authorization (org.camunda.bpm.engine.authorization.Authorization)117 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)26 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)22 User (org.camunda.bpm.engine.identity.User)20 Test (org.junit.Test)17 AuthorizationQuery (org.camunda.bpm.engine.authorization.AuthorizationQuery)16 Group (org.camunda.bpm.engine.identity.Group)13 Permission (org.camunda.bpm.engine.authorization.Permission)12 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)9 Tenant (org.camunda.bpm.engine.identity.Tenant)9 AuthorizationDto (org.camunda.bpm.engine.rest.dto.authorization.AuthorizationDto)8 Matchers.anyString (org.mockito.Matchers.anyString)7 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 IdentityService (org.camunda.bpm.engine.IdentityService)3 Resource (org.camunda.bpm.engine.authorization.Resource)3 TenantEntity (org.camunda.bpm.engine.impl.persistence.entity.TenantEntity)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Filter (org.camunda.bpm.engine.filter.Filter)2