001/* 002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thomas Roger 018 * 019 */ 020 021package org.nuxeo.ecm.platform.oauth2; 022 023/** 024 * @since 9.2 025 */ 026public class OAuth2Error { 027 028 public static final String INVALID_REQUEST = "invalid_request"; 029 030 public static final String INVALID_GRANT = "invalid_grant"; 031 032 public static final String UNAUTHORIZED_CLIENT = "unauthorized_client"; 033 034 public static final String ACCESS_DENIED = "access_denied"; 035 036 public static final String UNSUPPORTED_RESPONSE_TYPE = "unsupported_response_type"; 037 038 public static final String INVALID_SCOPE = "invalid_scope"; 039 040 public static final String SERVER_ERROR = "server_error"; 041 042 public static final String TEMPORARILY_UNAVAILABLE = "temporarily_unavailable"; 043 044 protected final String id; 045 046 protected final String description; 047 048 protected OAuth2Error(String id, String description) { 049 this.id = id; 050 this.description = description; 051 } 052 053 public String getId() { 054 return id; 055 } 056 057 public String getDescription() { 058 return description; 059 } 060 061 public static OAuth2Error invalidRequest(String description) { 062 return new OAuth2Error(INVALID_REQUEST, description); 063 } 064 065 public static OAuth2Error invalidRequest() { 066 return invalidRequest(null); 067 } 068 069 public static OAuth2Error invalidGrant(String description) { 070 return new OAuth2Error(INVALID_GRANT, description); 071 } 072 073 public static OAuth2Error invalidGrant() { 074 return invalidGrant(null); 075 } 076 077 public static OAuth2Error unauthorizedClient(String description) { 078 return new OAuth2Error(UNAUTHORIZED_CLIENT, description); 079 } 080 081 public static OAuth2Error unauthorizedClient() { 082 return unauthorizedClient(null); 083 } 084 085 public static OAuth2Error accessDenied(String description) { 086 return new OAuth2Error(ACCESS_DENIED, description); 087 } 088 089 public static OAuth2Error accessDenied() { 090 return accessDenied(null); 091 } 092 093 public static OAuth2Error unsupportedResponseType(String description) { 094 return new OAuth2Error(UNSUPPORTED_RESPONSE_TYPE, description); 095 } 096 097 public static OAuth2Error unsupportedResponseType() { 098 return unsupportedResponseType(null); 099 } 100 101 public static OAuth2Error invalidScope(String description) { 102 return new OAuth2Error(INVALID_SCOPE, description); 103 } 104 105 public static OAuth2Error invalidScope() { 106 return invalidScope(null); 107 } 108 109 public static OAuth2Error serverError(String description) { 110 return new OAuth2Error(SERVER_ERROR, description); 111 } 112 113 public static OAuth2Error serverError() { 114 return serverError(null); 115 } 116 117 public static OAuth2Error temporarilyUnavailable(String description) { 118 return new OAuth2Error(TEMPORARILY_UNAVAILABLE, description); 119 } 120 121 public static OAuth2Error temporarilyUnavailable() { 122 return temporarilyUnavailable(null); 123 } 124}