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 net.jcip.annotations.Immutable; 022 023import com.nimbusds.oauth2.sdk.ParseException; 024import com.nimbusds.oauth2.sdk.http.HTTPResponse; 025 026 027/** 028 * Resolve entity statement success response. 029 * 030 * <p>Related specifications: 031 * 032 * <ul> 033 * <li>OpenID Connect Federation 1.0, section 7.2.2. 034 * </ul> 035 */ 036@Immutable 037public class ResolveSuccessResponse extends ResolveResponse { 038 039 040 /** 041 * The resolve statement. 042 */ 043 private final ResolveStatement resolveStatement; 044 045 046 /** 047 * Creates a new trust negotiation success response. 048 * 049 * @param resolveStatement The resolve statement. Must not be 050 * {@code null}. 051 */ 052 public ResolveSuccessResponse(final ResolveStatement resolveStatement) { 053 if (resolveStatement == null) { 054 throw new IllegalArgumentException("The resolve statement must not be null"); 055 } 056 this.resolveStatement = resolveStatement; 057 } 058 059 060 /** 061 * Returns the resolve statement. No signature or expiration validation 062 * is performed. 063 * 064 * @return The resolve statement. 065 */ 066 public ResolveStatement getResolveStatement() { 067 return resolveStatement; 068 } 069 070 071 @Override 072 public boolean indicatesSuccess() { 073 return true; 074 } 075 076 077 @Override 078 public HTTPResponse toHTTPResponse() { 079 HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK); 080 httpResponse.setEntityContentType(ResolveStatement.CONTENT_TYPE); 081 httpResponse.setContent(getResolveStatement().getSignedStatement().serialize()); 082 return httpResponse; 083 } 084 085 086 /** 087 * Parses a resolve success response from the specified HTTP response. 088 * 089 * @param httpResponse The HTTP response. Must not be {@code null}. 090 * 091 * @return The resolve success response. 092 * 093 * @throws ParseException If parsing failed. 094 */ 095 public static ResolveSuccessResponse parse(final HTTPResponse httpResponse) 096 throws ParseException { 097 098 httpResponse.ensureStatusCode(HTTPResponse.SC_OK); 099 httpResponse.ensureEntityContentType(ResolveStatement.CONTENT_TYPE); 100 return new ResolveSuccessResponse(ResolveStatement.parse(httpResponse.getContent())); 101 } 102}