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.openid.connect.sdk.rp;
019
020
021import net.jcip.annotations.Immutable;
022
023import com.nimbusds.oauth2.sdk.ParseException;
024import com.nimbusds.oauth2.sdk.client.ClientRegistrationErrorResponse;
025import com.nimbusds.oauth2.sdk.client.ClientRegistrationResponse;
026import com.nimbusds.oauth2.sdk.http.HTTPResponse;
027
028
029/**
030 * Parser of OpenID Connect client registration response messages.
031 *
032 * <p>Related specifications:
033 *
034 * <ul>
035 *     <li>OpenID Connect Dynamic Client Registration 1.0, section 3.2 and 3.3.
036 *     <li>OAuth 2.0 Dynamic Client Registration Protocol (RFC 7591), sections
037 *         2 and 3.2.
038 * </ul>
039 */
040@Immutable
041public class OIDCClientRegistrationResponseParser {
042        
043        
044        /**
045         * Parses an OpenID Connect client registration response from the 
046         * specified HTTP response.
047         *
048         * @param httpResponse The HTTP response. Must not be {@code null}.
049         *
050         * @return The OpenID Connect client registration response.
051         *
052         * @throws ParseException If the HTTP response couldn't be parsed to an
053         *                        OpenID Connect client registration response.
054         */
055        public static ClientRegistrationResponse parse(final HTTPResponse httpResponse)
056                throws ParseException {
057
058                final int statusCode = httpResponse.getStatusCode();
059
060                if (statusCode == HTTPResponse.SC_OK || statusCode == HTTPResponse.SC_CREATED) {
061                        return OIDCClientInformationResponse.parse(httpResponse);
062                } else {
063                        return ClientRegistrationErrorResponse.parse(httpResponse);
064                }
065        }
066        
067        
068        /**
069         * Prevents public instantiation.
070         */
071        private OIDCClientRegistrationResponseParser() { }
072}