首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTTPS安全保护只能在主页上工作,不能在下一页上工作

HTTPS安全保护只能在主页上工作,不能在下一页上工作
EN

Stack Overflow用户
提问于 2018-07-08 21:49:04
回答 1查看 41关注 0票数 1

我在AWS EC2实例的80端口上部署了一个spring boot When应用程序,当我点击像用户登录或管理员登录这样的链接时,主页显示为安全,浏览器显示它不是Secured.What,我应该这样做才能保护我的整个应用程序。

下面是我的代码,我正在使用的一个网站,我是新手spring安全,请帮助。

Home.html

代码语言:javascript
复制
<div class="starter-template">
                <h1>Spring Boot Web Thymeleaf + Spring Security</h1>
                <h2>1. Visit <a th:href="@{/admin}">Admin page (Spring Security protected, Need Admin Role)</a></h2>
                <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>
            </div>


    @Configuration
    // http://docs.spring.io/spring-boot/docs/current/reference/html/howto-security.html
    // Switch off the Spring Boot security configuration
    //@EnableWebSecurity
    public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

        @Autowired
        private AccessDeniedHandler accessDeniedHandler;

        // roles admin allow to access /admin/**
        // roles user allow to access /user/**
        // custom 403 access denied handler
        @Override
        protected void configure(HttpSecurity http) throws Exception {

            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);
        }


            @Autowired
            public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

                auth.inMemoryAuthentication()
                        .withUser("user").password("password").roles("USER")
                        .and()
                        .withUser("admin").password("password").roles("ADMIN");
            }
        }

我做错了什么?问题出在代码还是我的AWS配置中

EN

回答 1

Stack Overflow用户

发布于 2018-07-12 15:04:18

通过将application.properties设置为以下值解决了此问题

server.use-forward-headers=true

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51232633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档