瀏覽代碼

Externalize error codes from OAuth2Error

Fixes gh-4606
Joe Grandja 7 年之前
父節點
當前提交
401c84b3f2

+ 2 - 2
oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/AuthorizationCodeAuthenticationFilterTests.java

@@ -33,7 +33,7 @@ import org.springframework.security.oauth2.client.authentication.OAuth2UserAuthe
 import org.springframework.security.oauth2.client.registration.ClientRegistration;
 import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
 import org.springframework.security.oauth2.core.AccessToken;
-import org.springframework.security.oauth2.core.OAuth2Error;
+import org.springframework.security.oauth2.core.OAuth2ErrorCode;
 import org.springframework.security.oauth2.core.endpoint.AuthorizationRequest;
 import org.springframework.security.oauth2.core.endpoint.OAuth2Parameter;
 import org.springframework.security.oauth2.core.user.OAuth2User;
@@ -82,7 +82,7 @@ public class AuthorizationCodeAuthenticationFilterTests {
 		filter.setAuthenticationFailureHandler(failureHandler);
 
 		MockHttpServletRequest request = this.setupRequest(clientRegistration);
-		String errorCode = OAuth2Error.INVALID_GRANT_ERROR_CODE;
+		String errorCode = OAuth2ErrorCode.INVALID_GRANT;
 		request.addParameter(OAuth2Parameter.ERROR, errorCode);
 		request.addParameter(OAuth2Parameter.STATE, "some state");
 		MockHttpServletResponse response = new MockHttpServletResponse();

+ 0 - 8
oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/OAuth2Error.java

@@ -31,14 +31,6 @@ import org.springframework.util.Assert;
  * @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-11.4">Section 11.4 OAuth Extensions Error Registry</a>
  */
 public final class OAuth2Error {
-	// Standard error codes
-	public static final String INVALID_REQUEST_ERROR_CODE = "invalid_request";
-	public static final String INVALID_CLIENT_ERROR_CODE = "invalid_client";
-	public static final String INVALID_GRANT_ERROR_CODE = "invalid_grant";
-	public static final String UNAUTHORIZED_CLIENT_ERROR_CODE = "unauthorized_client";
-	public static final String UNSUPPORTED_GRANT_TYPE_ERROR_CODE = "unsupported_grant_type";
-	public static final String INVALID_SCOPE_ERROR_CODE = "invalid_scope";
-
 	private final String errorCode;
 	private final String description;
 	private final String uri;

+ 46 - 0
oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/OAuth2ErrorCode.java

@@ -0,0 +1,46 @@
+/*
+ * Copyright 2012-2017 the original author or authors.
+ *
+ * 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 org.springframework.security.oauth2.core;
+
+/**
+ * Standard error codes defined by the <i>OAuth 2.0 Authorization Framework</i>.
+ *
+ * @author Joe Grandja
+ * @since 5.0
+ */
+public interface OAuth2ErrorCode {
+
+	String INVALID_REQUEST = "invalid_request";
+
+	String UNAUTHORIZED_CLIENT = "unauthorized_client";
+
+	String ACCESS_DENIED = "access_denied";
+
+	String UNSUPPORTED_RESPONSE_TYPE = "unsupported_response_type";
+
+	String INVALID_SCOPE = "invalid_scope";
+
+	String SERVER_ERROR = "server_error";
+
+	String TEMPORARILY_UNAVAILABLE = "temporarily_unavailable";
+
+	String INVALID_CLIENT = "invalid_client";
+
+	String INVALID_GRANT = "invalid_grant";
+
+	String UNSUPPORTED_GRANT_TYPE = "unsupported_grant_type";
+
+}