Search in sources :

Example 11 with UserManagementAuthoritiesPopulator

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

the class UserDetailsServiceTest method initializeAuthoritiesPopulator.

@BeforeEach
public void initializeAuthoritiesPopulator() {
    Set<UserRoleModel> roles = Arrays.stream(VALID_DB_ROLES).map(UserRoleModel::of).collect(Collectors.toSet());
    UserModel userModel = UserModel.newUser(USER_NAME, "password", EMAIL, AuthenticationType.SAML, roles, true);
    AuthenticationDescriptorKey key = new AuthenticationDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationModel configuration = Mockito.mock(ConfigurationModel.class);
    UserAccessor userAccessor = Mockito.mock(UserAccessor.class);
    Mockito.when(configuration.getField(Mockito.anyString())).thenReturn(Optional.empty());
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.eq(key))).thenReturn(List.of(configuration));
    Mockito.when(userAccessor.getUser(Mockito.anyString())).thenReturn(Optional.of(userModel));
    authoritiesPopulator = new UserManagementAuthoritiesPopulator(key, configurationModelConfigurationAccessor, userAccessor);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) UserAccessor(com.synopsys.integration.alert.common.persistence.accessor.UserAccessor) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

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