Spring security Spring Boot Oauth2验证资源所有者密码凭据授予的访问令牌

Spring security Spring Boot Oauth2验证资源所有者密码凭据授予的访问令牌,spring-security,spring-security-oauth2,spring-security-rest,Spring Security,Spring Security Oauth2,Spring Security Rest,我正在编写一个过滤器,它将拦截Restful API调用,提取承载令牌,并调用授权服务器进行验证 我在SpringBoot中找不到一款开箱即用的,但我相信有一种更干净的方法可以做到这一点。 以下是我所拥有的(伪代码): }吸取的教训,Spring Security Oauth2文档严重不足,请忘记在未完全梳理源代码的情况下尝试使用该框架。另一方面,代码编写得很好,很容易被戴夫·赛尔(Dave Syer)所称赞 这是我的配置: protected void configure(HttpSecuri

我正在编写一个过滤器,它将拦截Restful API调用,提取承载令牌,并调用授权服务器进行验证

我在SpringBoot中找不到一款开箱即用的,但我相信有一种更干净的方法可以做到这一点。 以下是我所拥有的(伪代码):


}

吸取的教训,Spring Security Oauth2文档严重不足,请忘记在未完全梳理源代码的情况下尝试使用该框架。另一方面,代码编写得很好,很容易被戴夫·赛尔(Dave Syer)所称赞

这是我的配置:

protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();                  
    http.authorizeRequests()
        .antMatchers("/")
        .permitAll()
        .and()      
        .addFilterBefore(getOAuth2AuthenticationProcessingFilter(), UsernamePasswordAuthenticationFilter.class)
        .exceptionHandling();                        
}
以下是我的getOAuth2AuthenticationProcessingFilter方法:

private OAuth2AuthenticationProcessingFilter getOAuth2AuthenticationProcessingFilter() {       
    // configure token Extractor
    BearerTokenExtractor tokenExtractor = new BearerTokenExtractor();
    // configure Auth manager
    OAuth2AuthenticationManager manager = new OAuth2AuthenticationManager();
    // configure RemoteTokenServices with your client Id and auth server endpoint
    manager.setTokenServices(remoteTokenServices);

    OAuth2AuthenticationProcessingFilter filter = new OAuth2AuthenticationProcessingFilter();
    filter.setTokenExtractor(tokenExtractor);        
    filter.setAuthenticationManager(manager);
    return filter;
}

您好,您能告诉我您是如何创建remoteTokenServices的吗?Primary@Bean public remoteTokenServices tokenService(){remoteTokenServices tokenService=new remoteTokenServices();tokenService.setCheckTokenEndpointUrl();tokenService.setClientId(“FooclientPassword”);tokenService.setClientSecret(“secret”);返回令牌服务;}
private OAuth2AuthenticationProcessingFilter getOAuth2AuthenticationProcessingFilter() {       
    // configure token Extractor
    BearerTokenExtractor tokenExtractor = new BearerTokenExtractor();
    // configure Auth manager
    OAuth2AuthenticationManager manager = new OAuth2AuthenticationManager();
    // configure RemoteTokenServices with your client Id and auth server endpoint
    manager.setTokenServices(remoteTokenServices);

    OAuth2AuthenticationProcessingFilter filter = new OAuth2AuthenticationProcessingFilter();
    filter.setTokenExtractor(tokenExtractor);        
    filter.setAuthenticationManager(manager);
    return filter;
}