use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.
the class MappingLdapAuthoritiesPopulatorTest method testEmptyAdditionalRoles.
@Test
public void testEmptyAdditionalRoles() {
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
Mockito.doReturn(Set.of(new SimpleGrantedAuthority(DefaultUserRole.ALERT_USER.name()))).when(authoritiesPopulator).addAdditionalRoles(Mockito.anyString(), Mockito.anySet());
ContextSource contextSource = Mockito.mock(ContextSource.class);
DirContextOperations user = Mockito.mock(DirContextOperations.class);
MappingLdapAuthoritiesPopulator ldapAuthoritiesPopulator = new MappingLdapAuthoritiesPopulator(contextSource, null, authoritiesPopulator);
Set<GrantedAuthority> actualRoles = ldapAuthoritiesPopulator.getAdditionalRoles(user, "");
boolean hasAlertUserRole = actualRoles.stream().map(GrantedAuthority::getAuthority).allMatch(roleName -> DefaultUserRole.ALERT_USER.name().equals(roleName));
Mockito.verify(authoritiesPopulator).addAdditionalRoles(Mockito.anyString(), Mockito.anySet());
assertFalse(actualRoles.isEmpty());
assertTrue(hasAlertUserRole);
}
use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.
the class MappingLdapAuthoritiesPopulatorTest method testEmptyGroupSearchBase.
@Test
public void testEmptyGroupSearchBase() {
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
ContextSource contextSource = Mockito.mock(ContextSource.class);
MappingLdapAuthoritiesPopulator ldapAuthoritiesPopulator = new MappingLdapAuthoritiesPopulator(contextSource, null, authoritiesPopulator);
Set<GrantedAuthority> actualRoles = ldapAuthoritiesPopulator.getGroupMembershipRoles("", "");
assertTrue(actualRoles.isEmpty());
}
use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.
the class LdapManagerTest method testAuthenticationTypeDigest.
@Test
public void testAuthenticationTypeDigest() throws Exception {
final String authenticationType = "digest";
ConfigurationModel configurationModel = createConfigurationModel();
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).get().setFieldValue(authenticationType);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
ldapManager.getAuthenticationProvider();
FieldUtility updatedProperties = ldapManager.getCurrentConfiguration();
assertEquals(authenticationType, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
}
use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.
the class LdapManagerTest method testAuthenticationTypeSimple.
@Test
public void testAuthenticationTypeSimple() throws Exception {
final String authenticationType = "simple";
ConfigurationModel configurationModel = createConfigurationModel();
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).get().setFieldValue(authenticationType);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
ldapManager.getAuthenticationProvider();
FieldUtility updatedProperties = ldapManager.getCurrentConfiguration();
assertEquals(authenticationType, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
}
use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.
the class LdapManagerTest method testExceptionOnAuthenticator.
@Test
public void testExceptionOnAuthenticator() {
final String userSearchBase = "";
final String userSearchFilter = "";
final String userDNPatterns = "";
ConfigurationModel configurationModel = createConfigurationModel();
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_BASE).get().setFieldValue(userSearchBase);
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_FILTER).get().setFieldValue(userSearchFilter);
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_DN_PATTERNS).get().setFieldValue(userDNPatterns);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
try {
ldapManager.getAuthenticationProvider();
fail();
} catch (AlertConfigurationException ex) {
// exception occurred
}
}
Aggregations