Search in sources :

Example 66 with Authorization

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

the class AuthorizationPerformanceTestCase method grouptGrant.

protected void grouptGrant(String groupId, Resource resource, Permission... perms) {
    AuthorizationService authorizationService = engine.getAuthorizationService();
    Authorization groupGrant = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    groupGrant.setResource(resource);
    groupGrant.setResourceId(ANY);
    for (Permission permission : perms) {
        groupGrant.addPermission(permission);
    }
    groupGrant.setGroupId(groupId);
    authorizationService.saveAuthorization(groupGrant);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) AuthorizationService(org.camunda.bpm.engine.AuthorizationService) Permission(org.camunda.bpm.engine.authorization.Permission)

Example 67 with Authorization

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

the class LdapGroupQueryTest method createGrantAuthorization.

protected void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
    Authorization authorization = createAuthorization(AUTH_TYPE_GRANT, resource, resourceId);
    authorization.setUserId(userId);
    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 68 with Authorization

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

the class LdapGroupQueryTest method testPaginationWithAuthenticatedUser.

public void testPaginationWithAuthenticatedUser() {
    createGrantAuthorization(GROUP, "management", "oscar", READ);
    createGrantAuthorization(GROUP, "consulting", "oscar", READ);
    createGrantAuthorization(GROUP, "external", "oscar", READ);
    try {
        processEngineConfiguration.setAuthorizationEnabled(true);
        identityService.setAuthenticatedUserId("oscar");
        Set<String> groupNames = new HashSet<String>();
        List<Group> groups = identityService.createGroupQuery().listPage(0, 2);
        assertEquals(2, groups.size());
        checkPagingResults(groupNames, groups.get(0).getId(), groups.get(1).getId());
        groups = identityService.createGroupQuery().listPage(2, 2);
        assertEquals(1, groups.size());
        assertFalse(groupNames.contains(groups.get(0).getId()));
        groupNames.add(groups.get(0).getId());
        groups = identityService.createGroupQuery().listPage(4, 2);
        assertEquals(0, groups.size());
        identityService.setAuthenticatedUserId("daniel");
        groups = identityService.createGroupQuery().listPage(0, 2);
        assertEquals(0, groups.size());
    } finally {
        processEngineConfiguration.setAuthorizationEnabled(false);
        identityService.clearAuthentication();
        for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
            authorizationService.deleteAuthorization(authorization.getId());
        }
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) Group(org.camunda.bpm.engine.identity.Group) HashSet(java.util.HashSet)

Example 69 with Authorization

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

the class LdapUserQueryTest method testPaginationWithAuthenticatedUser.

public void testPaginationWithAuthenticatedUser() {
    createGrantAuthorization(USER, "roman", "oscar", READ);
    createGrantAuthorization(USER, "daniel", "oscar", READ);
    createGrantAuthorization(USER, "monster", "oscar", READ);
    createGrantAuthorization(USER, "ruecker", "oscar", READ);
    try {
        processEngineConfiguration.setAuthorizationEnabled(true);
        identityService.setAuthenticatedUserId("oscar");
        Set<String> userNames = new HashSet<String>();
        List<User> users = identityService.createUserQuery().listPage(0, 2);
        assertEquals(2, users.size());
        checkPagingResults(userNames, users.get(0).getId(), users.get(1).getId());
        users = identityService.createUserQuery().listPage(2, 2);
        assertEquals(2, users.size());
        checkPagingResults(userNames, users.get(0).getId(), users.get(1).getId());
        users = identityService.createUserQuery().listPage(4, 2);
        assertEquals(1, users.size());
        assertFalse(userNames.contains(users.get(0).getId()));
        userNames.add(users.get(0).getId());
        identityService.setAuthenticatedUserId("daniel");
        users = identityService.createUserQuery().listPage(0, 2);
        assertEquals(1, users.size());
        assertEquals("daniel", users.get(0).getId());
        users = identityService.createUserQuery().listPage(2, 2);
        assertEquals(0, users.size());
    } finally {
        processEngineConfiguration.setAuthorizationEnabled(false);
        identityService.clearAuthentication();
        for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
            authorizationService.deleteAuthorization(authorization.getId());
        }
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) User(org.camunda.bpm.engine.identity.User) HashSet(java.util.HashSet)

Example 70 with Authorization

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

the class LdapDisableAuthorizationCheckTest method testUserQueryPaginationWithAuthenticatedUserWithAuthorizations.

public void testUserQueryPaginationWithAuthenticatedUserWithAuthorizations() {
    createGrantAuthorization(USER, "roman", "oscar", READ);
    createGrantAuthorization(USER, "daniel", "oscar", READ);
    createGrantAuthorization(USER, "monster", "oscar", READ);
    createGrantAuthorization(USER, "ruecker", "oscar", READ);
    try {
        processEngineConfiguration.setAuthorizationEnabled(true);
        identityService.setAuthenticatedUserId("oscar");
        testUserPaging(identityService);
    } finally {
        processEngineConfiguration.setAuthorizationEnabled(false);
        identityService.clearAuthentication();
        for (Authorization authorization : authorizationService.createAuthorizationQuery().list()) {
            authorizationService.deleteAuthorization(authorization.getId());
        }
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization)

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