【问题标题】:JwtAccessTokenConverter and JwtTokenStore was drepreciated. What can be used instead?JwtAccessTokenConverter 和 JwtTokenStore 被贬低了。可以用什么代替?
【发布时间】:2021-12-19 21:29:58
【问题描述】:

我正在使用 Spring Security 创建一个应用程序。我需要将 JWT 与 JwtAccessTokenConverter 和 JwtTokenStore 一起使用。当我导入时,它表明它已折旧。可以用什么代替?


package com.devsuperior.dscatalog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class AppConfig {

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder(); // return a instance
    }
    
    
    // Objects can access a token JWT: ready, write, create, etc
    
    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter tokenConverter = new JwtAccessTokenConverter();
        tokenConverter.setSigningKey("MY-JWT-SECRET");
        return tokenConverter;
    }

    @Bean
    public JwtTokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
    }

}

【问题讨论】:

标签: java spring jwt


【解决方案1】:

实际上,整个Spring Security OAuth project 已被弃用。我假设您想要授权服务器的替代方案。如果是这种情况,您可以尝试使用Spring Authorization Server

由 Spring Security 团队领导的 Spring Authorization Server 项目专注于为 Spring 社区提供 OAuth 2.1 Authorization Server 支持。

它现在支持大量 features,您可以等待下一个版本中完全支持的 OIDC 实现。

【讨论】:

    【解决方案2】:

    我将 pom.xml 调整为该依赖项:

    <dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
    </dependency>
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 2021-11-10
    • 1970-01-01
    • 2014-09-05
    相关资源
    最近更新 更多