我有3个运行的服务器,UI(或客户端),资源服务器和认证服务器。除了从资源服务器到客户端的信息之外,所有的事情都可以完美运行如果我使用邮递员或任何其他休息服务程序,我从认证服务器获取令牌,然后使用令牌从调查服务器获取信息。现在,我去我的客户端服务器,如果我不验证我重定向到我登录授权服务器,它使我回客户端服务器,它应该显示一个简单的一行:如何在春季启动时从客户端服务器获取资源服务器文本
灯都关了
但我只得到404空错误什么是应该表示它没有得到令牌与请求。
在我的资源服务器是一个简单的一行:
{“灯”:“灯都关了”}
任何帮助,如何摆脱资源服务器与信息赞赏附加到它的令牌。
我的资源服务器代码:
LightBoot.java
@RestController public class LightsBoot {
private static final String lights = "lights are %s";
@RequestMapping(value = "/lights")
public Lights greeting(@RequestParam(value = "name", defaultValue = "off") String name) {
return new Lights(String.format(lights, name));
} }
和我的客户端代码:
@SpringBootApplication public class ClientApplication {
public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
@Bean
OAuth2RestTemplate oAuth2RestTemplate(OAuth2ClientContext clientContext, OAuth2ProtectedResourceDetails details) {
return new OAuth2RestTemplate(details, clientContext);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
} }
@RestController public class NewController {
private RestTemplate restTemplate;
@Value("${endpoint.lights}")
private String lights;
@Autowired
public NewController(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public GetLights newLight() {
return restTemplate.getForObject(lights, GetLights.class);
}
@RequestMapping(value = "/")
public String lights() {
return newLight() + " <--- here should be value of lights";
}
}
客户端性能的样子:我的客户端应用程序的
auth-server: http://localhost:8081/authserver
resource-server: http://localhost:8082/resource
endpoint:
lights: http://localhost:8082/resource/lights
server:
port: 8080
security:
basic:
enabled: false
oauth2:
client:
client-id: user
client-secret: user-secret
access-token-uri: ${auth-server}/oauth/token
user-authorization-uri: ${auth-server}/oauth/authorize
scope: USER
authorized-grant-types: authorization_code
resource:
token-info-uri: ${auth-server}/oauth/check_token
logging:
level:
org.springframework.security: DEBUG
EDIT1 控制台输出
Redirecting to 'http://localhost:8081/authserver/oauth/authorize?client_id=jan&redirect_uri=http://localhost:8080/login&response_type=code&scope=USER&state=qJE3Rp'
Retrieving token from http://localhost:8081/authserver/oauth/token
2017-08-10 14:47:48.898 DEBUG 17560 --- [nio-8080-exec-2] g.c.AuthorizationCodeAccessTokenProvider : Encoding and sending form: {grant_type=[authorization_code], code=[0zeUdq], redirect_uri=[http://localhost:8080/login]}
2017-08-10 14:47:48.928 DEBUG 17560 --- [nio-8080-exec-2] s.CompositeSessionAuthenticationStrategy : Delegating to org.springframework.security.w[email protected]327cec
2017-08-10 14:47:48.929 DEBUG 17560 --- [nio-8080-exec-2] s.CompositeSessionAuthenticationStrategy : Delegating to o[email protected]1dd8d6
2017-08-10 14:47:48.929 DEBUG 17560 --- [nio-8080-exec-2] uth2ClientAuthenticationProcessingFilter : Authentication success. Updating SecurityContextHolder to contain: or[email protected]e5d78cca: Principal: user; Credentials: [PROTECTED]; Authenticated: true; Details: remoteAddress=0:0:0:0:0:0:0:1, sessionId=<SESSION>, tokenType=bearertokenValue=<TOKEN>; Granted Authorities: ROLE_USER
2017-08-10 14:47:48.929 DEBUG 17560 --- [nio-8080-exec-2] RequestAwareAuthenticationSuccessHandler : Redirecting to DefaultSavedRequest Url: http://localhost:8080/
2017-08-10 14:47:48.929 DEBUG 17560 --- [nio-8080-exec-2] o.s.s.web.DefaultRedirectStrategy : Redirecting to 'http://localhost:8080/'
当你说“让我回到客户端服务器”时,你具体指什么?授权服务器是否返回重定向响应?如果是这样,那么重定向到哪里?这听起来像你在这一点上被发送到一个不正确的URL。 – DaveyDaveDave
@DaveyDaveDave我添加了一个编辑,以显示什么控制台打印出来。要访问我的客户我去http:// localhost:8080,它需要我授权服务器,我登录,然后回到http:// localhost:8080 – Jan