无法获取用户详细信息:class org.springframework.web.client.RestClientException,无法提取响应:没有合适的

时间:2017-01-04 20:08:44

标签: java spring spring-boot spring-oauth2

在构建简单的应用程序时收到此错误消息

获取用户信息:http://localhost:9999/uaa/user   无法获取用户详细信息:class org.springframework.web.client.RestClientException,无法提取响应:没有为响应类型[interface java.util.Map]找到合适的HttpMessageConverter和内容类型[text / html; charset = UTF-8 ]

但是我确定内容类型是json

这是github存储库https://github.com/ashraf-revo/oauth

这是服务器

@SpringBootApplication
public class AuthServerApplication {

public static void main(String[] args) {
    SpringApplication.run(AuthServerApplication.class, args);
}
}

@Order(1)
@Configuration
@EnableWebSecurity
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws     Exception {
      auth.inMemoryAuthentication().withUser("ashraf").password("ashraf").roles("user");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/user").authenticated().and().formLogin();
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}
}

@Configuration
class OAuth2ServerConfig {
private static final String RESOURCE_IDS = "revo";

@Configuration
@EnableResourceServer
protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.resourceId(RESOURCE_IDS);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {

        http.authorizeRequests().antMatchers("/user").authenticated();
    }
}

@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
    @Autowired
    TokenStore tokenStore;

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory().withClient("revo")
                .resourceIds(RESOURCE_IDS)
                .authorizedGrantTypes("authorization_code", "implicit")
                .authorities("ROLE_CLIENT")
                .scopes("read", "write")
                .secret("revo");
    }

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

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

}

这是客户

@SpringBootApplication
public class ClientApplication {

public static void main(String[] args) {
    SpringApplication.run(ClientApplication.class, args);
}
}

@Configuration
@EnableOAuth2Sso
class SecurityConfigurer extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().mvcMatchers("/home").authenticated();
}
}

 @Configuration
 class MvcConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("index");
    registry.addViewController("/home").setViewName("home");
}
}

2 个答案:

答案 0 :(得分:0)

你可以考虑一下spring-boot版本和spring-cloud版本,选择一个不是最新版本,比如spring-boot-1.4.4.RELEASE和spring-cloud-Camden.SR5;因为我有同样的麻烦并且由此解决方式

答案 1 :(得分:0)

如果您可以控制服务器响应,请修改它以将Content-type设置为application / json。

请尝试,

<remove name="WebDAVModule" />