spring boot XSRF-TOKEN如何添加ssl(https),配置

时间:2017-05-17 10:54:43

标签: java spring ssl spring-boot spring-security

我遇到配置弹簧启动的大问题。在我的应用程序中,我使用XSRF-TOKEN进行授权。

         http.httpBasic().and()
                .formLogin().loginPage("/login").and()
                .authorizeRequests()
                .antMatchers(
                        "/index_orange.html",
                        "/index.html",
                        "/databases.html",
                        "/crm.html",
                        "/price.html",
                        "/var/www/download"
                )
                .permitAll()
                .antMatchers("/admin/**").hasRole("ADMIN")
                .antMatchers("/user/**").hasRole("USER")
                .anyRequest().authenticated().and()
                .requiresChannel()
                .csrf().ignoringAntMatchers("/registerform","/newpassblue","/getPaymentNotification")
                .csrfTokenRepository(csrfTokenRepository()).and()
                .addFilterBefore(csrfHeaderFilter(), SessionManagementFilter.class);

授权非常有效,但我如何添加SSL(HTTPS)?

我读过,我必须使用 .requiresChannel(),但此连接会导致编译错误。

我的globalUserDetails:

        @Autowired
    public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .jdbcAuthentication()
                .dataSource(securityDataSource)
                .usersByUsernameQuery(USER_BY_EMAILS)
                .authoritiesByUsernameQuery(AUTHORIZATION_BY_EMAILS)
                .passwordEncoder(new ShaPasswordEncoder(512));

    }

我的属性文件:

   server:
    port: 8083
    ssl:
      enabled: true
      key-alias: tomcat
      key-store: keystore.p12
      key-store-password: "*****"
logging:
    path: /var/log/gateway2
    level:
        org.springframework.security: INFO
security:
    sessions: ALWAYS
zuul:
    routes:
        front:
            url: http://192.168.14.73:8080/ui-web
        backend:
            url: http://192.168.14.63:8180/idbms-web
        backend2:
            url: http://192.168.14.50:8080/itdjg-mcalendar-ui
        crm:
            url: http://192.168.14.73:8080/ui-web/crm
        bazy-danych:
            url: http://192.168.14.73:8080/ui-web
spring:
     mvc:
        view:
            prefix: /WEB-INF/jsp/
            suffix: .jsp

1 个答案:

答案 0 :(得分:0)

requiresChannel()之后添加和()。但是我认为您需要使用ssl启动Spring启动应用程序。

构建keystore.jks并使用以下参数运行应用程序或将它们添加到application.properties。

--server.port=443 --server.ssl.key-store=classpath:keystore.jks --server.ssl.key-store-password=<password> --server.ssl.key-password=<password>