大佬教程收集整理的这篇文章主要介绍了用于Web的RESTFul和FormLogin(Cookies)的Spring Security HTTP Basic-批注,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的研究为我提供了解决方案:)
解
@Configuration
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, proxyTargetClass = truE)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@autowired
private AuthenticationProvIDer authenticationProvIDer;
@autowired
public voID configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvIDer(authenticationProvIDer);
}
@Configuration
@Order(1)
public static class APIWebSecurityConfig extends WebSecurityConfigurerAdapter{
@OverrIDe
protected voID configure(httpSecurity http) throws Exception {
http.csrf().disable()
.antMatcher("/API/**")
.authorizerequests()
.anyrequest().hasAnyRole("admin", "API")
.and()
.httpBasic();
}
}
@Configuration
@Order(2)
public static class FormWebSecurityConfig extends WebSecurityConfigurerAdapter{
@OverrIDe
public voID configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/CSS/**", "/Js/**", "/img/**", "/lib/**");
}
@OverrIDe
protected voID configure(httpSecurity http) throws Exception {
http.csrf().disable() //http with disable CSRF
.authorizerequests() //Authorize request Configuration
.antMatchers("/connect/**").permitAll()
.antMatchers("/", "/register").permitAll()
.antMatchers("/admin/**").hasRole("admin")
.anyrequest().authenticated()
.and() //Login Form configuration for all others
.formLogin()
.loginPage("/login").permitAll()
.and() //logout Form configuration
.logout().permitAll();
}
}
}
具体而言
我只想对特定的网址格式进行http基本身份验证。
详细
我正在为我的应用程序创建一个API接口,需要通过简单的http基本身份验证进行身份验证。但其他网页应不使用http基本而是在正常的形式登录。
当前配置-不起作用
@Override
protected void configure(httpSecurity http) throws Exception {
http //http Security
.csrf().disable() //Disable CSRF
.authorizerequests() //Authorize request Configuration
.antMatchers("/connect/**").permitAll()
.antMatchers("/","/register").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/api/**").hasRole("API")
.anyrequest().authenticated()
.and() //http basic Authentication only for API
.antMatcher("/api/**").httpBasic()
.and() //Login Form configuration for all others
.formLogin().loginPage("/login").permitAll()
.and() //Logout Form configuration
.logout().permitAll();
}
以上是大佬教程为你收集整理的用于Web的RESTFul和FormLogin(Cookies)的Spring Security HTTP Basic-批注全部内容,希望文章能够帮你解决用于Web的RESTFul和FormLogin(Cookies)的Spring Security HTTP Basic-批注所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。