【发布时间】:2020-09-27 01:54:05
【问题描述】:
我有这个 SpringBoot 安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(HttpMethod.PUT, "/api/**").permitAll()
.antMatchers(publicMatchers()).permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").defaultSuccessUrl("/book/list")
.failureUrl("/login?error").permitAll()
.and()
.logout().permitAll();
}
private String[] publicMatchers() {
/** Public URLs. */
final String[] PUBLIC_MATCHERS = {
"/webjars/**",
serverContextPath + "/css/**",
serverContextPath + "/js/**",
serverContextPath + "/fonts/**",
serverContextPath + "/images/**",
"/api/**",
serverContextPath ,
"/",
"/error/**/*",
"/console/**",
ForgotMyPasswordController.FORGOT_PASSWORD_URL_MAPPING,
ForgotMyPasswordController.CHANGE_PASSWORD_PATH,
SignupController.SIGNUP_URL_MAPPING
};
return PUBLIC_MATCHERS;
}
期待这个 URL http://localhost:5678/pradera/api/users/fcm(使用 PUT 方法)将是公开的,但是当我在 Postman 上测试它时,Ii 将我重定向到登录页面
在 publicMatchers() 方法上,我也有 "/api/**",,它似乎适用于调用 http://localhost:5678/pradera/api/deviceevent/list (GET)
【问题讨论】:
-
您在 /api 映射之前有一个 /pradera 映射,但在您的安全配置中,只有 /api 匹配 permitAll() 将其更改为 /pradera/api/** 以使其工作,除非您没有'未提供上下文映射。
标签: spring-boot rest spring-mvc spring-security