我有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