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