【发布时间】:2017-01-04 20:08:44
【问题描述】:
我在构建简单应用程序时收到此错误消息
从:http://localhost:9999/uaa/user 获取用户信息 无法获取用户详细信息:org.springframework.web.client.RestClientException 类,无法提取响应:没有为响应类型 [interface java.util.Map] 和内容类型 [text/html;charset=UTF-8 找到合适的 HttpMessageConverter ]
但是我确定内容类型是 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");
}
}
【问题讨论】:
-
您请求“text/html”,但希望收到“application/json”。那是行不通的。
-
我无法控制发送此请求。 spring EnableOAuth2Sso 发送请求以获取用户信息
-
你能发布你完整的异常堆栈跟踪吗?
标签: java spring spring-boot spring-oauth2