Search in sources :

Example 56 with Authorization

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

the class AuthorizationQueryTest method createAuthorization.

protected void createAuthorization(String userId, String groupId, Resource resourceType, String resourceId, Permission... permissions) {
    Authorization authorization = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GRANT);
    authorization.setUserId(userId);
    authorization.setGroupId(groupId);
    authorization.setResource(resourceType);
    authorization.setResourceId(resourceId);
    for (Permission permission : permissions) {
        authorization.addPermission(permission);
    }
    authorizationService.saveAuthorization(authorization);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) Permission(org.camunda.bpm.engine.authorization.Permission)

Example 57 with Authorization

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

the class AuthorizationServiceTest method testUniqueGroupConstraints.

public void testUniqueGroupConstraints() {
    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.setGroupId("someGroup");
    authorization2.setResource(resource1);
    authorization2.setResourceId("someId");
    authorization2.setGroupId("someGroup");
    // the first one can be saved
    authorizationService.saveAuthorization(authorization1);
    // the second one cannot
    try {
        authorizationService.saveAuthorization(authorization2);
        fail("exception expected");
    } catch (Exception 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.setGroupId("someGroup");
    authorizationService.saveAuthorization(authorization3);
    // but not a second
    Authorization authorization4 = authorizationService.createNewAuthorization(AUTH_TYPE_REVOKE);
    authorization4.setResource(resource1);
    authorization4.setResourceId("someId");
    authorization4.setGroupId("someGroup");
    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)

Example 58 with Authorization

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

the class AuthorizationServiceTest method testUpdatePersistentAuthorization.

public void testUpdatePersistentAuthorization() {
    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
    savedAuthorization.setUserId("anotherUserId");
    savedAuthorization.setResource(resource2);
    savedAuthorization.setResourceId("anotherResourceId");
    savedAuthorization.addPermission(DELETE);
    authorizationService.saveAuthorization(savedAuthorization);
    // 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 59 with Authorization

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

the class AuthorizationServiceTest method testGrantAuthorizationType.

public void testGrantAuthorizationType() {
    Authorization grantAuthorization = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    // I can set userId = null
    grantAuthorization.setUserId(null);
    // I can set userId = ANY
    grantAuthorization.setUserId(ANY);
    // I can set anything else:
    grantAuthorization.setUserId("something");
    // I can set groupId = null
    grantAuthorization.setGroupId(null);
    // I can set anything else:
    grantAuthorization.setGroupId("something");
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization)

Example 60 with Authorization

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

the class AuthorizationServiceTest method testGlobalAuthorizationType.

public void testGlobalAuthorizationType() {
    Authorization globalAuthorization = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    // I can set userId = null
    globalAuthorization.setUserId(null);
    // I can set userId = ANY
    globalAuthorization.setUserId(ANY);
    try {
        // I cannot set anything else:
        globalAuthorization.setUserId("something");
        fail("exception expected");
    } catch (Exception e) {
        assertTextPresent("ENGINE-03028 Illegal value 'something' for userId for GLOBAL authorization. Must be '*'", e.getMessage());
    }
    // I can set groupId = null
    globalAuthorization.setGroupId(null);
    try {
        // I cannot set anything else:
        globalAuthorization.setGroupId("something");
        fail("exception expected");
    } catch (Exception e) {
        assertTextPresent("ENGINE-03027 Cannot use 'groupId' for GLOBAL authorization", e.getMessage());
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

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