001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2020, 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.openid.connect.sdk.federation.api; 019 020 021import java.net.URI; 022import java.util.List; 023import java.util.Map; 024 025import com.nimbusds.oauth2.sdk.AbstractRequest; 026import com.nimbusds.oauth2.sdk.http.HTTPRequest; 027import com.nimbusds.oauth2.sdk.util.URLUtils; 028 029 030/** 031 * Federation API request. 032 * 033 * <p>Related specifications: 034 * 035 * <ul> 036 * <li>OpenID Connect Federation 1.0, section 6. 037 * </ul> 038 */ 039public abstract class FederationAPIRequest extends AbstractRequest { 040 041 042 /** 043 * The requested operation. 044 */ 045 private final OperationType operationType; 046 047 048 /** 049 * Creates a new federation API request. 050 * 051 * @param endpoint The federation API endpoint. Must not be 052 * {@code null}. 053 * @param operationType The requested operation type. Must not be 054 * {@code null}. 055 */ 056 public FederationAPIRequest(final URI endpoint, final OperationType operationType) { 057 super(endpoint); 058 if (operationType == null) { 059 throw new IllegalArgumentException("The operation type must not be null"); 060 } 061 this.operationType = operationType; 062 } 063 064 065 /** 066 * Returns the requested operation type. 067 * 068 * @return The operation type. 069 */ 070 public OperationType getOperationType() { 071 return operationType; 072 } 073 074 075 /** 076 * Returns the request query parameters. 077 * 078 * @return The request query parameters. 079 */ 080 public abstract Map<String, List<String>> toParameters(); 081 082 083 @Override 084 public HTTPRequest toHTTPRequest() { 085 086 HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.GET, getEndpointURI()); 087 httpRequest.setQuery(URLUtils.serializeParameters(toParameters())); 088 return httpRequest; 089 } 090}