Ver Fonte

Polish PublicClientAuthenticationConverter

Commit 5c31fb1b7e7a0efbb60cb7aa34762ad5577eba45
Joe Grandja há 5 anos atrás
pai
commit
e49d4a79b4

+ 2 - 4
oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/PublicClientAuthenticationConverter.java

@@ -52,10 +52,8 @@ public class PublicClientAuthenticationConverter implements AuthenticationConver
 
 		// client_id (REQUIRED for public clients)
 		String clientId = parameters.getFirst(OAuth2ParameterNames.CLIENT_ID);
-		if (!StringUtils.hasText(clientId)) {
-			return null;
-		}
-		if (parameters.get(OAuth2ParameterNames.CLIENT_ID).size() != 1) {
+		if (!StringUtils.hasText(clientId) ||
+				parameters.get(OAuth2ParameterNames.CLIENT_ID).size() != 1) {
 			throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST));
 		}
 

+ 6 - 3
oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/web/PublicClientAuthenticationConverterTests.java

@@ -45,11 +45,14 @@ public class PublicClientAuthenticationConverterTests {
 	}
 
 	@Test
-	public void convertWhenMissingClientIdThenReturnNull() {
+	public void convertWhenMissingClientIdThenInvalidRequestError() {
 		MockHttpServletRequest request = createPkceTokenRequest();
 		request.removeParameter(OAuth2ParameterNames.CLIENT_ID);
-		Authentication authentication = this.converter.convert(request);
-		assertThat(authentication).isNull();
+		assertThatThrownBy(() -> this.converter.convert(request))
+				.isInstanceOf(OAuth2AuthenticationException.class)
+				.extracting(ex -> ((OAuth2AuthenticationException) ex).getError())
+				.extracting("errorCode")
+				.isEqualTo(OAuth2ErrorCodes.INVALID_REQUEST);
 	}
 
 	@Test