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