jwt令牌如何通过具有rest端点的spring boot应用程序中的授权头发送?

mwg9r5ms  于 2021-09-30  发布在  Java
关注(0)|答案(0)|浏览(194)

我制作了一个具有Spring Security 的spring引导应用程序,该应用程序具有登录和基于角色的端点访问权限。登录用户获得一个存储为http cookie的jwt密钥(如果我将其保存为非http cookie,我可以在javascript中访问该cookie,并可以使用ajax请求将其添加到授权头并发送到其余端点,但这不是我想要实现的)。我尝试添加jwt auth filter和jwt intreceptors,并检查了许多github repo,但还没有找到为每个对特定rest端点的调用添加http授权头的完美解决方案。
我的安全配置的代码段:

http.csrf().disable();

    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    http.exceptionHandling().accessDeniedPage("/sportscamp/signin/**");

    // Entry points
    http.csrf().disable().authorizeRequests().antMatchers("/h2-console/**/**").permitAll()
            .antMatchers("/", "index", "/css/**", "/js/**", "/sportscamp/**", "/sportscamp/signin/**",
                    "/sportscamp/signup/**", "/sportscamp/authenticate/")
            .permitAll().antMatchers("/coach/**").hasRole("COACH").antMatchers("/athelete/**")
            .hasRole("ATHLETE").anyRequest().authenticated();

    http.addFilterBefore(MyJwtRequestFilter, UsernamePasswordAuthenticationFilter.class);

注意:请不要建议使用 Postman 发送验证标题。我想知道现实世界中的应用程序如何使用jwt处理这个用户和登录

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题