【问题标题】:Spring Boot Security Displays page as Not SecuredSpring Boot Security 将页面显示为不安全
【发布时间】:2018-07-09 18:21:04
【问题描述】:

我希望有一个主页,然后是登录页面,由于登录页面未经授权,根据我的理解,该页面变为 UnSecured。代码如下:

主页.html

<h2>1. Visit <a th:href="@{/admin}">Admin page (Spring Security protected, Need Admin Role)</a></h2>`enter code here`
                <h2>2. Visit <a th:href="@{/user}">User page (Spring Security protected, Need User Role)</a></h2>
                <h2>3. Visit <a th:href="@{/about}">Normal page</a></h2>

这里的登录页面将变得不安全,因为它没有得到spring boot security的授权。我该如何解决以下情况

 http.csrf().disable()
                .authorizeRequests()
                .antMatchers("/", "/home", "/about").permitAll()
                .antMatchers("/admin/**").hasAnyRole("ADMIN")
                .antMatchers("/user/**").hasAnyRole("USER")
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
                .logout()
                .permitAll()
                .and()
                .exceptionHandling().accessDeniedHandler(accessDeniedHandler);

'

请帮忙。使用上述方法使用 Spring Boot Security 是否可行?

【问题讨论】:

    标签: spring-boot spring-security


    【解决方案1】:

    我通过在 application.properties 中设置以下属性解决了这个问题 server.use-forward-headers=true

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      • 2016-08-07
      • 2014-07-16
      • 2012-02-14
      • 2019-09-28
      • 1970-01-01
      相关资源
      最近更新 更多