use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testRevokeAuthPermissions.
public void testRevokeAuthPermissions() {
AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_REVOKE);
assertFalse(authorization.isPermissionRevoked(ALL));
List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertEquals(0, perms.size());
authorization.removePermission(READ);
perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(READ));
assertTrue(perms.contains(ALL));
assertEquals(2, perms.size());
try {
authorization.isPermissionGranted(READ);
fail("Exception expected");
} catch (IllegalStateException e) {
assertTextPresent("ENGINE-03026 Method 'isPermissionGranted' cannot be used for authorization with type 'REVOKE'.", e.getMessage());
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity in project camunda-bpm-platform by camunda.
the class AuthorizationServiceTest method testGrantAuthPermissions.
public void testGrantAuthPermissions() {
AuthorizationEntity authorization = new AuthorizationEntity(AUTH_TYPE_GRANT);
assertFalse(authorization.isPermissionGranted(ALL));
assertTrue(authorization.isPermissionGranted(NONE));
List<Permission> perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(NONE));
assertEquals(1, perms.size());
authorization.addPermission(READ);
perms = Arrays.asList(authorization.getPermissions(Permissions.values()));
assertTrue(perms.contains(NONE));
assertTrue(perms.contains(READ));
assertEquals(2, perms.size());
assertTrue(authorization.isPermissionGranted(READ));
// (none is always granted => you are always authorized to do nothing)
assertTrue(authorization.isPermissionGranted(NONE));
try {
authorization.isPermissionRevoked(READ);
fail("Exception expected");
} catch (IllegalStateException e) {
assertTextPresent("ENGINE-03026 Method 'isPermissionRevoked' cannot be used for authorization with type 'GRANT'.", e.getMessage());
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity in project camunda-bpm-platform by camunda.
the class AuthorizationServiceAuthorizationsTest method testCreateAuthorization.
public void testCreateAuthorization() {
// add base permission which allows nobody to create authorizations
Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
basePerms.setResource(AUTHORIZATION);
basePerms.setResourceId(ANY);
// add all then remove 'create'
basePerms.addPermission(ALL);
basePerms.removePermission(CREATE);
authorizationService.saveAuthorization(basePerms);
// now enable authorizations:
processEngineConfiguration.setAuthorizationEnabled(true);
identityService.setAuthenticatedUserId(jonny2);
try {
// we cannot create another authorization
authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL);
fail("exception expected");
} catch (AuthorizationException e) {
assertEquals(1, e.getMissingAuthorizations().size());
MissingAuthorization info = e.getMissingAuthorizations().get(0);
assertEquals(jonny2, e.getUserId());
assertExceptionInfo(CREATE.getName(), AUTHORIZATION.resourceName(), null, info);
}
// circumvent auth check to get new transient object
Authorization authorization = new AuthorizationEntity(AUTH_TYPE_REVOKE);
authorization.setUserId("someUserId");
authorization.setResource(Resources.APPLICATION);
try {
authorizationService.saveAuthorization(authorization);
fail("exception expected");
} catch (AuthorizationException e) {
assertEquals(1, e.getMissingAuthorizations().size());
MissingAuthorization info = e.getMissingAuthorizations().get(0);
assertEquals(jonny2, e.getUserId());
assertExceptionInfo(CREATE.getName(), AUTHORIZATION.resourceName(), null, info);
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity in project camunda-bpm-platform by camunda.
the class DeleteAuthorizationCmd method execute.
public Void execute(CommandContext commandContext) {
final AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
AuthorizationEntity authorization = (AuthorizationEntity) new AuthorizationQueryImpl().authorizationId(authorizationId).singleResult();
ensureNotNull("Authorization for Id '" + authorizationId + "' does not exist", "authorization", authorization);
authorizationManager.delete(authorization);
return null;
}
Aggregations