field tokenservices需要“resourceservertokenservices”类型的bean

9rbhqvlz  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(340)

当令牌无效时,我试图重写检查令牌oauth响应消息,但我得到以下错误:

Field tokenServices in com.krishantha.rentcloud.authorizationserver.config.OAuth2ResourceServerConfig required a bean of type 'org.springframework.security.oauth2.provider.token.ResourceServerTokenServices' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
    - Bean method 'jwkTokenServices' in 'ResourceServerTokenServicesConfiguration.JwkTokenStoreConfiguration' not loaded because OAuth JWK Condition did not find key jwk set URI not provided
    - Bean method 'jwkTokenServices' in 'ResourceServerTokenServicesConfiguration.JwkTokenStoreConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration did not match
    - Bean method 'jwtTokenServices' in 'ResourceServerTokenServicesConfiguration.JwtTokenServicesConfiguration' not loaded because OAuth JWT Condition did not find provided public key
    - Bean method 'jwtTokenServices' in 'ResourceServerTokenServicesConfiguration.JwtTokenServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration did not match
    - Bean method 'socialTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.SocialTokenServicesConfiguration' not loaded because @ConditionalOnClass did not find required class 'org.springframework.social.connect.support.OAuth2ConnectionFactory'
    - Bean method 'userInfoTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.SocialTokenServicesConfiguration' not loaded because @ConditionalOnClass did not find required class 'org.springframework.social.connect.support.OAuth2ConnectionFactory'
    - Bean method 'socialTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.SocialTokenServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration did not match
    - Bean method 'userInfoTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.SocialTokenServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration did not match
    - Bean method 'socialTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.SocialTokenServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$RemoteTokenServicesConfiguration did not match
    - Bean method 'userInfoTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.SocialTokenServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$RemoteTokenServicesConfiguration did not match
    - Bean method 'remoteTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.TokenInfoServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration did not match
    - Bean method 'remoteTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.TokenInfoServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$RemoteTokenServicesConfiguration did not match
    - Bean method 'userInfoTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.UserInfoTokenServicesConfiguration' not loaded because OAuth TokenInfo Condition did not find user-info-uri property
    - Bean method 'userInfoTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.UserInfoTokenServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration did not match
    - Bean method 'userInfoTokenServices' in 'ResourceServerTokenServicesConfiguration.RemoteTokenServicesConfiguration.UserInfoTokenServicesConfiguration' not loaded because Ancestor org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerTokenServicesConfiguration$RemoteTokenServicesConfiguration did not match

Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.security.oauth2.provider.token.ResourceServerTokenServices' in your configuration.

我的配置文件是:

package com.krishantha.rentcloud.authorizationserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
import org.springframework.stereotype.Component;

@Component
@Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {

    @Autowired
    public ResourceServerTokenServices tokenServices;

    @Autowired
    private WebResponseExceptionTranslator<?> oauth2ResponseExceptionTranslator;

    @Override
    public void configure(final ResourceServerSecurityConfigurer config) {
        OAuth2AccessDeniedHandler auth2AccessDeniedHandler = new OAuth2AccessDeniedHandler();
        auth2AccessDeniedHandler.setExceptionTranslator(oauth2ResponseExceptionTranslator);
        OAuth2AuthenticationEntryPoint authenticationEntryPoint = new OAuth2AuthenticationEntryPoint();
        authenticationEntryPoint.setExceptionTranslator(oauth2ResponseExceptionTranslator);
        config.tokenServices(tokenServices).accessDeniedHandler(auth2AccessDeniedHandler).authenticationEntryPoint(authenticationEntryPoint);
    }

}

自定义WebResponseExceptionTranslator为:

@Component  
public class CustomWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator {

    /**
     * Modify OAuth2.0 Error Response
     * @param e
     * @return ResponseEntity<OAuth2Exception>
     * @throws Exception
     */

    @Override
    public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
        ResponseEntity responseEntity = super.translate(e);
        OAuth2Exception auth2Exception = (OAuth2Exception)responseEntity.getBody();
        if (auth2Exception != null) {
            auth2Exception.addAdditionalInformation("data", null);
            auth2Exception.addAdditionalInformation("message", auth2Exception.getMessage());
            auth2Exception.addAdditionalInformation("statusCode", String.valueOf(auth2Exception.getHttpErrorCode()));
        }
        return new ResponseEntity<OAuth2Exception>(auth2Exception, responseEntity.getHeaders(), responseEntity.getStatusCode());
    }
}

有谁能帮我摆脱这个优点吗?我试图在令牌过期时修改oauth的响应消息。请帮忙。
提前谢谢

暂无答案!

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

相关问题