diff --git a/src/main/java/com/primefactorsolutions/config/SecurityConfig.java b/src/main/java/com/primefactorsolutions/config/SecurityConfig.java index f892d3f..f347ba3 100644 --- a/src/main/java/com/primefactorsolutions/config/SecurityConfig.java +++ b/src/main/java/com/primefactorsolutions/config/SecurityConfig.java @@ -4,6 +4,7 @@ import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.views.LoginView; 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.Configuration; import org.springframework.http.HttpMethod; @@ -24,6 +25,8 @@ import java.util.Collection; @EnableWebSecurity @Configuration public class SecurityConfig extends VaadinWebSecurity { + @Value("${spring.ldap.url}") + private String ldapUrl; @Override protected void configure(final HttpSecurity http) throws Exception { @@ -47,10 +50,10 @@ public class SecurityConfig extends VaadinWebSecurity { @Bean public AuthenticationManager authenticationManager(final UserDetailsContextMapper userDetailsContextMapper) { - DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( - "ldap://localhost:8389/dc=primefactorsolutions,dc=com"); + final DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( + String.format("%s/dc=primefactorsolutions,dc=com", ldapUrl)); contextSource.setCacheEnvironmentProperties(false); - LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource); + final LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource); factory.setUserDnPatterns("uid={0},ou=users"); factory.setUserDetailsContextMapper(userDetailsContextMapper); diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 0000000..fd2c3c7 --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1,2 @@ +spring.ldap.url=ldap://localhost:8391 +spring.ldap.embedded.port=8391 diff --git a/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java b/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java index f05c2ef..d51af1f 100644 --- a/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java +++ b/src/test/java/com/primefactorsolutions/views/AbstractAppTests.java @@ -14,21 +14,19 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; -import com.github.mvysny.kaributesting.v10.MockVaadin; import com.github.mvysny.kaributesting.v10.Routes; 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.stream.Collectors; @SpringBootTest +@ActiveProfiles(value = "test") public class AbstractAppTests { private static final Routes routes = new Routes().autoDiscoverViews("com.primefactorsolutions");