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.oauth2.sdk; 019 020 021import net.jcip.annotations.Immutable; 022 023import com.nimbusds.oauth2.sdk.http.HTTPResponse; 024 025 026/** 027 * Request object POST error response. 028 * 029 * <p>Example request object POST error response indicating an invalid JWS 030 * signature: 031 * 032 * <pre> 033 * HTTP/1.1 401 Unauthorized 034 * Date: Tue, 2 May 2017 15:22:31 GMT 035 * </pre> 036 * 037 * <p>Related specifications: 038 * 039 * <ul> 040 * <li>Financial-grade API - Part 2: Read and Write API Security Profile, 041 * section 7. 042 * <li>The OAuth 2.0 Authorization Framework: JWT Secured Authorization 043 * Request (JAR) (draft-ietf-oauth-jwsreq-17). 044 * </ul> 045 */ 046@Deprecated 047@Immutable 048public final class RequestObjectPOSTErrorResponse extends RequestObjectPOSTResponse implements ErrorResponse { 049 050 051 /** 052 * Holds the HTTP status code. 053 */ 054 private final ErrorObject errorObject; 055 056 057 /** 058 * Creates a new request object POST error response. 059 * 060 * @param httpStatusCode The HTTP status code. Should be other than 061 * 2xx. 062 */ 063 public RequestObjectPOSTErrorResponse(final int httpStatusCode) { 064 errorObject = new ErrorObject(null, null, httpStatusCode); 065 } 066 067 068 public int getHTTPStatusCode() { 069 return errorObject.getHTTPStatusCode(); 070 } 071 072 073 @Override 074 public ErrorObject getErrorObject() { 075 return errorObject; 076 } 077 078 079 @Override 080 public boolean indicatesSuccess() { 081 return false; 082 } 083 084 085 @Override 086 public HTTPResponse toHTTPResponse() { 087 return new HTTPResponse(getHTTPStatusCode()); 088 } 089 090 091 /** 092 * Parses a request object POST error response from the specified 093 * HTTP response. 094 * 095 * @param httpResponse The HTTP response. Must not be {@code null}. 096 * 097 * @return The request object POST error response. 098 * 099 * @throws ParseException If the HTTP response couldn't be parsed to a 100 * request object POST error response. 101 */ 102 public static RequestObjectPOSTErrorResponse parse(final HTTPResponse httpResponse) 103 throws ParseException { 104 105 if (httpResponse.getStatusCode() >= 200 && httpResponse.getStatusCode() <= 299) { 106 throw new ParseException("Unexpected HTTP status code, must not be 2xx"); 107 } 108 109 return new RequestObjectPOSTErrorResponse(httpResponse.getStatusCode()); 110 } 111}