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));
}
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());
}
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
}
}
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
}
}
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);
}
}
Aggregations