Search in sources :

Example 1 with UserAndGroups

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

the class FileUserGroupProvider method getUserAndGroups.

@Override
public UserAndGroups getUserAndGroups(final String identity) throws AuthorizationAccessException {
    final UserGroupHolder holder = userGroupHolder.get();
    final User user = holder.getUser(identity);
    final Set<Group> groups = holder.getGroups(identity);
    return new UserAndGroups() {

        @Override
        public User getUser() {
            return user;
        }

        @Override
        public Set<Group> getGroups() {
            return groups;
        }
    };
}
Also used : UserAndGroups(org.apache.nifi.registry.security.authorization.UserAndGroups) Group(org.apache.nifi.registry.security.authorization.Group) User(org.apache.nifi.registry.security.authorization.User)

Example 2 with UserAndGroups

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

the class LdapUserGroupProviderTest method testSearchUsersWithGroupingAndGroupName.

@Test
public void testSearchUsersWithGroupingAndGroupName() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(USER_SEARCH_BASE, null);
    when(configurationContext.getProperty(PROP_USER_IDENTITY_ATTRIBUTE)).thenReturn(new StandardPropertyValue("uid"));
    // using description in lieu of memberof
    when(configurationContext.getProperty(PROP_USER_GROUP_ATTRIBUTE)).thenReturn(new StandardPropertyValue("description"));
    when(configurationContext.getProperty(PROP_GROUP_NAME_ATTRIBUTE)).thenReturn(new StandardPropertyValue("cn"));
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertEquals(8, ldapUserGroupProvider.getUsers().size());
    assertEquals(2, ldapUserGroupProvider.getGroups().size());
    final UserAndGroups userAndGroups = ldapUserGroupProvider.getUserAndGroups("user4");
    assertNotNull(userAndGroups.getUser());
    assertEquals(1, userAndGroups.getGroups().size());
    assertEquals("team1", userAndGroups.getGroups().iterator().next().getName());
}
Also used : UserAndGroups(org.apache.nifi.registry.security.authorization.UserAndGroups) StandardPropertyValue(org.apache.nifi.registry.util.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 3 with UserAndGroups

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

the class LdapUserGroupProviderTest method testSearchUsersWithGroupingNoGroupName.

@Test
public void testSearchUsersWithGroupingNoGroupName() throws Exception {
    final AuthorizerConfigurationContext configurationContext = getBaseConfiguration(USER_SEARCH_BASE, null);
    when(configurationContext.getProperty(PROP_USER_IDENTITY_ATTRIBUTE)).thenReturn(new StandardPropertyValue("uid"));
    // using description in lieu of memberof
    when(configurationContext.getProperty(PROP_USER_GROUP_ATTRIBUTE)).thenReturn(new StandardPropertyValue("description"));
    ldapUserGroupProvider.onConfigured(configurationContext);
    assertEquals(8, ldapUserGroupProvider.getUsers().size());
    assertEquals(2, ldapUserGroupProvider.getGroups().size());
    final UserAndGroups userAndGroups = ldapUserGroupProvider.getUserAndGroups("user4");
    assertNotNull(userAndGroups.getUser());
    assertEquals(1, userAndGroups.getGroups().size());
    assertEquals("cn=team1,ou=groups,o=nifi", userAndGroups.getGroups().iterator().next().getName());
}
Also used : UserAndGroups(org.apache.nifi.registry.security.authorization.UserAndGroups) StandardPropertyValue(org.apache.nifi.registry.util.StandardPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext) Test(org.junit.Test)

Example 4 with UserAndGroups

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

the class IdentityAuthenticationProvider method getUserGroups.

private static Set<String> getUserGroups(final Authorizer authorizer, final String userIdentity) {
    if (authorizer instanceof ManagedAuthorizer) {
        final ManagedAuthorizer managedAuthorizer = (ManagedAuthorizer) authorizer;
        final UserGroupProvider userGroupProvider = managedAuthorizer.getAccessPolicyProvider().getUserGroupProvider();
        final UserAndGroups userAndGroups = userGroupProvider.getUserAndGroups(userIdentity);
        final Set<Group> userGroups = userAndGroups.getGroups();
        if (userGroups == null || userGroups.isEmpty()) {
            return Collections.emptySet();
        } else {
            return userAndGroups.getGroups().stream().map(Group::getName).collect(Collectors.toSet());
        }
    } else {
        return null;
    }
}
Also used : UserAndGroups(org.apache.nifi.registry.security.authorization.UserAndGroups) Group(org.apache.nifi.registry.security.authorization.Group) ManagedAuthorizer(org.apache.nifi.registry.security.authorization.ManagedAuthorizer) UserGroupProvider(org.apache.nifi.registry.security.authorization.UserGroupProvider)

Aggregations

UserAndGroups (org.apache.nifi.registry.security.authorization.UserAndGroups)4 AuthorizerConfigurationContext (org.apache.nifi.registry.security.authorization.AuthorizerConfigurationContext)2 Group (org.apache.nifi.registry.security.authorization.Group)2 StandardPropertyValue (org.apache.nifi.registry.util.StandardPropertyValue)2 Test (org.junit.Test)2 ManagedAuthorizer (org.apache.nifi.registry.security.authorization.ManagedAuthorizer)1 User (org.apache.nifi.registry.security.authorization.User)1 UserGroupProvider (org.apache.nifi.registry.security.authorization.UserGroupProvider)1