小编Jul*_* G.的帖子

Spring Security:用于API的JWT令牌和用于Web的会话

我的目标是在Spring Boot应用程序中使用这两种安全性.我已经使用JWT完成了API端,但我不知道如何为WEB端实现会话.我已经在另一个项目中完成了这项工作,但我不知道如何让它们协同工作.

这是我的SecurityConfig:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().ignoringAntMatchers("/api/**")
         .and()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
         .and()
            .authorizeRequests()
            .antMatchers("/api/register").permitAll()
            .antMatchers("/api/login").permitAll()
            .antMatchers("/api/public").permitAll()
            .antMatchers("/api/lost").permitAll()
            .antMatchers("/").permitAll()
            .antMatchers("/login").permitAll()
            .antMatchers("/contact").permitAll()
            .antMatchers("/resources/**").permitAll()
            .antMatchers("/file/**").permitAll()
            .anyRequest().authenticated()
         .and()
            .apply(new JWTConfigurer(this.tokenProvider));
}
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
         // For API side something like : .match("/api/**")
         // No CSRF
         .csrf().ignoringAntMatchers("/api/**")
         // STATELESS session
         // Use token filter
         .apply(new JWTConfigurer(this.tokenProvider));

         // For WEB side something like : .match "others"
         // Use CSRF
         .csrf()
         // Use session …
Run Code Online (Sandbox Code Playgroud)

session spring spring-security jwt spring-boot

6
推荐指数
1
解决办法
3622
查看次数

标签 统计

jwt ×1

session ×1

spring ×1

spring-boot ×1

spring-security ×1