Skip to content

Commit bbac85e

Browse files
Steve Riesenbergsjohnr
Steve Riesenberg
authored andcommitted
Reduce severity of invalid registrationId to warn
This prevents filling the log file with error messages when routine scans are being performed. Closes spring-projectsgh-11344
1 parent ae6fb8c commit bbac85e

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/DefaultOAuth2AuthorizationRequestResolver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private OAuth2AuthorizationRequest resolve(HttpServletRequest request, String re
149149
}
150150
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(registrationId);
151151
if (clientRegistration == null) {
152-
throw new IllegalArgumentException("Invalid Client Registration with Id: " + registrationId);
152+
throw new InvalidClientRegistrationIdException("Invalid Client Registration with Id: " + registrationId);
153153
}
154154
OAuth2AuthorizationRequest.Builder builder = getBuilder(clientRegistration);
155155

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2002-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.oauth2.client.web;
18+
19+
/**
20+
* @author Steve Riesenberg
21+
* @since 5.8
22+
*/
23+
class InvalidClientRegistrationIdException extends IllegalArgumentException {
24+
25+
/**
26+
* @param message the exception message
27+
*/
28+
InvalidClientRegistrationIdException(String message) {
29+
super(message);
30+
}
31+
32+
}

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationRequestRedirectFilter.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,15 @@ private void sendRedirectForAuthorization(HttpServletRequest request, HttpServle
230230

231231
private void unsuccessfulRedirectForAuthorization(HttpServletRequest request, HttpServletResponse response,
232232
Exception ex) throws IOException {
233-
this.logger.error(LogMessage.format("Authorization Request failed: %s", ex), ex);
233+
LogMessage message = LogMessage.format("Authorization Request failed: %s", ex);
234+
if (InvalidClientRegistrationIdException.class.isAssignableFrom(ex.getClass())) {
235+
// Log an invalid registrationId at WARN level to allow these errors to be
236+
// tuned separately from other errors
237+
this.logger.warn(message, ex);
238+
}
239+
else {
240+
this.logger.error(message, ex);
241+
}
234242
response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(),
235243
HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
236244
}

0 commit comments

Comments
 (0)