【问题标题】:Spring security always returning 403Spring Security 总是返回 403
【发布时间】:2018-08-15 09:44:16
【问题描述】:

谁能告诉我为什么这段代码总是返回 403?

我映射了 /login 以触发安全登录,但它无法正常工作。

package esercizio.security;

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.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().withUser("q@q").password("pluto").roles("USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        .authorizeRequests()
        .antMatchers("/**").anonymous()
        .antMatchers("/auth/**").hasRole("USER")
        .anyRequest().authenticated()
        .and()
        .formLogin()
        .loginPage("/login.jsp")
        .defaultSuccessUrl("/auth/list-student")
        .failureUrl("/errorPage")
        .and()
        .logout().logoutSuccessUrl("/login.jsp");
    }
}

如果 URL 不以 /auth 开头,它应该让任何人进入,我不知道为什么它不会发生。

【问题讨论】:

  • @dur 我已经在我的表单中配置了 csrf

标签: spring spring-security


【解决方案1】:

我认为,你必须在你的权限前面加上“ROLE_”,比如 ROLE_USER。

更多访问:

Spring Security always return the 403 accessDeniedPage after login

【讨论】:

  • spring自动添加的
猜你喜欢
  • 2015-10-23
  • 2018-08-28
  • 1970-01-01
  • 2017-06-30
  • 2019-05-24
  • 2018-04-23
  • 2022-01-16
  • 2015-11-12
  • 1970-01-01
相关资源
最近更新 更多