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 * Trust mark status error response. 029 * 030 * <p>Related specifications: 031 * 032 * <ul> 033 * <li>OpenID Connect Federation 1.0, section 7.5. 034 * </ul> 035 */ 036@Immutable 037public class TrustMarkStatusErrorResponse extends TrustMarkStatusResponse { 038 039 040 /** 041 * The federation API error. 042 */ 043 private final FederationAPIError error; 044 045 046 /** 047 * Creates a new trust mark status error response. 048 * 049 * @param error The federation API error. Must not be {@code null}. 050 */ 051 public TrustMarkStatusErrorResponse(final FederationAPIError error) { 052 if (error == null) { 053 throw new IllegalArgumentException("The error object must not be null"); 054 } 055 this.error = error; 056 } 057 058 059 /** 060 * Returns the federation API error. 061 * 062 * @return The federation API error. 063 */ 064 public FederationAPIError getErrorObject() { 065 return error; 066 } 067 068 069 @Override 070 public boolean indicatesSuccess() { 071 return false; 072 } 073 074 075 @Override 076 public HTTPResponse toHTTPResponse() { 077 return error.toHTTPResponse(); 078 } 079 080 081 /** 082 * Parses a trust mark status error response from the specified HTTP 083 * response. 084 * 085 * @param httpResponse The HTTP response. Must not be {@code null}. 086 * 087 * @return The trust mark status error response. 088 * 089 * @throws ParseException If parsing failed. 090 */ 091 public static TrustMarkStatusErrorResponse parse(final HTTPResponse httpResponse) 092 throws ParseException { 093 httpResponse.ensureStatusCodeNotOK(); 094 return new TrustMarkStatusErrorResponse(FederationAPIError.parse(httpResponse)); 095 } 096}