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 Messages 1.0, section 2.3.3. 016 * <li>OpenID Connect Standard 1.0, section 4.3. 017 * <li>OAuth 2.0 Bearer Token Usage (RFC 6750), section 3.1. 018 * </ul> 019 * 020 * @author Vladimir Dzhuvinov 021 */ 022public abstract class UserInfoResponse implements Response { 023 024 025 /** 026 * Parses a UserInfo response from the specified HTTP response. 027 * 028 * @param httpResponse The HTTP response. Must not be {@code null}. 029 * 030 * @return The UserInfo success or error response. 031 * 032 * @throws ParseException If the HTTP response couldn't be parsed to a 033 * UserInfo response. 034 */ 035 public static UserInfoResponse parse(final HTTPResponse httpResponse) 036 throws ParseException { 037 038 if (httpResponse.getStatusCode() == HTTPResponse.SC_OK) 039 return UserInfoSuccessResponse.parse(httpResponse); 040 else 041 return UserInfoErrorResponse.parse(httpResponse); 042 } 043}