Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将访问令牌转换为JSON_Java_Jdbc_Oauth_Token_Spring Cloud - Fatal编程技术网

Java 无法将访问令牌转换为JSON

Java 无法将访问令牌转换为JSON,java,jdbc,oauth,token,spring-cloud,Java,Jdbc,Oauth,Token,Spring Cloud,我在spring cloud(我的授权服务器)中使用Oauth2.0,我使用jdbcTokenStore(而不是JwtTokenStore)将令牌存储在数据库中,它工作正常,但当我发出http请求时,postman返回此错误。 { “错误”:“无效的\u令牌”, “错误描述”:“无法将访问令牌转换为JSON” } 这是因为我还没有实现方法accesstokenconverter 我一直在寻找如何实现这个方法,但我还不走运。 你们能帮帮我吗 package com.restaurants.serv

我在spring cloud(我的授权服务器)中使用Oauth2.0,我使用jdbcTokenStore(而不是JwtTokenStore)将令牌存储在数据库中,它工作正常,但当我发出http请求时,postman返回此错误。 { “错误”:“无效的\u令牌”, “错误描述”:“无法将访问令牌转换为JSON” } 这是因为我还没有实现方法accesstokenconverter

我一直在寻找如何实现这个方法,但我还不走运。 你们能帮帮我吗

package com.restaurants.serviciooauth.security;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;

import javax.sql.DataSource;


@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
 private  BCryptPasswordEncoder passwordEncoder;

    @Autowired
    AuthenticationManager authenticationManager;

    //configuration to jdbc
    @Autowired
    private DataSource dataSource;

    @Bean
    public TokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
       security.tokenKeyAccess("permitAll()")
       .checkTokenAccess("isAuthenticated()");
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
     clients.inMemory().withClient("frontendapp")
             .secret(passwordEncoder.encode("12345"))
             .scopes("read","write")
     .authorizedGrantTypes("password","refresh_token")
     .accessTokenValiditySeconds(3600)
     .refreshTokenValiditySeconds(3600)
             .and()
             .withClient("androidapp")
             .secret(passwordEncoder.encode("12345"))
             .scopes("read","write")
             .authorizedGrantTypes("password","refresh_token")
             .accessTokenValiditySeconds(3600)
             .refreshTokenValiditySeconds(3600);
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager)
                .tokenStore(tokenStore());
    }


}