mitreid-connect
公開メンバ関数 | 関数 | 非公開変数類 | 全メンバ一覧
org.mitre.openid.connect.client.service.impl.WebfingerIssuerService.WebfingerIssuerFetcher クラス
org.mitre.openid.connect.client.service.impl.WebfingerIssuerService.WebfingerIssuerFetcher の継承関係図
Inheritance graph
org.mitre.openid.connect.client.service.impl.WebfingerIssuerService.WebfingerIssuerFetcher 連携図
Collaboration graph

公開メンバ関数

LoadingResult load (String identifier) throws Exception
 

関数

 WebfingerIssuerFetcher (HttpClient httpClient)
 

非公開変数類

HttpComponentsClientHttpRequestFactory httpFactory
 
JsonParser parser = new JsonParser()
 

詳解

著者
jricher

構築子と解体子

◆ WebfingerIssuerFetcher()

org.mitre.openid.connect.client.service.impl.WebfingerIssuerService.WebfingerIssuerFetcher.WebfingerIssuerFetcher ( HttpClient  httpClient)
inlinepackage
214  {
215  this.httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
216  }
HttpComponentsClientHttpRequestFactory httpFactory
Definition: WebfingerIssuerService.java:211

関数詳解

◆ load()

LoadingResult org.mitre.openid.connect.client.service.impl.WebfingerIssuerService.WebfingerIssuerFetcher.load ( String  identifier) throws Exception
inline
219  {
220 
221  UriComponents key = WebfingerURLNormalizer.normalizeResource(identifier);
222 
223  RestTemplate restTemplate = new RestTemplate(httpFactory);
224  // construct the URL to go to
225 
226  String scheme = key.getScheme();
227 
228  // preserving http scheme is strictly for demo system use only.
229  if (!Strings.isNullOrEmpty(scheme) &&scheme.equals("http")) {
230  if (forceHttps) {
231  throw new IllegalArgumentException("Scheme must not be 'http'");
232  } else {
233  logger.warn("Webfinger endpoint MUST use the https URI scheme, overriding by configuration");
234  scheme = "http://"; // add on colon and slashes.
235  }
236  } else {
237  // otherwise we don't know the scheme, assume HTTPS
238  scheme = "https://";
239  }
240 
241  // do a webfinger lookup
242  URIBuilder builder = new URIBuilder(scheme
243  + key.getHost()
244  + (key.getPort() >= 0 ? ":" + key.getPort() : "")
245  + Strings.nullToEmpty(key.getPath())
246  + "/.well-known/webfinger"
247  + (Strings.isNullOrEmpty(key.getQuery()) ? "" : "?" + key.getQuery())
248  );
249  builder.addParameter("resource", identifier);
250  builder.addParameter("rel", "http://openid.net/specs/connect/1.0/issuer");
251 
252  try {
253 
254  // do the fetch
255  logger.info("Loading: " + builder.toString());
256  String webfingerResponse = restTemplate.getForObject(builder.build(), String.class);
257 
258  JsonElement json = parser.parse(webfingerResponse);
259 
260  if (json != null && json.isJsonObject()) {
261  // find the issuer
262  JsonArray links = json.getAsJsonObject().get("links").getAsJsonArray();
263  for (JsonElement link : links) {
264  if (link.isJsonObject()) {
265  JsonObject linkObj = link.getAsJsonObject();
266  if (linkObj.has("href")
267  && linkObj.has("rel")
268  && linkObj.get("rel").getAsString().equals("http://openid.net/specs/connect/1.0/issuer")) {
269 
270  // we found the issuer, return it
271  String href = linkObj.get("href").getAsString();
272 
273  if (identifier.equals(href)
274  || identifier.startsWith("http")) {
275  // try to avoid sending a URL as the login hint
276  return new LoadingResult(null, href);
277  } else {
278  // otherwise pass back whatever the user typed as a login hint
279  return new LoadingResult(identifier, href);
280  }
281  }
282  }
283  }
284  }
285  } catch (JsonParseException | RestClientException e) {
286  logger.warn("Failure in fetching webfinger input", e.getMessage());
287  }
288 
289  // we couldn't find it!
290 
291  if (key.getScheme().equals("http") || key.getScheme().equals("https")) {
292  // if it looks like HTTP then punt: return the input, hope for the best
293  logger.warn("Returning normalized input string as issuer, hoping for the best: " + identifier);
294  return new LoadingResult(null, identifier);
295  } else {
296  // if it's not HTTP, give up
297  logger.warn("Couldn't find issuer: " + identifier);
298  throw new IllegalArgumentException();
299  }
300 
301  }
boolean forceHttps
Definition: WebfingerIssuerService.java:95
static final Logger logger
Definition: WebfingerIssuerService.java:64
HttpComponentsClientHttpRequestFactory httpFactory
Definition: WebfingerIssuerService.java:211

メンバ詳解

◆ httpFactory

HttpComponentsClientHttpRequestFactory org.mitre.openid.connect.client.service.impl.WebfingerIssuerService.WebfingerIssuerFetcher.httpFactory
private

◆ parser

JsonParser org.mitre.openid.connect.client.service.impl.WebfingerIssuerService.WebfingerIssuerFetcher.parser = new JsonParser()
private

このクラス詳解は次のファイルから抽出されました: