1
0
mirror of synced 2026-08-05 17:57:15 +00:00

Update exception variable names

Consistently use `ex` for caught exception and `cause` for Exception
constructor arguments.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-28 23:53:30 -07:00
committed by Rob Winch
parent e9130489a6
commit 8d80166aaf
194 changed files with 635 additions and 633 deletions
@@ -36,10 +36,10 @@ public class AccessDeniedException extends RuntimeException {
* Constructs an <code>AccessDeniedException</code> with the specified message and
* root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public AccessDeniedException(String msg, Throwable t) {
super(msg, t);
public AccessDeniedException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -39,10 +39,10 @@ public class AuthorizationServiceException extends AccessDeniedException {
* Constructs an <code>AuthorizationServiceException</code> with the specified message
* and root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public AuthorizationServiceException(String msg, Throwable t) {
super(msg, t);
public AuthorizationServiceException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -25,8 +25,9 @@ public final class ExpressionUtils {
try {
return expr.getValue(ctx, Boolean.class);
}
catch (EvaluationException e) {
throw new IllegalArgumentException("Failed to evaluate expression '" + expr.getExpressionString() + "'", e);
catch (EvaluationException ex) {
throw new IllegalArgumentException("Failed to evaluate expression '" + expr.getExpressionString() + "'",
ex);
}
}
@@ -54,8 +54,8 @@ public class ExpressionBasedAnnotationAttributeFactory implements PrePostInvocat
: parser.parseExpression(preFilterAttribute);
return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression);
}
catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
catch (ParseException ex) {
throw new IllegalArgumentException("Failed to parse expression '" + ex.getExpressionString() + "'", ex);
}
}
@@ -73,8 +73,8 @@ public class ExpressionBasedAnnotationAttributeFactory implements PrePostInvocat
return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression);
}
}
catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
catch (ParseException ex) {
throw new IllegalArgumentException("Failed to parse expression '" + ex.getExpressionString() + "'", ex);
}
return null;
@@ -36,10 +36,10 @@ public class AccountExpiredException extends AccountStatusException {
* Constructs a <code>AccountExpiredException</code> with the specified message and
* root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public AccountExpiredException(String msg, Throwable t) {
super(msg, t);
public AccountExpiredException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -29,8 +29,8 @@ public abstract class AccountStatusException extends AuthenticationException {
super(msg);
}
public AccountStatusException(String msg, Throwable t) {
super(msg, t);
public AccountStatusException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -41,10 +41,10 @@ public class AuthenticationCredentialsNotFoundException extends AuthenticationEx
* Constructs an <code>AuthenticationCredentialsNotFoundException</code> with the
* specified message and root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public AuthenticationCredentialsNotFoundException(String msg, Throwable t) {
super(msg, t);
public AuthenticationCredentialsNotFoundException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -42,10 +42,10 @@ public class AuthenticationServiceException extends AuthenticationException {
* Constructs an <code>AuthenticationServiceException</code> with the specified
* message and root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public AuthenticationServiceException(String msg, Throwable t) {
super(msg, t);
public AuthenticationServiceException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -38,10 +38,10 @@ public class BadCredentialsException extends AuthenticationException {
* Constructs a <code>BadCredentialsException</code> with the specified message and
* root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public BadCredentialsException(String msg, Throwable t) {
super(msg, t);
public BadCredentialsException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -36,10 +36,10 @@ public class CredentialsExpiredException extends AccountStatusException {
* Constructs a <code>CredentialsExpiredException</code> with the specified message
* and root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public CredentialsExpiredException(String msg, Throwable t) {
super(msg, t);
public CredentialsExpiredException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -155,7 +155,7 @@ public class DefaultAuthenticationEventPublisher
Assert.isAssignable(AbstractAuthenticationFailureEvent.class, clazz);
addMapping((String) exceptionClass, (Class<? extends AbstractAuthenticationFailureEvent>) clazz);
}
catch (ClassNotFoundException e) {
catch (ClassNotFoundException ex) {
throw new RuntimeException("Failed to load authentication event class " + eventClass);
}
}
@@ -194,7 +194,7 @@ public class DefaultAuthenticationEventPublisher
this.defaultAuthenticationFailureEventConstructor = defaultAuthenticationFailureEventClass
.getConstructor(Authentication.class, AuthenticationException.class);
}
catch (NoSuchMethodException e) {
catch (NoSuchMethodException ex) {
throw new RuntimeException("Default Authentication Failure event class "
+ defaultAuthenticationFailureEventClass.getName() + " has no suitable constructor");
}
@@ -206,7 +206,7 @@ public class DefaultAuthenticationEventPublisher
.getConstructor(Authentication.class, AuthenticationException.class);
this.exceptionMappings.put(exceptionClass, constructor);
}
catch (NoSuchMethodException e) {
catch (NoSuchMethodException ex) {
throw new RuntimeException(
"Authentication event class " + eventClass.getName() + " has no suitable constructor");
}
@@ -36,10 +36,10 @@ public class DisabledException extends AccountStatusException {
* Constructs a <code>DisabledException</code> with the specified message and root
* cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public DisabledException(String msg, Throwable t) {
super(msg, t);
public DisabledException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -46,10 +46,10 @@ public class InsufficientAuthenticationException extends AuthenticationException
* Constructs an <code>InsufficientAuthenticationException</code> with the specified
* message and root cause.
* @param msg the detail message
* @param t root cause
* @param cause root cause
*/
public InsufficientAuthenticationException(String msg, Throwable t) {
super(msg, t);
public InsufficientAuthenticationException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -36,10 +36,10 @@ public class LockedException extends AccountStatusException {
* Constructs a <code>LockedException</code> with the specified message and root
* cause.
* @param msg the detail message.
* @param t root cause
* @param cause root cause
*/
public LockedException(String msg, Throwable t) {
super(msg, t);
public LockedException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -188,14 +188,14 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
break;
}
}
catch (AccountStatusException | InternalAuthenticationServiceException e) {
prepareException(e, authentication);
catch (AccountStatusException | InternalAuthenticationServiceException ex) {
prepareException(ex, authentication);
// SEC-546: Avoid polling additional providers if auth failure is due to
// invalid account status
throw e;
throw ex;
}
catch (AuthenticationException e) {
lastException = e;
catch (AuthenticationException ex) {
lastException = ex;
}
}
@@ -205,15 +205,15 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
parentResult = this.parent.authenticate(authentication);
result = parentResult;
}
catch (ProviderNotFoundException e) {
catch (ProviderNotFoundException ex) {
// ignore as we will throw below if no other exception occurred prior to
// calling parent and the parent
// may throw ProviderNotFound even though a provider in the child already
// handled the request
}
catch (AuthenticationException e) {
parentException = e;
lastException = e;
catch (AuthenticationException ex) {
parentException = ex;
lastException = ex;
}
}
@@ -256,8 +256,8 @@ public abstract class AbstractJaasAuthenticationProvider implements Authenticati
+ "The LoginContext is unavailable");
}
}
catch (LoginException e) {
this.log.warn("Error error logging out of LoginContext", e);
catch (LoginException ex) {
this.log.warn("Error error logging out of LoginContext", ex);
}
}
}
@@ -30,8 +30,8 @@ import org.springframework.security.core.AuthenticationException;
public class DefaultLoginExceptionResolver implements LoginExceptionResolver {
@Override
public AuthenticationException resolveException(LoginException e) {
return new AuthenticationServiceException(e.getMessage(), e);
public AuthenticationException resolveException(LoginException ex) {
return new AuthenticationServiceException(ex.getMessage(), ex);
}
}
@@ -223,7 +223,7 @@ public class JaasAuthenticationProvider extends AbstractJaasAuthenticationProvid
return new URL("file", "", loginConfigPath).toString();
}
catch (IOException e) {
catch (IOException ex) {
// SEC-1700: May be inside a jar
return this.loginConfig.getURL().toString();
}
@@ -34,10 +34,10 @@ public interface LoginExceptionResolver {
/**
* Translates a Jaas LoginException to an SpringSecurityException.
* @param e The LoginException thrown by the configured LoginModule.
* @param ex The LoginException thrown by the configured LoginModule.
* @return The AuthenticationException that the JaasAuthenticationProvider should
* throw.
*/
AuthenticationException resolveException(LoginException e);
AuthenticationException resolveException(LoginException ex);
}
@@ -82,8 +82,8 @@ public class RsaKeyConverters {
try {
return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(pkcs8));
}
catch (Exception e) {
throw new IllegalArgumentException(e);
catch (Exception ex) {
throw new IllegalArgumentException(ex);
}
};
}
@@ -115,8 +115,8 @@ public class RsaKeyConverters {
try {
return (RSAPublicKey) keyFactory.generatePublic(new X509EncodedKeySpec(x509));
}
catch (Exception e) {
throw new IllegalArgumentException(e);
catch (Exception ex) {
throw new IllegalArgumentException(ex);
}
};
}
@@ -130,8 +130,8 @@ public class RsaKeyConverters {
try {
return KeyFactory.getInstance("RSA");
}
catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException(ex);
}
}
@@ -28,10 +28,10 @@ public abstract class AuthenticationException extends RuntimeException {
* Constructs an {@code AuthenticationException} with the specified message and root
* cause.
* @param msg the detail message
* @param t the root cause
* @param cause the root cause
*/
public AuthenticationException(String msg, Throwable t) {
super(msg, t);
public AuthenticationException(String msg, Throwable cause) {
super(msg, cause);
}
/**
@@ -108,7 +108,7 @@ public class SpringSecurityCoreVersion {
properties.load(SpringSecurityCoreVersion.class.getClassLoader()
.getResourceAsStream("META-INF/spring-security.versions"));
}
catch (IOException | NullPointerException e) {
catch (IOException | NullPointerException ex) {
return null;
}
return properties.getProperty("org.springframework:spring-core");
@@ -43,8 +43,8 @@ public abstract class Sha512DigestUtils {
try {
return MessageDigest.getInstance("SHA-512");
}
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage());
catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex.getMessage());
}
}
@@ -38,10 +38,10 @@ public class UsernameNotFoundException extends AuthenticationException {
* Constructs a {@code UsernameNotFoundException} with the specified message and root
* cause.
* @param msg the detail message.
* @param t root cause
* @param cause root cause
*/
public UsernameNotFoundException(String msg, Throwable t) {
super(msg, t);
public UsernameNotFoundException(String msg, Throwable cause) {
super(msg, cause);
}
}
@@ -107,9 +107,9 @@ public final class SecurityJackson2Modules {
instance = securityModule.newInstance();
}
}
catch (Exception e) {
catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Cannot load module " + className, e);
logger.debug("Cannot load module " + className, ex);
}
}
return instance;
@@ -137,7 +137,7 @@ public final class MethodInvocationUtils {
try {
method = clazz.getMethod(methodName, classArgs);
}
catch (NoSuchMethodException e) {
catch (NoSuchMethodException ex) {
return null;
}
@@ -117,21 +117,21 @@ public class RoleHierarchyImplTests {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_A");
fail("Cycle in role hierarchy was not detected!");
}
catch (CycleInRoleHierarchyException e) {
catch (CycleInRoleHierarchyException ex) {
}
try {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_A");
fail("Cycle in role hierarchy was not detected!");
}
catch (CycleInRoleHierarchyException e) {
catch (CycleInRoleHierarchyException ex) {
}
try {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_A");
fail("Cycle in role hierarchy was not detected!");
}
catch (CycleInRoleHierarchyException e) {
catch (CycleInRoleHierarchyException ex) {
}
try {
@@ -139,14 +139,14 @@ public class RoleHierarchyImplTests {
"ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_E\nROLE_E > ROLE_D\nROLE_D > ROLE_B");
fail("Cycle in role hierarchy was not detected!");
}
catch (CycleInRoleHierarchyException e) {
catch (CycleInRoleHierarchyException ex) {
}
try {
roleHierarchyImpl.setHierarchy("ROLE_C > ROLE_B\nROLE_B > ROLE_A\nROLE_A > ROLE_B");
fail("Cycle in role hierarchy was not detected!");
}
catch (CycleInRoleHierarchyException e) {
catch (CycleInRoleHierarchyException ex) {
}
}
@@ -157,7 +157,7 @@ public class RoleHierarchyImplTests {
try {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_A > ROLE_C\nROLE_C > ROLE_D\nROLE_B > ROLE_D");
}
catch (CycleInRoleHierarchyException e) {
catch (CycleInRoleHierarchyException ex) {
fail("A cycle in role hierarchy was incorrectly detected!");
}
}
@@ -271,8 +271,8 @@ public class ProviderManagerTests {
mgr.authenticate(authReq);
fail("Expected exception");
}
catch (BadCredentialsException e) {
assertThat(e).isSameAs(expected);
catch (BadCredentialsException ex) {
assertThat(ex).isSameAs(expected);
}
}
@@ -289,8 +289,8 @@ public class ProviderManagerTests {
mgr.authenticate(authReq);
fail("Expected exception");
}
catch (LockedException e) {
assertThat(e).isSameAs(expected);
catch (LockedException ex) {
assertThat(ex).isSameAs(expected);
}
verify(publisher).publishAuthenticationFailure(expected, authReq);
}
@@ -329,18 +329,18 @@ public class ProviderManagerTests {
childMgr.authenticate(authReq);
fail("Expected exception");
}
catch (BadCredentialsException e) {
assertThat(e).isSameAs(badCredentialsExParent);
catch (BadCredentialsException ex) {
assertThat(ex).isSameAs(badCredentialsExParent);
}
verify(publisher).publishAuthenticationFailure(badCredentialsExParent, authReq); // Parent
// publishes
verifyNoMoreInteractions(publisher); // Child should not publish (duplicate event)
}
private AuthenticationProvider createProviderWhichThrows(final AuthenticationException e) {
private AuthenticationProvider createProviderWhichThrows(final AuthenticationException ex) {
AuthenticationProvider provider = mock(AuthenticationProvider.class);
given(provider.supports(any(Class.class))).willReturn(true);
given(provider.authenticate(any(Authentication.class))).willThrow(e);
given(provider.authenticate(any(Authentication.class))).willThrow(ex);
return provider;
}
@@ -77,7 +77,7 @@ public class JaasAuthenticationProviderTests {
this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "asdf"));
fail("LoginException should have been thrown for the bad password");
}
catch (AuthenticationException e) {
catch (AuthenticationException ex) {
}
assertThat(this.eventCheck.failedEvent).as("Failure event not fired").isNotNull();
@@ -92,7 +92,7 @@ public class JaasAuthenticationProviderTests {
this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("asdf", "password"));
fail("LoginException should have been thrown for the bad user");
}
catch (AuthenticationException e) {
catch (AuthenticationException ex) {
}
assertThat(this.eventCheck.failedEvent).as("Failure event not fired").isNotNull();
@@ -241,9 +241,9 @@ public class JaasAuthenticationProviderTests {
try {
this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "password"));
}
catch (LockedException e) {
catch (LockedException ex) {
}
catch (Exception e) {
catch (Exception ex) {
fail("LockedException should have been thrown and caught");
}
}
@@ -75,7 +75,7 @@ public class SecurityContextLoginModuleTests {
this.module.login();
fail("LoginException expected, there is no Authentication in the SecurityContext");
}
catch (LoginException e) {
catch (LoginException ex) {
}
}
@@ -107,7 +107,7 @@ public class SecurityContextLoginModuleTests {
this.module.login();
fail("LoginException expected, the authentication is null in the SecurityContext");
}
catch (Exception e) {
catch (Exception ex) {
}
}
@@ -63,8 +63,8 @@ public class TestLoginModule implements LoginModule {
this.password = new String(passwordCallback.getPassword());
this.user = nameCallback.getName();
}
catch (Exception e) {
throw new RuntimeException(e);
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@@ -40,8 +40,8 @@ public class KeyBasedPersistenceTokenServiceTests {
service.setSecureRandom(rnd);
service.afterPropertiesSet();
}
catch (Exception e) {
throw new RuntimeException(e);
catch (Exception ex) {
throw new RuntimeException(ex);
}
return service;
}