Search in sources :

Example 1 with TestResource

use of org.camunda.bpm.engine.test.api.identity.TestResource in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method createAuthenticationData.

private void createAuthenticationData() {
    IdentityService identityService = engineRule.getIdentityService();
    Group group = identityService.newGroup("group");
    identityService.saveGroup(group);
    User user = identityService.newUser("user");
    User user2 = identityService.newUser("user2");
    identityService.saveUser(user);
    identityService.saveUser(user2);
    Tenant tenant = identityService.newTenant("tenant");
    identityService.saveTenant(tenant);
    Tenant tenant2 = identityService.newTenant("tenant2");
    identityService.saveTenant(tenant2);
    identityService.createMembership("user", "group");
    identityService.createTenantUserMembership("tenant", "user");
    identityService.createTenantUserMembership("tenant2", "user2");
    TestResource resource1 = new TestResource("resource1", 100);
    // create global authorization which grants all permissions to all users (on resource1):
    AuthorizationService authorizationService = engineRule.getAuthorizationService();
    Authorization globalAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
    globalAuth.setResource(resource1);
    globalAuth.setResourceId(ANY);
    globalAuth.addPermission(ALL);
    authorizationService.saveAuthorization(globalAuth);
    // grant user read auth on resource2
    TestResource resource2 = new TestResource("resource2", 200);
    Authorization userGrant = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT);
    userGrant.setUserId("user");
    userGrant.setResource(resource2);
    userGrant.setResourceId(ANY);
    userGrant.addPermission(READ);
    authorizationService.saveAuthorization(userGrant);
    identityService.setAuthenticatedUserId("user");
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) Authorization(org.camunda.bpm.engine.authorization.Authorization) Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) Tenant(org.camunda.bpm.engine.identity.Tenant) AuthorizationService(org.camunda.bpm.engine.AuthorizationService) TestResource(org.camunda.bpm.engine.test.api.identity.TestResource)

Aggregations

AuthorizationService (org.camunda.bpm.engine.AuthorizationService)1 IdentityService (org.camunda.bpm.engine.IdentityService)1 Authorization (org.camunda.bpm.engine.authorization.Authorization)1 Group (org.camunda.bpm.engine.identity.Group)1 Tenant (org.camunda.bpm.engine.identity.Tenant)1 User (org.camunda.bpm.engine.identity.User)1 TestResource (org.camunda.bpm.engine.test.api.identity.TestResource)1