繁体   English   中英

Spring 安全 session 域

[英]Spring Security session domain

我和我的朋友正在为大学练习制作 Java spring 引导应用程序。 它的正面在 Firebase,API 在 Heroku

问题如下,我配置Spring Security如下:

@Override
protected void configure(final HttpSecurity http) throws Exception {
    http.cors().and().csrf().disable()
            .authorizeRequests()
            .antMatchers("/admin/**", "/bid/getBids", "/bid/{id}", "/purchase/create",
                    "/purchase/{id}", "/purchase/question/{questionId}/answer").hasAuthority("ROLE_ADMIN")
            .antMatchers("/registration/**", "/registration").permitAll()
            .anyRequest().authenticated()
            .and()
                .httpBasic()
            .and()
            .formLogin()
            .permitAll()
            .and()
            .logout()
            .logoutSuccessUrl("/").deleteCookies("JSESSIONID")
            .invalidateHttpSession(true);
}

当我通过 swagger/postman 在 Heroku 上测试 API 时,一切正常,包括角色限制。

但是当它尝试通过 /login 路径设置授权时,它会重定向到 swagger-ui 页面,因为这就是我设置它的方式。 I rewrote the redirect to its main page on Firebase, but the session doesn't work that way, apparently because cookies are saved to the address of my application on Heroku.

请告诉我如何配置 Spring 安全性,以便其站点在授权期间保存用户会话,并且该站点与我的 API 正常工作?

我使用翻译器翻译一些短语,对此感到抱歉

您的前端和后端应用程序在不同的域上提供服务,并且 HTTP cookie 信息仅针对特定域存储。 因此,我认为您可以通过将 spring 引导应用程序放在 src/resources/static 下轻松地为您的 static 页面(或单页应用程序资源)提供服务。 通过这样做,您还可以限制您的前端应用程序并仅允许授权用户使用。 If you want to serve the front-end application on firebase and backend on Heroku you should forward it to the upstream host by configuring rewrite rules in the firebase.json file ( https://firebase.google.cn/docs/hosting/full -config?authuser=0#rewrites )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM