【发布时间】:2019-03-11 11:02:07
【问题描述】:
我启用了 Spring Boot 安全性,并在排除列表中添加了一些 url (porterty security.ignored) 在 application.yaml 中。
现在我想在我的配置类中以编程方式将一些新的 url 添加到排除列表中。
我怎样才能做到这一点?
PS 我无法编辑 yaml,我只能编辑配置类。
【问题讨论】:
标签: spring spring-boot spring-security
我启用了 Spring Boot 安全性,并在排除列表中添加了一些 url (porterty security.ignored) 在 application.yaml 中。
现在我想在我的配置类中以编程方式将一些新的 url 添加到排除列表中。
我怎样才能做到这一点?
PS 我无法编辑 yaml,我只能编辑配置类。
【问题讨论】:
标签: spring spring-boot spring-security
如果您希望在 java 中排除一些 url 模式而不是 yaml 或属性。
例子:
如果需要排除,
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/login**").permitAll()
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/**").access("hasRole('ROLE_USER')")
.and()
.formLogin().loginPage("/login").failureUrl("/login?error")
.usernameParameter("username").passwordParameter("password")
.and()
.logout().logoutSuccessUrl("/login?logout")
.and()
.exceptionHandling().accessDeniedPage("/403")
.and()
.csrf();
}
如果需要忽略,
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/authFailure");
}
希望这是有用的。
【讨论】: