/** * 通过访问授权服务器获取非对称加密公钥 Key * @return 公钥 Key */ private String getKeyFromAuthorizationServer() { final RestTemplate keyUriRestTemplate = new RestTemplate(); final HttpHeaders headers = new HttpHeaders(); final String username = this.resource.getClientId(); final String password = this.resource.getClientSecret(); if (username != null && password != null) { final byte[] token = Base64.getEncoder().encode((username + ":" + password).getBytes()); headers.add("Authorization", "Basic " + new String(token)); } final HttpEntity<Void> request = new HttpEntity<>(headers); final String url = this.resource.getJwt().getKeyUri(); return (String) keyUriRestTemplate .exchange(url, HttpMethod.GET, request, Map.class).getBody() .get("value"); }
private String getKeyFromServer() { RestTemplate keyUriRestTemplate = new RestTemplate(); if (!CollectionUtils.isEmpty(this.customizers)) { for (JwtAccessTokenConverterRestTemplateCustomizer customizer : this.customizers) { customizer.customize(keyUriRestTemplate); } } HttpHeaders headers = new HttpHeaders(); String username = this.resource.getClientId(); String password = this.resource.getClientSecret(); if (username != null && password != null) { byte[] token = Base64.getEncoder() .encode((username + ":" + password).getBytes()); headers.add("Authorization", "Basic " + new String(token)); } HttpEntity<Void> request = new HttpEntity<>(headers); String url = this.resource.getJwt().getKeyUri(); return (String) keyUriRestTemplate .exchange(url, HttpMethod.GET, request, Map.class).getBody() .get("value"); }
private String getKeyFromServer() { RestTemplate keyUriRestTemplate = new RestTemplate(); if (!CollectionUtils.isEmpty(this.customizers)) { for (JwtAccessTokenConverterRestTemplateCustomizer customizer : this.customizers) { customizer.customize(keyUriRestTemplate); } } HttpHeaders headers = new HttpHeaders(); String username = this.resource.getClientId(); String password = this.resource.getClientSecret(); if (username != null && password != null) { byte[] token = Base64.getEncoder() .encode((username + ":" + password).getBytes()); headers.add("Authorization", "Basic " + new String(token)); } HttpEntity<Void> request = new HttpEntity<>(headers); String url = this.resource.getJwt().getKeyUri(); return (String) keyUriRestTemplate .exchange(url, HttpMethod.GET, request, Map.class).getBody() .get("value"); }
private void doValidate() throws BindException { BindingResult errors = new BeanPropertyBindingResult(this, "resourceServerProperties"); boolean jwtConfigPresent = StringUtils.hasText(this.jwt.getKeyUri()) || StringUtils.hasText(this.jwt.getKeyValue()); boolean jwkConfigPresent = StringUtils.hasText(this.jwk.getKeySetUri()); if (jwtConfigPresent && jwkConfigPresent) { errors.reject("ambiguous.keyUri", "Only one of jwt.keyUri (or jwt.keyValue) and jwk.keySetUri should" + " be configured."); } if (!jwtConfigPresent && !jwkConfigPresent) { if (!StringUtils.hasText(this.userInfoUri) && !StringUtils.hasText(this.tokenInfoUri)) { errors.rejectValue("tokenInfoUri", "missing.tokenInfoUri", "Missing tokenInfoUri and userInfoUri and there is no " + "JWT verifier key"); } if (StringUtils.hasText(this.tokenInfoUri) && isPreferTokenInfo()) { if (!StringUtils.hasText(this.clientSecret)) { errors.rejectValue("clientSecret", "missing.clientSecret", "Missing client secret"); } } } if (errors.hasErrors()) { throw new BindException(errors); } }
private void doValidate() throws BindException { BindingResult errors = new BeanPropertyBindingResult(this, "resourceServerProperties"); boolean jwtConfigPresent = StringUtils.hasText(this.jwt.getKeyUri()) || StringUtils.hasText(this.jwt.getKeyValue()); boolean jwkConfigPresent = StringUtils.hasText(this.jwk.getKeySetUri()); if (jwtConfigPresent && jwkConfigPresent) { errors.reject("ambiguous.keyUri", "Only one of jwt.keyUri (or jwt.keyValue) and jwk.keySetUri should" + " be configured."); } if (!jwtConfigPresent && !jwkConfigPresent) { if (!StringUtils.hasText(this.userInfoUri) && !StringUtils.hasText(this.tokenInfoUri)) { errors.rejectValue("tokenInfoUri", "missing.tokenInfoUri", "Missing tokenInfoUri and userInfoUri and there is no " + "JWT verifier key"); } if (StringUtils.hasText(this.tokenInfoUri) && isPreferTokenInfo()) { if (!StringUtils.hasText(this.clientSecret)) { errors.rejectValue("clientSecret", "missing.clientSecret", "Missing client secret"); } } } if (errors.hasErrors()) { throw new BindException(errors); } }