Search in sources :

Example 11 with Permission

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

the class PermissionConverter method getNamesForPermissions.

public static String[] getNamesForPermissions(Authorization authorization, Permission[] permissions) {
    int type = authorization.getAuthorizationType();
    // special case all permissions are granted
    if ((type == Authorization.AUTH_TYPE_GLOBAL || type == Authorization.AUTH_TYPE_GRANT) && authorization.isEveryPermissionGranted()) {
        return new String[] { Permissions.ALL.getName() };
    }
    // special case all permissions are revoked
    if (type == Authorization.AUTH_TYPE_REVOKE && authorization.isEveryPermissionRevoked()) {
        return new String[] { Permissions.ALL.getName() };
    }
    List<String> names = new ArrayList<String>();
    for (Permission permission : permissions) {
        String name = permission.getName();
        // filter NONE and ALL from permissions array
        if (!name.equals(Permissions.NONE.getName()) && !name.equals(Permissions.ALL.getName())) {
            names.add(name);
        }
    }
    return names.toArray(new String[names.size()]);
}
Also used : ArrayList(java.util.ArrayList) Permission(org.camunda.bpm.engine.authorization.Permission)

Example 12 with Permission

use of org.camunda.bpm.engine.authorization.Permission 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 13 with Permission

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

the class AuthorizationScenarioInstance method assertAuthorizationException.

public void assertAuthorizationException(AuthorizationException e) {
    if (!missingAuthorizations.isEmpty() && e != null) {
        String message = e.getMessage();
        String assertionFailureMessage = describeScenarioFailure("Expected an authorization exception but the message was wrong: " + e.getMessage());
        List<MissingAuthorization> actualMissingAuthorizations = new ArrayList<MissingAuthorization>(e.getMissingAuthorizations());
        List<MissingAuthorization> expectedMissingAuthorizations = MissingAuthorizationMatcher.asMissingAuthorizations(missingAuthorizations);
        Assert.assertThat(actualMissingAuthorizations, containsInAnyOrder(MissingAuthorizationMatcher.asMatchers(expectedMissingAuthorizations)));
        for (Authorization missingAuthorization : missingAuthorizations) {
            Assert.assertTrue(assertionFailureMessage, message.contains(missingAuthorization.getUserId()));
            Assert.assertEquals(missingAuthorization.getUserId(), e.getUserId());
            for (Permission permission : missingAuthorization.getPermissions(Permissions.values())) {
                if (permission != Permissions.NONE) {
                    Assert.assertTrue(assertionFailureMessage, message.contains(permission.getName()));
                }
            }
            if (!Authorization.ANY.equals(missingAuthorization.getResourceId())) {
                // missing ANY authorizations are not explicitly represented in the error message
                Assert.assertTrue(assertionFailureMessage, message.contains(missingAuthorization.getResourceId()));
            }
            Resource resource = AuthorizationTestUtil.getResourceByType(missingAuthorization.getResourceType());
            Assert.assertTrue(assertionFailureMessage, message.contains(resource.resourceName()));
        }
    } else if (missingAuthorizations.isEmpty() && e == null) {
    // nothing to do
    } else {
        if (e != null) {
            Assert.fail(describeScenarioFailure("Expected no authorization exception but got one: " + e.getMessage()));
        } else {
            Assert.fail(describeScenarioFailure("Expected failure due to missing authorizations but code under test was successful"));
        }
    }
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) MissingAuthorization(org.camunda.bpm.engine.authorization.MissingAuthorization) ArrayList(java.util.ArrayList) Permission(org.camunda.bpm.engine.authorization.Permission) Resource(org.camunda.bpm.engine.authorization.Resource)

Example 14 with Permission

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

the class AuthorizationSpec method toString.

public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("[Resource: ");
    sb.append(resource);
    sb.append(", Resource Id: ");
    sb.append(resourceId);
    sb.append(", Type: ");
    sb.append(type);
    sb.append(", User Id: ");
    sb.append(userId);
    sb.append(", Permissions: [");
    for (Permission permission : permissions) {
        sb.append(permission.getName());
        sb.append(", ");
    }
    sb.append("]]");
    return sb.toString();
}
Also used : Permission(org.camunda.bpm.engine.authorization.Permission)

Example 15 with Permission

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

the class AuthorizationTestBaseRule method createGrantAuthorization.

public void createGrantAuthorization(Resource resource, String resourceId, String userId, Permission... permissions) {
    Authorization authorization = createAuthorization(Authorization.AUTH_TYPE_GRANT, resource, resourceId);
    authorization.setUserId(userId);
    for (Permission permission : permissions) {
        authorization.addPermission(permission);
    }
    engineRule.getAuthorizationService().saveAuthorization(authorization);
    manageAuthorization(authorization);
}
Also used : Authorization(org.camunda.bpm.engine.authorization.Authorization) Permission(org.camunda.bpm.engine.authorization.Permission)

Aggregations

Permission (org.camunda.bpm.engine.authorization.Permission)20 Authorization (org.camunda.bpm.engine.authorization.Authorization)12 AuthorizationEntity (org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity)4 ArrayList (java.util.ArrayList)2 AuthorizationService (org.camunda.bpm.engine.AuthorizationService)2 MissingAuthorization (org.camunda.bpm.engine.authorization.MissingAuthorization)2 Resource (org.camunda.bpm.engine.authorization.Resource)2