JAVA-42: Upgrade spring-security-ldap to Spring Boot 2
This commit is contained in:
parent
4382852a17
commit
ee95317ad9
|
@ -9,9 +9,9 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-1</artifactId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-1</relativePath>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -21,6 +21,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.baeldung;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
@ -19,15 +19,4 @@ public class SampleLDAPApplication extends SpringBootServletInitializer {
|
|||
SpringApplication.run(SampleLDAPApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurerAdapter adapter() {
|
||||
return new WebMvcConfigurerAdapter() {
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/login")
|
||||
.setViewName("login");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.security;
|
||||
package com.baeldung.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
|
@ -14,13 +14,26 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
auth.ldapAuthentication().userSearchBase("ou=people").userSearchFilter("(uid={0})").groupSearchBase("ou=groups").groupSearchFilter("(member={0})").contextSource().root("dc=baeldung,dc=com").ldif("classpath:users.ldif");
|
||||
auth.ldapAuthentication()
|
||||
.userSearchBase("ou=people")
|
||||
.userSearchFilter("(uid={0})")
|
||||
.groupSearchBase("ou=groups")
|
||||
.groupSearchFilter("(member={0})")
|
||||
.contextSource()
|
||||
.root("dc=baeldung,dc=com")
|
||||
.ldif("classpath:users.ldif");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.authorizeRequests().antMatchers("/", "/home").permitAll().anyRequest().authenticated();
|
||||
http.formLogin().loginPage("/login").permitAll().and().logout().logoutSuccessUrl("/");
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home", "/css/**")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
.and().formLogin().loginPage("/login").permitAll()
|
||||
.and().logout().logoutSuccessUrl("/");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/login")
|
||||
.setViewName("login");
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
management.health.ldap.enabled=false
|
|
@ -10,6 +10,7 @@
|
|||
<http auto-config="true" use-expressions="true">
|
||||
<intercept-url pattern="/" access="permitAll"/>
|
||||
<intercept-url pattern="/home" access="permitAll"/>
|
||||
<intercept-url pattern="/css/**" access="permitAll"/>
|
||||
<intercept-url pattern="/login" access="permitAll"/>
|
||||
<intercept-url pattern="/secure" access="isAuthenticated()"/>
|
||||
|
||||
|
|
Loading…
Reference in New Issue