Search in sources :

Example 1 with AccessPolicySummary

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

the class AuthorizationService method accessPolicyToSummaryDTO.

private AccessPolicySummary accessPolicyToSummaryDTO(final org.apache.nifi.registry.security.authorization.AccessPolicy accessPolicy) {
    if (accessPolicy == null) {
        return null;
    }
    Boolean isConfigurable = AuthorizerCapabilityDetection.isAccessPolicyConfigurable(authorizer, accessPolicy);
    final AccessPolicySummary accessPolicySummaryDTO = new AccessPolicySummary();
    accessPolicySummaryDTO.setIdentifier(accessPolicy.getIdentifier());
    accessPolicySummaryDTO.setAction(accessPolicy.getAction().toString());
    accessPolicySummaryDTO.setResource(accessPolicy.getResource());
    accessPolicySummaryDTO.setConfigurable(isConfigurable);
    return accessPolicySummaryDTO;
}
Also used : AccessPolicySummary(org.apache.nifi.registry.authorization.AccessPolicySummary)

Example 2 with AccessPolicySummary

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

the class AuthorizationService method userToDTO.

private User userToDTO(final org.apache.nifi.registry.security.authorization.User user) {
    if (user == null) {
        return null;
    }
    String userIdentifier = user.getIdentifier();
    Collection<Tenant> groupsContainingUser = userGroupProvider.getGroups().stream().filter(group -> group.getUsers().contains(userIdentifier)).map(this::tenantToDTO).collect(Collectors.toList());
    Collection<AccessPolicySummary> accessPolicySummaries = getAccessPolicySummariesForUser(userIdentifier);
    User userDTO = new User(user.getIdentifier(), user.getIdentity());
    userDTO.setConfigurable(AuthorizerCapabilityDetection.isUserConfigurable(authorizer, user));
    userDTO.setResourcePermissions(getTopLevelPermissions(userDTO.getIdentifier()));
    userDTO.addUserGroups(groupsContainingUser);
    userDTO.addAccessPolicies(accessPolicySummaries);
    return userDTO;
}
Also used : Tenant(org.apache.nifi.registry.authorization.Tenant) User(org.apache.nifi.registry.authorization.User) NiFiUser(org.apache.nifi.registry.security.authorization.user.NiFiUser) CurrentUser(org.apache.nifi.registry.authorization.CurrentUser) AccessPolicySummary(org.apache.nifi.registry.authorization.AccessPolicySummary)

Example 3 with AccessPolicySummary

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

the class SecureLdapIT method createAccessPoliciesSnapshot.

private List<AccessPolicy> createAccessPoliciesSnapshot() {
    final AccessPolicySummary[] policySummaries = client.target(createURL("policies")).request().header("Authorization", "Bearer " + adminAuthToken).get(AccessPolicySummary[].class);
    final List<AccessPolicy> policies = new ArrayList<>(policySummaries.length);
    for (AccessPolicySummary s : policySummaries) {
        AccessPolicy policy = client.target(createURL("policies/" + s.getIdentifier())).request().header("Authorization", "Bearer " + adminAuthToken).get(AccessPolicy.class);
        policies.add(policy);
    }
    return policies;
}
Also used : AccessPolicySummary(org.apache.nifi.registry.authorization.AccessPolicySummary) ArrayList(java.util.ArrayList) AccessPolicy(org.apache.nifi.registry.authorization.AccessPolicy)

Example 4 with AccessPolicySummary

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

the class SecureLdapIT method getPolicyByResourceAction.

/**
 * A helper method to lookup access policies
 *
 * @return A string containing the identifier of the policy, or null if the policy identity is not found.
 */
private AccessPolicy getPolicyByResourceAction(String action, String resource) {
    final AccessPolicySummary[] policies = client.target(createURL("policies")).request().header("Authorization", "Bearer " + adminAuthToken).get(AccessPolicySummary[].class);
    final AccessPolicySummary matchedPolicy = Arrays.stream(policies).filter(p -> p.getAction().equalsIgnoreCase(action) && p.getResource().equalsIgnoreCase(resource)).findFirst().orElse(null);
    if (matchedPolicy == null) {
        return null;
    }
    String policyId = matchedPolicy.getIdentifier();
    final AccessPolicy policy = client.target(createURL("policies/" + policyId)).request().header("Authorization", "Bearer " + adminAuthToken).get(AccessPolicy.class);
    return policy;
}
Also used : AccessPolicySummary(org.apache.nifi.registry.authorization.AccessPolicySummary) AccessPolicy(org.apache.nifi.registry.authorization.AccessPolicy)

Example 5 with AccessPolicySummary

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

the class AuthorizationService method userGroupToDTO.

private UserGroup userGroupToDTO(final org.apache.nifi.registry.security.authorization.Group userGroup) {
    if (userGroup == null) {
        return null;
    }
    Collection<Tenant> userTenants = userGroup.getUsers() != null ? userGroup.getUsers().stream().map(this::tenantIdToDTO).collect(Collectors.toSet()) : null;
    Collection<AccessPolicySummary> accessPolicySummaries = getAccessPolicySummariesForUserGroup(userGroup.getIdentifier());
    UserGroup userGroupDTO = new UserGroup(userGroup.getIdentifier(), userGroup.getName());
    userGroupDTO.setConfigurable(AuthorizerCapabilityDetection.isGroupConfigurable(authorizer, userGroup));
    userGroupDTO.setResourcePermissions(getTopLevelPermissions(userGroupDTO.getIdentifier()));
    userGroupDTO.addUsers(userTenants);
    userGroupDTO.addAccessPolicies(accessPolicySummaries);
    return userGroupDTO;
}
Also used : Tenant(org.apache.nifi.registry.authorization.Tenant) AccessPolicySummary(org.apache.nifi.registry.authorization.AccessPolicySummary) UserGroup(org.apache.nifi.registry.authorization.UserGroup)

Aggregations

AccessPolicySummary (org.apache.nifi.registry.authorization.AccessPolicySummary)5 AccessPolicy (org.apache.nifi.registry.authorization.AccessPolicy)2 Tenant (org.apache.nifi.registry.authorization.Tenant)2 ArrayList (java.util.ArrayList)1 CurrentUser (org.apache.nifi.registry.authorization.CurrentUser)1 User (org.apache.nifi.registry.authorization.User)1 UserGroup (org.apache.nifi.registry.authorization.UserGroup)1 NiFiUser (org.apache.nifi.registry.security.authorization.user.NiFiUser)1