All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.authlete.common.dto.RevocationResponse Maven / Gradle / Ivy

Go to download

Authlete Java library used commonly by service implementations and the Authlete server.

There is a newer version: 4.15
Show newest version
/*
 * Copyright (C) 2015 Authlete, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.authlete.common.dto;


/**
 * Response from Authlete's {@code /auth/revocation} API.
 *
 * 

* Authlete's {@code /auth/revocation} API returns JSON which can * be mapped to this class. The service implementation should retrieve the * value of {@code "action"} from the response and take the following steps * according to the value. *

* *
*
{@link Action#INVALID_CLIENT INVALID_CLIENT}
*
*

* When the value of {@code "action"} is {@code "INVALID_CLIENT"}, it means * that authentication of the client failed. In this case, the HTTP status * of the response to the client application is either {@code "400 Bad * Request"} or {@code "401 Unauthorized"}. The description about {@code * "invalid_client"} shown below is an excerpt from RFC 6749. *

*
*
*
invalid_client
*
*

* Client authentication failed (e.g., unknown client, no client * authentication included, or unsupported authentication method). * The authorization server MAY return an HTTP 401 (Unauthorized) * status code to indicate which HTTP authentication schemes are * supported. If the client attempted to authenticate via the * "Authorization" request header field, the authorization server * MUST respond with an HTTP 401 (Unauthorized) status code and * include the "WWW-Authenticate" response header field matching the * authentication scheme used by the client. *

*
*
*
*

* In either case, the JSON string returned by {@link #getResponseContent()} * can be used as the entity body of the response to the client application. *

* *

* The following illustrates the response which the service implementation * should generate and return to the client application. *

* *
 * HTTP/1.1 400 Bad Request
 * Content-Type: application/json
 * Cache-Control: no-store
 * Pragma: no-cache
 *
 * (The value returned from {@link #getResponseContent()})
* *
 * HTTP/1.1 401 Unauthorized
 * WWW-Authenticate: (challenge)
 * Content-Type: application/json
 * Cache-Control: no-store
 * Pragma: no-cache
 *
 * (The value returned from {@link #getResponseContent()})
*
* *
{@link Action#INTERNAL_SERVER_ERROR INTERNAL_SERVER_ERROR}
*
*

* When the value of {@code "action"} is {@code "INTERNAL_SERVER_ERROR"}, * it means that the request from the service implementation * ({@link RevocationRequest}) was wrong or that an error occurred in Authlete. *

* *

* In either case, from the viewpoint of the client application, it is an * error on the server side. Therefore, the service implementation should * generate a response to the client application with the HTTP status of * {@code "500 Internal Server Error"}. *

* *

* {@link #getResponseContent()} returns a JSON string which describes * the error, so it can be used as the entity body of the response. *

* *

* The following illustrates the response which the service implementation * should generate and return to the client application. *

* *
 * HTTP/1.1 500 Internal Server Error
 * Content-Type: application/json
 * Cache-Control: no-store
 * Pragma: no-cache
 *
 * (The value returned from {@link #getResponseContent()})
*
* *
{@link Action#BAD_REQUEST BAD_REQUEST}
*
*

* When the value of {@code "action"} is {@code "BAD_REQUEST"}, it means * that the request from the client application is invalid. *

* *

* The HTTP status of the response returned to the client application * must be {@code "400 Bad Request"} and the content type must be * {@code "application/json"}. RFC 7009, 2.2.1. Error Response states "The error presentation conforms to * the definition in Section 5.2 of [RFC 6749]." *

* *

* {@link #getResponseContent()} returns a JSON string which describes * the error, so it can be used as the entity body of the response. *

* *

* The following illustrates the response which the service implementation * should generate and return to the client application. *

* *
 * HTTP/1.1 400 Bad Request
 * Content-Type: application/json
 * Cache-Control: no-store
 * Pragma: no-cache
 *
 * (The value returned from {@link #getResponseContent()})
*
* *
{@link Action#OK OK}
*
*

* When the value of {@code "action"} is {@code "OK"}, it means that * the request from the client application is valid and the presented * token has been revoked successfully or that the client submitted an * invalid token. Note that invalid tokens do not cause an error. See * 2.2. * Revocation Response for details. *

* *

* The HTTP status of the response returned to the client application * must be {@code "200 OK"}. *

* *

* If the original request from the client application contains * {@code callback} request parameter and its value is not empty, * the content type should be {@code "application/javascript"} and * the content should be a JavaScript snippet for JSONP. *

* *

* {@link #getResponseContent()} returns a JavaScript snippet if the * original request from the client application contains {@code callback} * request parameter and its value is not empty. Otherwise, {@code * getResponseContent()} returns {@code null}. *

* *

* The following illustrates the response which the service implementation * should generate and return to the client application. *

* *
 * HTTP/1.1 200 OK
 * Content-Type: application/javascript
 * Cache-Control: no-store
 * Pragma: no-cache
 *
 * (The value returned from {@link #getResponseContent()})
*
*
* * @see RFC 7009, OAuth 2.0 Token Revocation * * @author Takahiko Kawasaki * * @since 1.16 * @since Authlete 1.1 */ public class RevocationResponse extends ApiResponse { private static final long serialVersionUID = 1L; /** * The next action that the service implementation should take. */ public enum Action { /** * Authentication of the client application failed. The service * implementation should return either {@code "400 Bad Request"} * or {@code "401 Unauthorized"} to the client application. */ INVALID_CLIENT, /** * The request from the service was wrong or an error occurred * in Authlete. The service implementation should return {@code * "500 Internal Server Error"} to the client application. */ INTERNAL_SERVER_ERROR, /** * The request from the client was wrong. The service implementation * should return {@code "400 Bad Request"} to the client application. */ BAD_REQUEST, /** * The request from the client was valid. The service implementation * should return {@code "200 OK"} to the client application. */ OK } private static final String SUMMARY_FORMAT = "action=%s, responseContent=%s"; private Action action; private String responseContent; /** * Get the next action that the service implementation should take. */ public Action getAction() { return action; } /** * Set the next action that the service implementation should take. */ public void setAction(Action action) { this.action = action; } /** * Get the response content which can be used as the entity body * of the response returned to the client application. */ public String getResponseContent() { return responseContent; } /** * Set the response content which can be used as the entity body * of the response returned to the client application. */ public void setResponseContent(String responseContent) { this.responseContent = responseContent; } /** * Get the summary of this instance. */ public String summarize() { return String.format(SUMMARY_FORMAT, action, responseContent); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy