Search in sources :

Example 6 with UserManagementAuthoritiesPopulator

use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.

the class LdapManagerTest method testAuthenticationProviderCreated.

@Test
public void testAuthenticationProviderCreated() throws Exception {
    ConfigurationModel configurationModel = createConfigurationModel();
    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);
    assertNotNull(ldapManager.getAuthenticationProvider());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 7 with UserManagementAuthoritiesPopulator

use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.

the class LdapManagerTest method testExceptionOnContext.

@Test
public void testExceptionOnContext() {
    final String managerDN = "";
    final String managerPassword = "";
    ConfigurationModel configurationModel = createConfigurationModel();
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_SERVER).get().setFieldValue(null);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_DN).get().setFieldValue(managerDN);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_PWD).get().setFieldValue(managerPassword);
    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
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 8 with UserManagementAuthoritiesPopulator

use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.

the class LdapManagerTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    ConfigurationModel configurationModel = createConfigurationModel();
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    FieldUtility updatedProperties = ldapManager.getCurrentConfiguration();
    assertEquals(DEFAULT_ENABLED, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_ENABLED).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_SERVER, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_SERVER).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_MANAGER_DN, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_DN).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_MANAGER_PASSWORD, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_PWD).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_AUTHENTICATION_TYPE, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_REFERRAL, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_REFERRAL).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_USER_SEARCH_BASE, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_BASE).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_USER_SEARCH_FILTER, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_FILTER).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_USER_DN_PATTERNS, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_USER_DN_PATTERNS).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_USER_ATTRIBUTES, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_USER_ATTRIBUTES).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_GROUP_SEARCH_BASE, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_GROUP_SEARCH_BASE).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_GROUP_SEARCH_FILTER, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_GROUP_SEARCH_FILTER).flatMap(field -> field.getFieldValue()).orElse(null));
    assertEquals(DEFAULT_GROUP_ROLE_ATTRIBUTE, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_GROUP_ROLE_ATTRIBUTE).flatMap(field -> field.getFieldValue()).orElse(null));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 9 with UserManagementAuthoritiesPopulator

use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.

the class LdapManagerTest method testIsEnabled.

@Test
public void testIsEnabled() {
    ConfigurationModel configurationModel = createConfigurationModel();
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    assertTrue(ldapManager.isLdapEnabled());
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_ENABLED).ifPresent(field -> field.setFieldValue("false"));
    assertFalse(ldapManager.isLdapEnabled());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 10 with UserManagementAuthoritiesPopulator

use of com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator in project hub-alert by blackducksoftware.

the class MappingLdapAuthoritiesPopulatorTest method testExceptionGroupMembershipRoles.

@Test
public void testExceptionGroupMembershipRoles() {
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    ContextSource contextSource = Mockito.mock(ContextSource.class);
    SpringSecurityLdapTemplate ldapTemplate = new SpringSecurityLdapTemplate(contextSource) {

        @Override
        public Set<Map<String, List<String>>> searchForMultipleAttributeValues(String base, String filter, Object[] params, String[] attributeNames) {
            throw new JUnitException("Group Membership Roles Test Exception");
        }
    };
    MappingLdapAuthoritiesPopulator ldapAuthoritiesPopulator = new MappingLdapAuthoritiesPopulator(contextSource, "searchbase={0}", authoritiesPopulator) {

        @Override
        protected SpringSecurityLdapTemplate getLdapTemplate() {
            return ldapTemplate;
        }
    };
    Set<GrantedAuthority> actualRoles = ldapAuthoritiesPopulator.getGroupMembershipRoles(null, null);
    assertTrue(actualRoles.isEmpty());
}
Also used : SpringSecurityLdapTemplate(org.springframework.security.ldap.SpringSecurityLdapTemplate) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ContextSource(org.springframework.ldap.core.ContextSource) JUnitException(org.junit.platform.commons.JUnitException) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

UserManagementAuthoritiesPopulator (com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator)11 Test (org.junit.jupiter.api.Test)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 AuthenticationDescriptorKey (com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey)8 DefaultConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor)7 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)7 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)3 ContextSource (org.springframework.ldap.core.ContextSource)3 GrantedAuthority (org.springframework.security.core.GrantedAuthority)3 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)3 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)2 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 UserAccessor (com.synopsys.integration.alert.common.persistence.accessor.UserAccessor)1 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)1 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)1 Map (java.util.Map)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 JUnitException (org.junit.platform.commons.JUnitException)1 DirContextOperations (org.springframework.ldap.core.DirContextOperations)1