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 com.nimbusds.oauth2.sdk.ParseException;
022import com.nimbusds.oauth2.sdk.Response;
023import com.nimbusds.oauth2.sdk.http.HTTPResponse;
024
025
026/**
027 * Trust negotiation response.
028 *
029 * <p>Related specifications:
030 *
031 * <ul>
032 *     <li>OpenID Connect Federation 1.0, sections 6.2.2 and 6.4.
033 * </ul>
034 */
035public abstract class TrustNegotiationResponse implements Response {
036        
037        
038        /**
039         * Casts this response to a trust negotiation success response.
040         *
041         * @return The trust negotiation success response.
042         */
043        public TrustNegotiationSuccessResponse toSuccessResponse() {
044                return (TrustNegotiationSuccessResponse)this;
045        }
046        
047        
048        /**
049         * Casts this response to a trust negotiation error response.
050         *
051         * @return The trust negotiation error response.
052         */
053        public TrustNegotiationErrorResponse toErrorResponse() {
054                return (TrustNegotiationErrorResponse)this;
055        }
056        
057        
058        /**
059         * Parses a trust negotiation response from the specified HTTP response.
060         *
061         * @param httpResponse The HTTP response. Must not be {@code null}.
062         *
063         * @return The trust negotiation response.
064         *
065         * @throws ParseException If parsing failed.
066         */
067        public static TrustNegotiationResponse parse(final HTTPResponse httpResponse)
068                throws ParseException {
069                if (httpResponse.indicatesSuccess()) {
070                        return TrustNegotiationSuccessResponse.parse(httpResponse);
071                } else {
072                        return TrustNegotiationErrorResponse.parse(httpResponse);
073                }
074        }
075}