Way*_*eio 5 java spring spring-mvc spring-security
我正在使用 Spring web security,下面的代码限制了除资源和 app.html 等列出的页面之外的所有页面
如何更改此设置以允许除我特别指定的页面之外的所有页面?
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http .authorizeRequests()
.antMatchers("/resources/**", "/registration", "/app.html").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
}
}
Run Code Online (Sandbox Code Playgroud)
我从这里得到了代码:https : //spring.io/blog/2013/07/03/spring-security-java-config-preview-web-security/ 但我看不到我的问题的答案。
谢谢
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/mysupersecureurl/**").authenticated()
.anyRequest().permitAll()
.and()
.csrf().disable();
}
Run Code Online (Sandbox Code Playgroud)
这将保护您的mysupersecureurl
并让其他网址打开(即permitAll()
)。
另外,如果您要向 .net 上的网址以外的其他网址发布帖子,您可以禁用 csrf mysupersecureurl
。您可以保留或删除该选项。
归档时间: |
|
查看次数: |
1302 次 |
最近记录: |