Search in sources :

Example 36 with Permissions

use of org.apache.nifi.registry.authorization.Permissions in project nifi-registry by apache.

the class UnsecuredNiFiRegistryClientIT method testGetAccessStatus.

@Test
public void testGetAccessStatus() throws IOException, NiFiRegistryException {
    final UserClient userClient = client.getUserClient();
    final CurrentUser currentUser = userClient.getAccessStatus();
    Assert.assertEquals("anonymous", currentUser.getIdentity());
    Assert.assertTrue(currentUser.isAnonymous());
    Assert.assertNotNull(currentUser.getResourcePermissions());
    Permissions fullAccess = new Permissions().withCanRead(true).withCanWrite(true).withCanDelete(true);
    Assert.assertEquals(fullAccess, currentUser.getResourcePermissions().getAnyTopLevelResource());
    Assert.assertEquals(fullAccess, currentUser.getResourcePermissions().getBuckets());
    Assert.assertEquals(fullAccess, currentUser.getResourcePermissions().getTenants());
    Assert.assertEquals(fullAccess, currentUser.getResourcePermissions().getPolicies());
    Assert.assertEquals(fullAccess, currentUser.getResourcePermissions().getProxy());
}
Also used : UserClient(org.apache.nifi.registry.client.UserClient) CurrentUser(org.apache.nifi.registry.authorization.CurrentUser) Permissions(org.apache.nifi.registry.authorization.Permissions) Test(org.junit.Test)

Example 37 with Permissions

use of org.apache.nifi.registry.authorization.Permissions in project nifi-registry by apache.

the class AuthorizationService method getPermissionsForResource.

private Permissions getPermissionsForResource(String tenantIdentifier, org.apache.nifi.registry.security.authorization.Resource resource) {
    Permissions permissions = new Permissions();
    permissions.setCanRead(checkTenantBelongsToPolicy(tenantIdentifier, resource, RequestAction.READ));
    permissions.setCanWrite(checkTenantBelongsToPolicy(tenantIdentifier, resource, RequestAction.WRITE));
    permissions.setCanDelete(checkTenantBelongsToPolicy(tenantIdentifier, resource, RequestAction.DELETE));
    return permissions;
}
Also used : Permissions(org.apache.nifi.registry.authorization.Permissions) ResourcePermissions(org.apache.nifi.registry.authorization.ResourcePermissions)

Example 38 with Permissions

use of org.apache.nifi.registry.authorization.Permissions in project nifi-registry by apache.

the class AuthorizationService method getPermissionsForResource.

public Permissions getPermissionsForResource(Authorizable authorizableResource, Permissions knownParentAuthorizablePermissions) {
    if (knownParentAuthorizablePermissions == null) {
        return getPermissionsForResource(authorizableResource);
    }
    final Permissions permissions = new Permissions(knownParentAuthorizablePermissions);
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (!permissions.getCanRead()) {
        permissions.setCanRead(authorizableResource.isAuthorized(authorizer, RequestAction.READ, user));
    }
    if (!permissions.getCanWrite()) {
        permissions.setCanWrite(authorizableResource.isAuthorized(authorizer, RequestAction.WRITE, user));
    }
    if (!permissions.getCanDelete()) {
        permissions.setCanDelete(authorizableResource.isAuthorized(authorizer, RequestAction.DELETE, user));
    }
    return permissions;
}
Also used : NiFiUser(org.apache.nifi.registry.security.authorization.user.NiFiUser) Permissions(org.apache.nifi.registry.authorization.Permissions) ResourcePermissions(org.apache.nifi.registry.authorization.ResourcePermissions)

Example 39 with Permissions

use of org.apache.nifi.registry.authorization.Permissions in project nifi-registry by apache.

the class AuthorizationService method getPermissionsForResource.

public Permissions getPermissionsForResource(Authorizable authorizableResource) {
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    final Permissions permissions = new Permissions();
    permissions.setCanRead(authorizableResource.isAuthorized(authorizer, RequestAction.READ, user));
    permissions.setCanWrite(authorizableResource.isAuthorized(authorizer, RequestAction.WRITE, user));
    permissions.setCanDelete(authorizableResource.isAuthorized(authorizer, RequestAction.DELETE, user));
    return permissions;
}
Also used : NiFiUser(org.apache.nifi.registry.security.authorization.user.NiFiUser) Permissions(org.apache.nifi.registry.authorization.Permissions) ResourcePermissions(org.apache.nifi.registry.authorization.ResourcePermissions)

Example 40 with Permissions

use of org.apache.nifi.registry.authorization.Permissions in project nifi-registry by apache.

the class PermissionsService method populateItemPermissions.

public void populateItemPermissions(final Iterable<? extends BucketItem> bucketItems) {
    Permissions topLevelBucketPermissions = authorizationService.getPermissionsForResource(authorizableLookup.getBucketsAuthorizable());
    bucketItems.forEach(i -> populateItemPermissions(i, topLevelBucketPermissions));
}
Also used : Permissions(org.apache.nifi.registry.authorization.Permissions)

Aggregations

Permissions (org.apache.nifi.registry.authorization.Permissions)43 Response (javax.ws.rs.core.Response)31 Sets (com.google.common.collect.Sets)30 IOException (java.io.IOException)30 StandardCharsets (java.nio.charset.StandardCharsets)30 ArrayList (java.util.ArrayList)30 Arrays (java.util.Arrays)30 Collection (java.util.Collection)30 Collections (java.util.Collections)30 Comparator (java.util.Comparator)30 Date (java.util.Date)30 HashMap (java.util.HashMap)30 HashSet (java.util.HashSet)30 LinkedHashMap (java.util.LinkedHashMap)30 LinkedHashSet (java.util.LinkedHashSet)30 List (java.util.List)30 ListIterator (java.util.ListIterator)30 Map (java.util.Map)30 Objects (java.util.Objects)30 Optional (java.util.Optional)30