【发布时间】:2015-07-29 03:02:07
【问题描述】:
我有以下安全配置
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/", "/inspinia/login.html", "/inspinia/css/**", "/inspinia/js/**", "/inspinia/fonts/**", "/inspinia/font-awesome/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
我想知道是否可以在 application.properties 而不是 WebSecurity 类中设置这些选项。
我是 spring 新手,有点困惑为什么有些设置放在 application.properties 中,而其他设置必须在类中定义。
【问题讨论】:
-
这里列出了可以配置的属性/yaml 文件。 docs.spring.io/spring-boot/docs/current/reference/html/…。查找安全属性,您会看到可以配置的内容。
标签: java spring spring-security spring-boot