001package com.nimbusds.openid.connect.sdk; 002 003 004import com.nimbusds.oauth2.sdk.ParseException; 005import com.nimbusds.oauth2.sdk.Response; 006import com.nimbusds.oauth2.sdk.http.HTTPResponse; 007 008 009/** 010 * The base abstract class for UserInfo success and error responses. 011 * 012 * <p>Related specifications: 013 * 014 * <ul> 015 * <li>OpenID Connect Core 1.0, section 5.3.2 and 5.3.3. 016 * <li>OAuth 2.0 Bearer Token Usage (RFC 6750), section 3.1. 017 * </ul> 018 */ 019public abstract class UserInfoResponse implements Response { 020 021 022 /** 023 * Parses a UserInfo response from the specified HTTP response. 024 * 025 * @param httpResponse The HTTP response. Must not be {@code null}. 026 * 027 * @return The UserInfo success or error response. 028 * 029 * @throws ParseException If the HTTP response couldn't be parsed to a 030 * UserInfo response. 031 */ 032 public static UserInfoResponse parse(final HTTPResponse httpResponse) 033 throws ParseException { 034 035 if (httpResponse.getStatusCode() == HTTPResponse.SC_OK) 036 return UserInfoSuccessResponse.parse(httpResponse); 037 else 038 return UserInfoErrorResponse.parse(httpResponse); 039 } 040}