fix tests
All checks were successful
Builder / Build-Project (push) Successful in 2m11s

This commit is contained in:
alex 2024-09-23 22:37:32 -04:00
parent ff2db18f0a
commit 16a9a91790
3 changed files with 10 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.EmployeeService;
import com.primefactorsolutions.views.LoginView; import com.primefactorsolutions.views.LoginView;
import com.vaadin.flow.spring.security.VaadinWebSecurity; import com.vaadin.flow.spring.security.VaadinWebSecurity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@ -24,6 +25,8 @@ import java.util.Collection;
@EnableWebSecurity @EnableWebSecurity
@Configuration @Configuration
public class SecurityConfig extends VaadinWebSecurity { public class SecurityConfig extends VaadinWebSecurity {
@Value("${spring.ldap.url}")
private String ldapUrl;
@Override @Override
protected void configure(final HttpSecurity http) throws Exception { protected void configure(final HttpSecurity http) throws Exception {
@ -47,10 +50,10 @@ public class SecurityConfig extends VaadinWebSecurity {
@Bean @Bean
public AuthenticationManager authenticationManager(final UserDetailsContextMapper userDetailsContextMapper) { public AuthenticationManager authenticationManager(final UserDetailsContextMapper userDetailsContextMapper) {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( final DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
"ldap://localhost:8389/dc=primefactorsolutions,dc=com"); String.format("%s/dc=primefactorsolutions,dc=com", ldapUrl));
contextSource.setCacheEnvironmentProperties(false); contextSource.setCacheEnvironmentProperties(false);
LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource); final LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
factory.setUserDnPatterns("uid={0},ou=users"); factory.setUserDnPatterns("uid={0},ou=users");
factory.setUserDetailsContextMapper(userDetailsContextMapper); factory.setUserDetailsContextMapper(userDetailsContextMapper);

View File

@ -0,0 +1,2 @@
spring.ldap.url=ldap://localhost:8391
spring.ldap.embedded.port=8391

View File

@ -14,21 +14,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import com.github.mvysny.kaributesting.v10.MockVaadin;
import com.github.mvysny.kaributesting.v10.Routes; import com.github.mvysny.kaributesting.v10.Routes;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.test.context.ActiveProfiles;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@SpringBootTest @SpringBootTest
@ActiveProfiles(value = "test")
public class AbstractAppTests { public class AbstractAppTests {
private static final Routes routes = new Routes().autoDiscoverViews("com.primefactorsolutions"); private static final Routes routes = new Routes().autoDiscoverViews("com.primefactorsolutions");