001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.oauth2.sdk; 019 020 021import java.net.MalformedURLException; 022import java.net.URI; 023import java.net.URL; 024 025import com.nimbusds.oauth2.sdk.http.HTTPRequest; 026import com.nimbusds.oauth2.sdk.util.URIUtils; 027 028 029/** 030 * The base abstract class for OAuth 2.0 and OpenID Connect configuration 031 * requests. 032 */ 033public abstract class AbstractConfigurationRequest extends AbstractRequest { 034 035 036 /** 037 * Creates a new base abstract request. 038 * 039 * @param baseURI The base URI. Must not be {@code null}. 040 * @param wellKnownPath The well known path to prepend to any existing 041 * path component in the base URI. Must not be 042 * {@code null}. 043 * @param strategy The well-known path composition strategy. Must 044 * not be {@code null}. 045 */ 046 public AbstractConfigurationRequest(final URI baseURI, final String wellKnownPath, final WellKnownPathComposeStrategy strategy) { 047 048 super(WellKnownPathComposeStrategy.POSTFIX.equals(strategy) ? 049 URI.create(URIUtils.removeTrailingSlash(baseURI) + wellKnownPath) : 050 URIUtils.prependPath(baseURI, wellKnownPath)); 051 } 052 053 054 @Override 055 public HTTPRequest toHTTPRequest() { 056 057 URL url; 058 try { 059 url = getEndpointURI().toURL(); 060 } catch (IllegalArgumentException | MalformedURLException e) { 061 throw new SerializeException(e.getMessage(), e); 062 } 063 064 return new HTTPRequest(HTTPRequest.Method.GET, url); 065 } 066}