【问题标题】:spring-boot project with spring-security do not access views带有 spring-security 的 spring-boot 项目不访问视图
【发布时间】:2016-04-29 00:53:59
【问题描述】:

我开始一个基于 spring-boot 的新项目,使用另一个项目的 spring-security 的这个工作配置类:

@Configuration
@ComponentScan
@EnableWebMvcSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private PermissionEvaluator permissionEvaluator;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
          .csrf()
            .disable()
          .authorizeRequests()
            .antMatchers("/").permitAll()
            .anyRequest().authenticated()
          .and()
          .formLogin()
            .loginPage("/signin")
            .loginProcessingUrl("/login").permitAll()
          .and()
          .logout()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/");
    }

    @Override
        public void configure(WebSecurity web) throws Exception {
            DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
          handler.setPermissionEvaluator(permissionEvaluator);
          web.expressionHandler(handler);
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
          .userDetailsService(userDetailsService)
          .passwordEncoder(passwordEncoder);
    }
}

当我在 tomcat 服务器中部署项目时,没有错误,并尝试访问应用程序,而不是索引页面,我得到一个弹出窗口,要求我输入用户名和密码。

该项目的完整代码是:https://github.com/klebermo/basic_webapp

任何人都可以看到这个配置有什么问题?

【问题讨论】:

  • 我建议阅读文档。简而言之,将@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) 添加到您的配置类中。

标签: spring spring-security spring-boot


【解决方案1】:

将此添加到您的 application.properties 文件中: security.basic.enabled=false

默认情况下,一切都使用 HTTP 基本身份验证进行保护。

参考:http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.html

【讨论】:

    猜你喜欢
    • 2018-01-29
    • 2017-07-22
    • 2017-10-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 2018-03-21
    • 2022-06-12
    • 2018-02-05
    相关资源
    最近更新 更多