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

View File

@ -34,10 +34,10 @@ public class IdentityUnavailableException extends RuntimeException {
* Constructs an <code>IdentityUnavailableException</code> with the specified message * Constructs an <code>IdentityUnavailableException</code> with the specified message
* and root cause. * and root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public IdentityUnavailableException(String msg, Throwable t) { public IdentityUnavailableException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -77,8 +77,8 @@ public class ObjectIdentityImpl implements ObjectIdentity {
Method method = typeClass.getMethod("getId", new Class[] {}); Method method = typeClass.getMethod("getId", new Class[] {});
result = method.invoke(object); result = method.invoke(object);
} }
catch (Exception e) { catch (Exception ex) {
throw new IdentityUnavailableException("Could not extract identity from object " + object, e); throw new IdentityUnavailableException("Could not extract identity from object " + object, ex);
} }
Assert.notNull(result, "getId() is required to return a non-null value"); Assert.notNull(result, "getId() is required to return a non-null value");

View File

@ -85,8 +85,8 @@ class AclClassIdUtils {
try { try {
hasClassIdType = classIdTypeFrom(resultSet) != null; hasClassIdType = classIdTypeFrom(resultSet) != null;
} }
catch (SQLException e) { catch (SQLException ex) {
log.debug("Unable to obtain the class id type", e); log.debug("Unable to obtain the class id type", ex);
} }
return hasClassIdType; return hasClassIdType;
} }
@ -101,8 +101,8 @@ class AclClassIdUtils {
try { try {
targetType = Class.forName(className); targetType = Class.forName(className);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException ex) {
log.debug("Unable to find class id type on classpath", e); log.debug("Unable to find class id type on classpath", ex);
} }
} }
return targetType; return targetType;

View File

@ -194,8 +194,8 @@ public class BasicLookupStrategy implements LookupStrategy {
try { try {
return (List<AccessControlEntryImpl>) this.fieldAces.get(acl); return (List<AccessControlEntryImpl>) this.fieldAces.get(acl);
} }
catch (IllegalAccessException e) { catch (IllegalAccessException ex) {
throw new IllegalStateException("Could not obtain AclImpl.aces field", e); throw new IllegalStateException("Could not obtain AclImpl.aces field", ex);
} }
} }
@ -203,8 +203,8 @@ public class BasicLookupStrategy implements LookupStrategy {
try { try {
this.fieldAcl.set(ace, acl); this.fieldAcl.set(ace, acl);
} }
catch (IllegalAccessException e) { catch (IllegalAccessException ex) {
throw new IllegalStateException("Could not or set AclImpl on AccessControlEntryImpl fields", e); throw new IllegalStateException("Could not or set AclImpl on AccessControlEntryImpl fields", ex);
} }
} }
@ -212,8 +212,8 @@ public class BasicLookupStrategy implements LookupStrategy {
try { try {
this.fieldAces.set(acl, aces); this.fieldAces.set(acl, aces);
} }
catch (IllegalAccessException e) { catch (IllegalAccessException ex) {
throw new IllegalStateException("Could not set AclImpl entries", e); throw new IllegalStateException("Could not set AclImpl entries", ex);
} }
} }

View File

@ -34,10 +34,10 @@ public class AlreadyExistsException extends AclDataAccessException {
* Constructs an <code>AlreadyExistsException</code> with the specified message and * Constructs an <code>AlreadyExistsException</code> with the specified message and
* root cause. * root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public AlreadyExistsException(String msg, Throwable t) { public AlreadyExistsException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -34,10 +34,10 @@ public class ChildrenExistException extends AclDataAccessException {
* Constructs an <code>ChildrenExistException</code> with the specified message and * Constructs an <code>ChildrenExistException</code> with the specified message and
* root cause. * root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public ChildrenExistException(String msg, Throwable t) { public ChildrenExistException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -34,10 +34,10 @@ public class NotFoundException extends AclDataAccessException {
* Constructs an <code>NotFoundException</code> with the specified message and root * Constructs an <code>NotFoundException</code> with the specified message and root
* cause. * cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public NotFoundException(String msg, Throwable t) { public NotFoundException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -36,10 +36,10 @@ public class UnloadedSidException extends AclDataAccessException {
* Constructs an <code>NotFoundException</code> with the specified message and root * Constructs an <code>NotFoundException</code> with the specified message and root
* cause. * cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public UnloadedSidException(String msg, Throwable t) { public UnloadedSidException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -628,8 +628,8 @@ public class AclImplTests {
((AuditableAccessControlEntry) ac).isAuditFailure())); ((AuditableAccessControlEntry) ac).isAuditFailure()));
} }
} }
catch (IllegalAccessException e) { catch (IllegalAccessException ex) {
e.printStackTrace(); ex.printStackTrace();
} }
return acl; return acl;

View File

@ -121,9 +121,9 @@ public class JdbcMutableAclServiceTests extends AbstractTransactionalJUnit4Sprin
// new DatabaseSeeder(dataSource, new // new DatabaseSeeder(dataSource, new
// ClassPathResource("createAclSchemaPostgres.sql")); // ClassPathResource("createAclSchemaPostgres.sql"));
} }
catch (Exception e) { catch (Exception ex) {
e.printStackTrace(); ex.printStackTrace();
throw e; throw ex;
} }
} }

View File

@ -156,8 +156,8 @@ public class CasAuthenticationProvider implements AuthenticationProvider, Initia
return new CasAuthenticationToken(this.key, userDetails, authentication.getCredentials(), return new CasAuthenticationToken(this.key, userDetails, authentication.getCredentials(),
this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()), userDetails, assertion); this.authoritiesMapper.mapAuthorities(userDetails.getAuthorities()), userDetails, assertion);
} }
catch (final TicketValidationException e) { catch (TicketValidationException ex) {
throw new BadCredentialsException(e.getMessage(), e); throw new BadCredentialsException(ex.getMessage(), ex);
} }
} }

View File

@ -74,8 +74,8 @@ public class ServiceAuthenticationDetailsSource
return new DefaultServiceAuthenticationDetails(this.serviceProperties.getService(), context, return new DefaultServiceAuthenticationDetails(this.serviceProperties.getService(), context,
this.artifactPattern); this.artifactPattern);
} }
catch (MalformedURLException e) { catch (MalformedURLException ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
} }

View File

@ -102,8 +102,8 @@ public abstract class AbstractConfiguredSecurityBuilder<O, B extends SecurityBui
try { try {
return build(); return build();
} }
catch (Exception e) { catch (Exception ex) {
this.logger.debug("Failed to perform build. Returning null", e); this.logger.debug("Failed to perform build. Returning null", ex);
return null; return null;
} }
} }

View File

@ -595,7 +595,7 @@ public class LdapAuthenticationProviderConfigurer<B extends ProviderManagerBuild
try (ServerSocket serverSocket = new ServerSocket(DEFAULT_PORT)) { try (ServerSocket serverSocket = new ServerSocket(DEFAULT_PORT)) {
return serverSocket.getLocalPort(); return serverSocket.getLocalPort();
} }
catch (IOException e) { catch (IOException ex) {
return RANDOM_PORT; return RANDOM_PORT;
} }
} }

View File

@ -63,9 +63,9 @@ final class AutowireBeanFactoryObjectPostProcessor
try { try {
result = (T) this.autowireBeanFactory.initializeBean(object, object.toString()); result = (T) this.autowireBeanFactory.initializeBean(object, object.toString());
} }
catch (RuntimeException e) { catch (RuntimeException ex) {
Class<?> type = object.getClass(); Class<?> type = object.getClass();
throw new RuntimeException("Could not postProcess " + object + " of type " + type, e); throw new RuntimeException("Could not postProcess " + object + " of type " + type, ex);
} }
this.autowireBeanFactory.autowireBean(object); this.autowireBeanFactory.autowireBean(object);
if (result instanceof DisposableBean) { if (result instanceof DisposableBean) {

View File

@ -153,8 +153,8 @@ public class GlobalMethodSecurityConfiguration implements ImportAware, SmartInit
try { try {
initializeMethodSecurityInterceptor(); initializeMethodSecurityInterceptor();
} }
catch (Exception e) { catch (Exception ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
PermissionEvaluator permissionEvaluator = getSingleBeanOrNull(PermissionEvaluator.class); PermissionEvaluator permissionEvaluator = getSingleBeanOrNull(PermissionEvaluator.class);
@ -182,7 +182,7 @@ public class GlobalMethodSecurityConfiguration implements ImportAware, SmartInit
try { try {
return this.context.getBean(type); return this.context.getBean(type);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
} }
return null; return null;
} }

View File

@ -311,26 +311,26 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
try { try {
this.defaultWebSecurityExpressionHandler.setRoleHierarchy(applicationContext.getBean(RoleHierarchy.class)); this.defaultWebSecurityExpressionHandler.setRoleHierarchy(applicationContext.getBean(RoleHierarchy.class));
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
} }
try { try {
this.defaultWebSecurityExpressionHandler this.defaultWebSecurityExpressionHandler
.setPermissionEvaluator(applicationContext.getBean(PermissionEvaluator.class)); .setPermissionEvaluator(applicationContext.getBean(PermissionEvaluator.class));
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
} }
this.ignoredRequestRegistry = new IgnoredRequestConfigurer(applicationContext); this.ignoredRequestRegistry = new IgnoredRequestConfigurer(applicationContext);
try { try {
this.httpFirewall = applicationContext.getBean(HttpFirewall.class); this.httpFirewall = applicationContext.getBean(HttpFirewall.class);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
} }
try { try {
this.requestRejectedHandler = applicationContext.getBean(RequestRejectedHandler.class); this.requestRejectedHandler = applicationContext.getBean(RequestRejectedHandler.class);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
} }
} }

View File

@ -165,8 +165,8 @@ class SecurityReactorContextConfiguration {
} }
@Override @Override
public void onError(Throwable t) { public void onError(Throwable ex) {
this.delegate.onError(t); this.delegate.onError(ex);
} }
@Override @Override

View File

@ -136,7 +136,7 @@ public final class RequestCacheConfigurer<H extends HttpSecurityBuilder<H>>
try { try {
return context.getBean(type); return context.getBean(type);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
return null; return null;
} }
} }

View File

@ -560,7 +560,7 @@ public final class SessionManagementConfigurer<H extends HttpSecurityBuilder<H>>
try { try {
return context.getBean(type); return context.getBean(type);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
return null; return null;
} }
} }

View File

@ -506,7 +506,7 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
try { try {
return this.bearerTokenResolver.resolve(request) != null; return this.bearerTokenResolver.resolve(request) != null;
} }
catch (OAuth2AuthenticationException e) { catch (OAuth2AuthenticationException ex) {
return false; return false;
} }
} }

View File

@ -325,7 +325,7 @@ public final class Saml2LoginConfigurer<B extends HttpSecurityBuilder<B>>
try { try {
return context.getBean(clazz); return context.getBean(clazz);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
} }
return null; return null;
} }

View File

@ -119,7 +119,7 @@ public abstract class AbstractSecurityWebSocketMessageBrokerConfigurer extends A
try { try {
return this.context.getBean(SimpAnnotationMethodMessageHandler.class).getPathMatcher(); return this.context.getBean(SimpAnnotationMethodMessageHandler.class).getPathMatcher();
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
return new AntPathMatcher(); return new AntPathMatcher();
} }
} }

View File

@ -51,9 +51,9 @@ public class AuthenticationManagerFactoryBean implements FactoryBean<Authenticat
try { try {
return (AuthenticationManager) this.bf.getBean(BeanIds.AUTHENTICATION_MANAGER); return (AuthenticationManager) this.bf.getBean(BeanIds.AUTHENTICATION_MANAGER);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
if (!BeanIds.AUTHENTICATION_MANAGER.equals(e.getBeanName())) { if (!BeanIds.AUTHENTICATION_MANAGER.equals(ex.getBeanName())) {
throw e; throw ex;
} }
UserDetailsService uds = getBeanOrNull(UserDetailsService.class); UserDetailsService uds = getBeanOrNull(UserDetailsService.class);

View File

@ -118,7 +118,7 @@ public class UserServiceBeanDefinitionParser extends AbstractUserDetailsServiceB
try { try {
this.random = SecureRandom.getInstance("SHA1PRNG"); this.random = SecureRandom.getInstance("SHA1PRNG");
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
// Shouldn't happen... // Shouldn't happen...
throw new RuntimeException("Failed find SHA1PRNG algorithm!"); throw new RuntimeException("Failed find SHA1PRNG algorithm!");
} }

View File

@ -113,8 +113,8 @@ public class RsaKeyConversionServicePostProcessor implements BeanFactoryPostProc
try { try {
return resource.getInputStream(); return resource.getInputStream();
} }
catch (IOException e) { catch (IOException ex) {
throw new UncheckedIOException(e); throw new UncheckedIOException(ex);
} }
} }
@ -123,8 +123,8 @@ public class RsaKeyConversionServicePostProcessor implements BeanFactoryPostProc
try (InputStream is = inputStream) { try (InputStream is = inputStream) {
return inputStreamKeyConverter.convert(is); return inputStreamKeyConverter.convert(is);
} }
catch (IOException e) { catch (IOException ex) {
throw new UncheckedIOException(e); throw new UncheckedIOException(ex);
} }
}; };
} }

View File

@ -152,7 +152,7 @@ public class DefaultFilterChainValidator implements FilterChainProxy.FilterChain
try { try {
filters = fcp.getFilters(loginPage); filters = fcp.getFilters(loginPage);
} }
catch (Exception e) { catch (Exception ex) {
// May happen legitimately if a filter-chain request matcher requires more // May happen legitimately if a filter-chain request matcher requires more
// request data than that provided // request data than that provided
// by the dummy request used when creating the filter invocation. // by the dummy request used when creating the filter invocation.
@ -196,19 +196,19 @@ public class DefaultFilterChainValidator implements FilterChainProxy.FilterChain
try { try {
fsi.getAccessDecisionManager().decide(token, loginRequest, attributes); fsi.getAccessDecisionManager().decide(token, loginRequest, attributes);
} }
catch (AccessDeniedException e) { catch (AccessDeniedException ex) {
this.logger this.logger
.warn("Anonymous access to the login page doesn't appear to be enabled. This is almost certainly " .warn("Anonymous access to the login page doesn't appear to be enabled. This is almost certainly "
+ "an error. Please check your configuration allows unauthenticated access to the configured " + "an error. Please check your configuration allows unauthenticated access to the configured "
+ "login page. (Simulated access was rejected: " + e + ")"); + "login page. (Simulated access was rejected: " + ex + ")");
} }
catch (Exception e) { catch (Exception ex) {
// May happen legitimately if a filter-chain request matcher requires more // May happen legitimately if a filter-chain request matcher requires more
// request data than that provided // request data than that provided
// by the dummy request used when creating the filter invocation. See SEC-1878 // by the dummy request used when creating the filter invocation. See SEC-1878
this.logger.info( this.logger.info(
"Unable to check access to the login page to determine if anonymous access is allowed. This might be an error, but can happen under normal circumstances.", "Unable to check access to the login page to determine if anonymous access is allowed. This might be an error, but can happen under normal circumstances.",
e); ex);
} }
} }

View File

@ -478,9 +478,9 @@ public class HeadersBeanDefinitionParser implements BeanDefinitionParser {
try { try {
builder.addConstructorArgValue(new StaticAllowFromStrategy(new URI(value))); builder.addConstructorArgValue(new StaticAllowFromStrategy(new URI(value)));
} }
catch (URISyntaxException e) { catch (URISyntaxException ex) {
parserContext.getReaderContext().error("'value' attribute doesn't represent a valid URI.", frameElement, parserContext.getReaderContext().error("'value' attribute doesn't represent a valid URI.", frameElement,
e); ex);
} }
return; return;
} }

View File

@ -363,7 +363,7 @@ final class OAuth2ResourceServerBeanDefinitionParser implements BeanDefinitionPa
try { try {
return this.bearerTokenResolver.resolve(request) != null; return this.bearerTokenResolver.resolve(request) != null;
} }
catch (OAuth2AuthenticationException e) { catch (OAuth2AuthenticationException ex) {
return false; return false;
} }
} }

View File

@ -52,10 +52,10 @@ class ContextSourceSettingPostProcessor implements BeanFactoryPostProcessor, Ord
contextSourceClass = ClassUtils.forName(REQUIRED_CONTEXT_SOURCE_CLASS_NAME, contextSourceClass = ClassUtils.forName(REQUIRED_CONTEXT_SOURCE_CLASS_NAME,
ClassUtils.getDefaultClassLoader()); ClassUtils.getDefaultClassLoader());
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException ex) {
throw new ApplicationContextException("Couldn't locate: " + REQUIRED_CONTEXT_SOURCE_CLASS_NAME + ". " throw new ApplicationContextException("Couldn't locate: " + REQUIRED_CONTEXT_SOURCE_CLASS_NAME + ". "
+ " If you are using LDAP with Spring Security, please ensure that you include the spring-ldap " + " If you are using LDAP with Spring Security, please ensure that you include the spring-ldap "
+ "jar file in your application", e); + "jar file in your application", ex);
} }
String[] sources = bf.getBeanNamesForType(contextSourceClass, false, false); String[] sources = bf.getBeanNamesForType(contextSourceClass, false, false);

View File

@ -221,7 +221,7 @@ public class LdapServerBeanDefinitionParser implements BeanDefinitionParser {
try (ServerSocket serverSocket = new ServerSocket(DEFAULT_PORT)) { try (ServerSocket serverSocket = new ServerSocket(DEFAULT_PORT)) {
return String.valueOf(serverSocket.getLocalPort()); return String.valueOf(serverSocket.getLocalPort());
} }
catch (IOException e) { catch (IOException ex) {
return RANDOM_PORT; return RANDOM_PORT;
} }
} }

View File

@ -489,12 +489,12 @@ public class GlobalMethodSecurityBeanDefinitionParser implements BeanDefinitionP
try { try {
this.delegate = this.beanFactory.getBean(this.authMgrBean, AuthenticationManager.class); this.delegate = this.beanFactory.getBean(this.authMgrBean, AuthenticationManager.class);
} }
catch (NoSuchBeanDefinitionException e) { catch (NoSuchBeanDefinitionException ex) {
if (BeanIds.AUTHENTICATION_MANAGER.equals(e.getBeanName())) { if (BeanIds.AUTHENTICATION_MANAGER.equals(ex.getBeanName())) {
throw new NoSuchBeanDefinitionException(BeanIds.AUTHENTICATION_MANAGER, throw new NoSuchBeanDefinitionException(BeanIds.AUTHENTICATION_MANAGER,
AuthenticationManagerFactoryBean.MISSING_BEAN_ERROR_MESSAGE); AuthenticationManagerFactoryBean.MISSING_BEAN_ERROR_MESSAGE);
} }
throw e; throw ex;
} }
} }
} }

View File

@ -122,8 +122,8 @@ final class ProtectPointcutPostProcessor implements BeanPostProcessor {
try { try {
methods = bean.getClass().getMethods(); methods = bean.getClass().getMethods();
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalStateException(e.getMessage()); throw new IllegalStateException(ex.getMessage());
} }
// Check to see if any of those methods are compatible with our pointcut // Check to see if any of those methods are compatible with our pointcut

View File

@ -1426,8 +1426,8 @@ public class ServerHttpSecurity {
return writer.toString(); return writer.toString();
} }
} }
catch (IOException e) { catch (IOException ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
} }

View File

@ -62,8 +62,8 @@ public class InvalidConfigurationTests {
setContext("<http auto-config='true' />"); setContext("<http auto-config='true' />");
fail(); fail();
} }
catch (BeanCreationException e) { catch (BeanCreationException ex) {
Throwable cause = ultimateCause(e); Throwable cause = ultimateCause(ex);
assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue(); assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue();
NoSuchBeanDefinitionException nsbe = (NoSuchBeanDefinitionException) cause; NoSuchBeanDefinitionException nsbe = (NoSuchBeanDefinitionException) cause;
assertThat(nsbe.getBeanName()).isEqualTo(BeanIds.AUTHENTICATION_MANAGER); assertThat(nsbe.getBeanName()).isEqualTo(BeanIds.AUTHENTICATION_MANAGER);
@ -71,11 +71,11 @@ public class InvalidConfigurationTests {
} }
} }
private Throwable ultimateCause(Throwable e) { private Throwable ultimateCause(Throwable ex) {
if (e.getCause() == null) { if (ex.getCause() == null) {
return e; return ex;
} }
return ultimateCause(e.getCause()); return ultimateCause(ex.getCause());
} }
private void setContext(String context) { private void setContext(String context) {

View File

@ -113,7 +113,7 @@ public class GlobalMethodSecurityConfigurationTests {
try { try {
this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("foo", "bar")); this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("foo", "bar"));
} }
catch (AuthenticationException e) { catch (AuthenticationException ex) {
} }
assertThat(this.events.getEvents()).extracting(Object::getClass) assertThat(this.events.getEvents()).extracting(Object::getClass)

View File

@ -120,8 +120,8 @@ public class NamespaceHttpX509Tests {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
return (T) certFactory.generateCertificate(is); return (T) certFactory.generateCertificate(is);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
} }
@ -244,8 +244,8 @@ public class NamespaceHttpX509Tests {
try { try {
return ((X500Name) certificate.getSubjectDN()).getCommonName(); return ((X500Name) certificate.getSubjectDN()).getCommonName();
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
} }

View File

@ -209,8 +209,8 @@ public class ServletApiConfigurerTests {
try { try {
return (T) FieldUtils.getFieldValue(target, fieldName); return (T) FieldUtils.getFieldValue(target, fieldName);
} }
catch (Exception e) { catch (Exception ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
} }

View File

@ -94,8 +94,8 @@ public class X509ConfigurerTests {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
return (T) certFactory.generateCertificate(is); return (T) certFactory.generateCertificate(is);
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
} }

View File

@ -256,8 +256,8 @@ public class Saml2LoginConfigurerTests {
iout.finish(); iout.finish();
return new String(out.toByteArray(), StandardCharsets.UTF_8); return new String(out.toByteArray(), StandardCharsets.UTF_8);
} }
catch (IOException e) { catch (IOException ex) {
throw new Saml2Exception("Unable to inflate string", e); throw new Saml2Exception("Unable to inflate string", ex);
} }
} }

View File

@ -64,8 +64,8 @@ public class TestSaml2Credentials {
return (X509Certificate) factory return (X509Certificate) factory
.generateCertificate(new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8))); .generateCertificate(new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)));
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
} }

View File

@ -42,8 +42,8 @@ public class XmlParser implements AutoCloseable {
return new XmlNode(dBuilder.parse(this.xml)); return new XmlNode(dBuilder.parse(this.xml));
} }
catch (IOException | ParserConfigurationException | SAXException e) { catch (IOException | ParserConfigurationException | SAXException ex) {
throw new IllegalStateException(e); throw new IllegalStateException(ex);
} }
} }

View File

@ -418,8 +418,8 @@ public class SessionManagementConfigTests {
try { try {
return (T) FieldUtils.getFieldValue(target, fieldName); return (T) FieldUtils.getFieldValue(target, fieldName);
} }
catch (Exception e) { catch (Exception ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
} }

View File

@ -65,7 +65,7 @@ public class SpringTestContext implements Closeable {
try { try {
this.context.close(); this.context.close();
} }
catch (Exception e) { catch (Exception ex) {
} }
} }

View File

@ -447,8 +447,8 @@ public class OAuth2ResourceServerSpecTests {
KeyFactory factory = KeyFactory.getInstance("RSA"); KeyFactory factory = KeyFactory.getInstance("RSA");
rsaPublicKey = (RSAPublicKey) factory.generatePublic(spec); rsaPublicKey = (RSAPublicKey) factory.generatePublic(spec);
} }
catch (NoSuchAlgorithmException | InvalidKeySpecException e) { catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
e.printStackTrace(); ex.printStackTrace();
} }
return rsaPublicKey; return rsaPublicKey;
} }

View File

@ -470,7 +470,7 @@ public class ServerHttpSecurityTests {
Object converter = ReflectionTestUtils.getField(filter, "authenticationConverter"); Object converter = ReflectionTestUtils.getField(filter, "authenticationConverter");
return converter.getClass().isAssignableFrom(ServerX509AuthenticationConverter.class); return converter.getClass().isAssignableFrom(ServerX509AuthenticationConverter.class);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException ex) {
// field doesn't exist // field doesn't exist
return false; return false;
} }

View File

@ -36,10 +36,10 @@ public class AccessDeniedException extends RuntimeException {
* Constructs an <code>AccessDeniedException</code> with the specified message and * Constructs an <code>AccessDeniedException</code> with the specified message and
* root cause. * root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public AccessDeniedException(String msg, Throwable t) { public AccessDeniedException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -39,10 +39,10 @@ public class AuthorizationServiceException extends AccessDeniedException {
* Constructs an <code>AuthorizationServiceException</code> with the specified message * Constructs an <code>AuthorizationServiceException</code> with the specified message
* and root cause. * and root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public AuthorizationServiceException(String msg, Throwable t) { public AuthorizationServiceException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -25,8 +25,9 @@ public final class ExpressionUtils {
try { try {
return expr.getValue(ctx, Boolean.class); return expr.getValue(ctx, Boolean.class);
} }
catch (EvaluationException e) { catch (EvaluationException ex) {
throw new IllegalArgumentException("Failed to evaluate expression '" + expr.getExpressionString() + "'", e); throw new IllegalArgumentException("Failed to evaluate expression '" + expr.getExpressionString() + "'",
ex);
} }
} }

View File

@ -54,8 +54,8 @@ public class ExpressionBasedAnnotationAttributeFactory implements PrePostInvocat
: parser.parseExpression(preFilterAttribute); : parser.parseExpression(preFilterAttribute);
return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression); return new PreInvocationExpressionAttribute(preFilterExpression, filterObject, preAuthorizeExpression);
} }
catch (ParseException e) { catch (ParseException ex) {
throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); throw new IllegalArgumentException("Failed to parse expression '" + ex.getExpressionString() + "'", ex);
} }
} }
@ -73,8 +73,8 @@ public class ExpressionBasedAnnotationAttributeFactory implements PrePostInvocat
return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression); return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression);
} }
} }
catch (ParseException e) { catch (ParseException ex) {
throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e); throw new IllegalArgumentException("Failed to parse expression '" + ex.getExpressionString() + "'", ex);
} }
return null; return null;

View File

@ -36,10 +36,10 @@ public class AccountExpiredException extends AccountStatusException {
* Constructs a <code>AccountExpiredException</code> with the specified message and * Constructs a <code>AccountExpiredException</code> with the specified message and
* root cause. * root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public AccountExpiredException(String msg, Throwable t) { public AccountExpiredException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -29,8 +29,8 @@ public abstract class AccountStatusException extends AuthenticationException {
super(msg); super(msg);
} }
public AccountStatusException(String msg, Throwable t) { public AccountStatusException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -41,10 +41,10 @@ public class AuthenticationCredentialsNotFoundException extends AuthenticationEx
* Constructs an <code>AuthenticationCredentialsNotFoundException</code> with the * Constructs an <code>AuthenticationCredentialsNotFoundException</code> with the
* specified message and root cause. * specified message and root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public AuthenticationCredentialsNotFoundException(String msg, Throwable t) { public AuthenticationCredentialsNotFoundException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -42,10 +42,10 @@ public class AuthenticationServiceException extends AuthenticationException {
* Constructs an <code>AuthenticationServiceException</code> with the specified * Constructs an <code>AuthenticationServiceException</code> with the specified
* message and root cause. * message and root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public AuthenticationServiceException(String msg, Throwable t) { public AuthenticationServiceException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -38,10 +38,10 @@ public class BadCredentialsException extends AuthenticationException {
* Constructs a <code>BadCredentialsException</code> with the specified message and * Constructs a <code>BadCredentialsException</code> with the specified message and
* root cause. * root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public BadCredentialsException(String msg, Throwable t) { public BadCredentialsException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -36,10 +36,10 @@ public class CredentialsExpiredException extends AccountStatusException {
* Constructs a <code>CredentialsExpiredException</code> with the specified message * Constructs a <code>CredentialsExpiredException</code> with the specified message
* and root cause. * and root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public CredentialsExpiredException(String msg, Throwable t) { public CredentialsExpiredException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -155,7 +155,7 @@ public class DefaultAuthenticationEventPublisher
Assert.isAssignable(AbstractAuthenticationFailureEvent.class, clazz); Assert.isAssignable(AbstractAuthenticationFailureEvent.class, clazz);
addMapping((String) exceptionClass, (Class<? extends AbstractAuthenticationFailureEvent>) clazz); addMapping((String) exceptionClass, (Class<? extends AbstractAuthenticationFailureEvent>) clazz);
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException ex) {
throw new RuntimeException("Failed to load authentication event class " + eventClass); throw new RuntimeException("Failed to load authentication event class " + eventClass);
} }
} }
@ -194,7 +194,7 @@ public class DefaultAuthenticationEventPublisher
this.defaultAuthenticationFailureEventConstructor = defaultAuthenticationFailureEventClass this.defaultAuthenticationFailureEventConstructor = defaultAuthenticationFailureEventClass
.getConstructor(Authentication.class, AuthenticationException.class); .getConstructor(Authentication.class, AuthenticationException.class);
} }
catch (NoSuchMethodException e) { catch (NoSuchMethodException ex) {
throw new RuntimeException("Default Authentication Failure event class " throw new RuntimeException("Default Authentication Failure event class "
+ defaultAuthenticationFailureEventClass.getName() + " has no suitable constructor"); + defaultAuthenticationFailureEventClass.getName() + " has no suitable constructor");
} }
@ -206,7 +206,7 @@ public class DefaultAuthenticationEventPublisher
.getConstructor(Authentication.class, AuthenticationException.class); .getConstructor(Authentication.class, AuthenticationException.class);
this.exceptionMappings.put(exceptionClass, constructor); this.exceptionMappings.put(exceptionClass, constructor);
} }
catch (NoSuchMethodException e) { catch (NoSuchMethodException ex) {
throw new RuntimeException( throw new RuntimeException(
"Authentication event class " + eventClass.getName() + " has no suitable constructor"); "Authentication event class " + eventClass.getName() + " has no suitable constructor");
} }

View File

@ -36,10 +36,10 @@ public class DisabledException extends AccountStatusException {
* Constructs a <code>DisabledException</code> with the specified message and root * Constructs a <code>DisabledException</code> with the specified message and root
* cause. * cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public DisabledException(String msg, Throwable t) { public DisabledException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -46,10 +46,10 @@ public class InsufficientAuthenticationException extends AuthenticationException
* Constructs an <code>InsufficientAuthenticationException</code> with the specified * Constructs an <code>InsufficientAuthenticationException</code> with the specified
* message and root cause. * message and root cause.
* @param msg the detail message * @param msg the detail message
* @param t root cause * @param cause root cause
*/ */
public InsufficientAuthenticationException(String msg, Throwable t) { public InsufficientAuthenticationException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -36,10 +36,10 @@ public class LockedException extends AccountStatusException {
* Constructs a <code>LockedException</code> with the specified message and root * Constructs a <code>LockedException</code> with the specified message and root
* cause. * cause.
* @param msg the detail message. * @param msg the detail message.
* @param t root cause * @param cause root cause
*/ */
public LockedException(String msg, Throwable t) { public LockedException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -188,14 +188,14 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
break; break;
} }
} }
catch (AccountStatusException | InternalAuthenticationServiceException e) { catch (AccountStatusException | InternalAuthenticationServiceException ex) {
prepareException(e, authentication); prepareException(ex, authentication);
// SEC-546: Avoid polling additional providers if auth failure is due to // SEC-546: Avoid polling additional providers if auth failure is due to
// invalid account status // invalid account status
throw e; throw ex;
} }
catch (AuthenticationException e) { catch (AuthenticationException ex) {
lastException = e; lastException = ex;
} }
} }
@ -205,15 +205,15 @@ public class ProviderManager implements AuthenticationManager, MessageSourceAwar
parentResult = this.parent.authenticate(authentication); parentResult = this.parent.authenticate(authentication);
result = parentResult; result = parentResult;
} }
catch (ProviderNotFoundException e) { catch (ProviderNotFoundException ex) {
// ignore as we will throw below if no other exception occurred prior to // ignore as we will throw below if no other exception occurred prior to
// calling parent and the parent // calling parent and the parent
// may throw ProviderNotFound even though a provider in the child already // may throw ProviderNotFound even though a provider in the child already
// handled the request // handled the request
} }
catch (AuthenticationException e) { catch (AuthenticationException ex) {
parentException = e; parentException = ex;
lastException = e; lastException = ex;
} }
} }

View File

@ -256,8 +256,8 @@ public abstract class AbstractJaasAuthenticationProvider implements Authenticati
+ "The LoginContext is unavailable"); + "The LoginContext is unavailable");
} }
} }
catch (LoginException e) { catch (LoginException ex) {
this.log.warn("Error error logging out of LoginContext", e); this.log.warn("Error error logging out of LoginContext", ex);
} }
} }
} }

View File

@ -30,8 +30,8 @@ import org.springframework.security.core.AuthenticationException;
public class DefaultLoginExceptionResolver implements LoginExceptionResolver { public class DefaultLoginExceptionResolver implements LoginExceptionResolver {
@Override @Override
public AuthenticationException resolveException(LoginException e) { public AuthenticationException resolveException(LoginException ex) {
return new AuthenticationServiceException(e.getMessage(), e); return new AuthenticationServiceException(ex.getMessage(), ex);
} }
} }

View File

@ -223,7 +223,7 @@ public class JaasAuthenticationProvider extends AbstractJaasAuthenticationProvid
return new URL("file", "", loginConfigPath).toString(); return new URL("file", "", loginConfigPath).toString();
} }
catch (IOException e) { catch (IOException ex) {
// SEC-1700: May be inside a jar // SEC-1700: May be inside a jar
return this.loginConfig.getURL().toString(); return this.loginConfig.getURL().toString();
} }

View File

@ -34,10 +34,10 @@ public interface LoginExceptionResolver {
/** /**
* Translates a Jaas LoginException to an SpringSecurityException. * 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 * @return The AuthenticationException that the JaasAuthenticationProvider should
* throw. * throw.
*/ */
AuthenticationException resolveException(LoginException e); AuthenticationException resolveException(LoginException ex);
} }

View File

@ -82,8 +82,8 @@ public class RsaKeyConverters {
try { try {
return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(pkcs8)); return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(pkcs8));
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
}; };
} }
@ -115,8 +115,8 @@ public class RsaKeyConverters {
try { try {
return (RSAPublicKey) keyFactory.generatePublic(new X509EncodedKeySpec(x509)); return (RSAPublicKey) keyFactory.generatePublic(new X509EncodedKeySpec(x509));
} }
catch (Exception e) { catch (Exception ex) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
}; };
} }
@ -130,8 +130,8 @@ public class RsaKeyConverters {
try { try {
return KeyFactory.getInstance("RSA"); return KeyFactory.getInstance("RSA");
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException(e); throw new IllegalStateException(ex);
} }
} }

View File

@ -28,10 +28,10 @@ public abstract class AuthenticationException extends RuntimeException {
* Constructs an {@code AuthenticationException} with the specified message and root * Constructs an {@code AuthenticationException} with the specified message and root
* cause. * cause.
* @param msg the detail message * @param msg the detail message
* @param t the root cause * @param cause the root cause
*/ */
public AuthenticationException(String msg, Throwable t) { public AuthenticationException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
/** /**

View File

@ -108,7 +108,7 @@ public class SpringSecurityCoreVersion {
properties.load(SpringSecurityCoreVersion.class.getClassLoader() properties.load(SpringSecurityCoreVersion.class.getClassLoader()
.getResourceAsStream("META-INF/spring-security.versions")); .getResourceAsStream("META-INF/spring-security.versions"));
} }
catch (IOException | NullPointerException e) { catch (IOException | NullPointerException ex) {
return null; return null;
} }
return properties.getProperty("org.springframework:spring-core"); return properties.getProperty("org.springframework:spring-core");

View File

@ -43,8 +43,8 @@ public abstract class Sha512DigestUtils {
try { try {
return MessageDigest.getInstance("SHA-512"); return MessageDigest.getInstance("SHA-512");
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(ex.getMessage());
} }
} }

View File

@ -38,10 +38,10 @@ public class UsernameNotFoundException extends AuthenticationException {
* Constructs a {@code UsernameNotFoundException} with the specified message and root * Constructs a {@code UsernameNotFoundException} with the specified message and root
* cause. * cause.
* @param msg the detail message. * @param msg the detail message.
* @param t root cause * @param cause root cause
*/ */
public UsernameNotFoundException(String msg, Throwable t) { public UsernameNotFoundException(String msg, Throwable cause) {
super(msg, t); super(msg, cause);
} }
} }

View File

@ -107,9 +107,9 @@ public final class SecurityJackson2Modules {
instance = securityModule.newInstance(); instance = securityModule.newInstance();
} }
} }
catch (Exception e) { catch (Exception ex) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Cannot load module " + className, e); logger.debug("Cannot load module " + className, ex);
} }
} }
return instance; return instance;

View File

@ -137,7 +137,7 @@ public final class MethodInvocationUtils {
try { try {
method = clazz.getMethod(methodName, classArgs); method = clazz.getMethod(methodName, classArgs);
} }
catch (NoSuchMethodException e) { catch (NoSuchMethodException ex) {
return null; return null;
} }

View File

@ -117,21 +117,21 @@ public class RoleHierarchyImplTests {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_A"); roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_A");
fail("Cycle in role hierarchy was not detected!"); fail("Cycle in role hierarchy was not detected!");
} }
catch (CycleInRoleHierarchyException e) { catch (CycleInRoleHierarchyException ex) {
} }
try { try {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_A"); roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_A");
fail("Cycle in role hierarchy was not detected!"); fail("Cycle in role hierarchy was not detected!");
} }
catch (CycleInRoleHierarchyException e) { catch (CycleInRoleHierarchyException ex) {
} }
try { try {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_A"); roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_B > ROLE_C\nROLE_C > ROLE_A");
fail("Cycle in role hierarchy was not detected!"); fail("Cycle in role hierarchy was not detected!");
} }
catch (CycleInRoleHierarchyException e) { catch (CycleInRoleHierarchyException ex) {
} }
try { 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"); "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!"); fail("Cycle in role hierarchy was not detected!");
} }
catch (CycleInRoleHierarchyException e) { catch (CycleInRoleHierarchyException ex) {
} }
try { try {
roleHierarchyImpl.setHierarchy("ROLE_C > ROLE_B\nROLE_B > ROLE_A\nROLE_A > ROLE_B"); roleHierarchyImpl.setHierarchy("ROLE_C > ROLE_B\nROLE_B > ROLE_A\nROLE_A > ROLE_B");
fail("Cycle in role hierarchy was not detected!"); fail("Cycle in role hierarchy was not detected!");
} }
catch (CycleInRoleHierarchyException e) { catch (CycleInRoleHierarchyException ex) {
} }
} }
@ -157,7 +157,7 @@ public class RoleHierarchyImplTests {
try { try {
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B\nROLE_A > ROLE_C\nROLE_C > ROLE_D\nROLE_B > ROLE_D"); 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!"); fail("A cycle in role hierarchy was incorrectly detected!");
} }
} }

View File

@ -271,8 +271,8 @@ public class ProviderManagerTests {
mgr.authenticate(authReq); mgr.authenticate(authReq);
fail("Expected exception"); fail("Expected exception");
} }
catch (BadCredentialsException e) { catch (BadCredentialsException ex) {
assertThat(e).isSameAs(expected); assertThat(ex).isSameAs(expected);
} }
} }
@ -289,8 +289,8 @@ public class ProviderManagerTests {
mgr.authenticate(authReq); mgr.authenticate(authReq);
fail("Expected exception"); fail("Expected exception");
} }
catch (LockedException e) { catch (LockedException ex) {
assertThat(e).isSameAs(expected); assertThat(ex).isSameAs(expected);
} }
verify(publisher).publishAuthenticationFailure(expected, authReq); verify(publisher).publishAuthenticationFailure(expected, authReq);
} }
@ -329,18 +329,18 @@ public class ProviderManagerTests {
childMgr.authenticate(authReq); childMgr.authenticate(authReq);
fail("Expected exception"); fail("Expected exception");
} }
catch (BadCredentialsException e) { catch (BadCredentialsException ex) {
assertThat(e).isSameAs(badCredentialsExParent); assertThat(ex).isSameAs(badCredentialsExParent);
} }
verify(publisher).publishAuthenticationFailure(badCredentialsExParent, authReq); // Parent verify(publisher).publishAuthenticationFailure(badCredentialsExParent, authReq); // Parent
// publishes // publishes
verifyNoMoreInteractions(publisher); // Child should not publish (duplicate event) 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); AuthenticationProvider provider = mock(AuthenticationProvider.class);
given(provider.supports(any(Class.class))).willReturn(true); 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; return provider;
} }

View File

@ -77,7 +77,7 @@ public class JaasAuthenticationProviderTests {
this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "asdf")); this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "asdf"));
fail("LoginException should have been thrown for the bad password"); 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(); assertThat(this.eventCheck.failedEvent).as("Failure event not fired").isNotNull();
@ -92,7 +92,7 @@ public class JaasAuthenticationProviderTests {
this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("asdf", "password")); this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("asdf", "password"));
fail("LoginException should have been thrown for the bad user"); 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(); assertThat(this.eventCheck.failedEvent).as("Failure event not fired").isNotNull();
@ -241,9 +241,9 @@ public class JaasAuthenticationProviderTests {
try { try {
this.jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "password")); 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"); fail("LockedException should have been thrown and caught");
} }
} }

View File

@ -75,7 +75,7 @@ public class SecurityContextLoginModuleTests {
this.module.login(); this.module.login();
fail("LoginException expected, there is no Authentication in the SecurityContext"); 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(); this.module.login();
fail("LoginException expected, the authentication is null in the SecurityContext"); fail("LoginException expected, the authentication is null in the SecurityContext");
} }
catch (Exception e) { catch (Exception ex) {
} }
} }

View File

@ -63,8 +63,8 @@ public class TestLoginModule implements LoginModule {
this.password = new String(passwordCallback.getPassword()); this.password = new String(passwordCallback.getPassword());
this.user = nameCallback.getName(); this.user = nameCallback.getName();
} }
catch (Exception e) { catch (Exception ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
} }

View File

@ -40,8 +40,8 @@ public class KeyBasedPersistenceTokenServiceTests {
service.setSecureRandom(rnd); service.setSecureRandom(rnd);
service.afterPropertiesSet(); service.afterPropertiesSet();
} }
catch (Exception e) { catch (Exception ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
return service; return service;
} }

View File

@ -107,8 +107,8 @@ public class Argon2PasswordEncoder implements PasswordEncoder {
try { try {
decoded = Argon2EncodingUtils.decode(encodedPassword); decoded = Argon2EncodingUtils.decode(encodedPassword);
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException ex) {
this.logger.warn("Malformed password hash", e); this.logger.warn("Malformed password hash", ex);
return false; return false;
} }

View File

@ -248,7 +248,7 @@ public final class Base64 {
try { try {
decode(bytes); decode(bytes);
} }
catch (InvalidBase64CharacterException e) { catch (InvalidBase64CharacterException ex) {
return false; return false;
} }
return true; return true;

View File

@ -43,8 +43,8 @@ public final class Utf8 {
return bytesCopy; return bytesCopy;
} }
catch (CharacterCodingException e) { catch (CharacterCodingException ex) {
throw new IllegalArgumentException("Encoding failed", e); throw new IllegalArgumentException("Encoding failed", ex);
} }
} }
@ -55,8 +55,8 @@ public final class Utf8 {
try { try {
return CHARSET.newDecoder().decode(ByteBuffer.wrap(bytes)).toString(); return CHARSET.newDecoder().decode(ByteBuffer.wrap(bytes)).toString();
} }
catch (CharacterCodingException e) { catch (CharacterCodingException ex) {
throw new IllegalArgumentException("Decoding failed", e); throw new IllegalArgumentException("Decoding failed", ex);
} }
} }

View File

@ -74,8 +74,8 @@ public class BouncyCastleAesCbcBytesEncryptor extends BouncyCastleAesBytesEncryp
try { try {
bytesWritten += blockCipher.doFinal(buf, bytesWritten); bytesWritten += blockCipher.doFinal(buf, bytesWritten);
} }
catch (InvalidCipherTextException e) { catch (InvalidCipherTextException ex) {
throw new IllegalStateException("unable to encrypt/decrypt", e); throw new IllegalStateException("unable to encrypt/decrypt", ex);
} }
if (bytesWritten == buf.length) { if (bytesWritten == buf.length) {
return buf; return buf;

View File

@ -71,8 +71,8 @@ public class BouncyCastleAesGcmBytesEncryptor extends BouncyCastleAesBytesEncryp
try { try {
bytesWritten += blockCipher.doFinal(buf, bytesWritten); bytesWritten += blockCipher.doFinal(buf, bytesWritten);
} }
catch (InvalidCipherTextException e) { catch (InvalidCipherTextException ex) {
throw new IllegalStateException("unable to encrypt/decrypt", e); throw new IllegalStateException("unable to encrypt/decrypt", ex);
} }
if (bytesWritten == buf.length) { if (bytesWritten == buf.length) {
return buf; return buf;

View File

@ -56,11 +56,11 @@ final class CipherUtils {
SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm); SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm);
return factory.generateSecret(keySpec); return factory.generateSecret(keySpec);
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
throw new IllegalArgumentException("Not a valid encryption algorithm", e); throw new IllegalArgumentException("Not a valid encryption algorithm", ex);
} }
catch (InvalidKeySpecException e) { catch (InvalidKeySpecException ex) {
throw new IllegalArgumentException("Not a valid secret key", e); throw new IllegalArgumentException("Not a valid secret key", ex);
} }
} }
@ -71,11 +71,11 @@ final class CipherUtils {
try { try {
return Cipher.getInstance(algorithm); return Cipher.getInstance(algorithm);
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
throw new IllegalArgumentException("Not a valid encryption algorithm", e); throw new IllegalArgumentException("Not a valid encryption algorithm", ex);
} }
catch (NoSuchPaddingException e) { catch (NoSuchPaddingException ex) {
throw new IllegalStateException("Should not happen", e); throw new IllegalStateException("Should not happen", ex);
} }
} }
@ -86,8 +86,8 @@ final class CipherUtils {
try { try {
return cipher.getParameters().getParameterSpec(parameterSpecClass); return cipher.getParameters().getParameterSpec(parameterSpecClass);
} }
catch (InvalidParameterSpecException e) { catch (InvalidParameterSpecException ex) {
throw new IllegalArgumentException("Unable to access parameter", e); throw new IllegalArgumentException("Unable to access parameter", ex);
} }
} }
@ -117,11 +117,11 @@ final class CipherUtils {
cipher.init(mode, secretKey); cipher.init(mode, secretKey);
} }
} }
catch (InvalidKeyException e) { catch (InvalidKeyException ex) {
throw new IllegalArgumentException("Unable to initialize due to invalid secret key", e); throw new IllegalArgumentException("Unable to initialize due to invalid secret key", ex);
} }
catch (InvalidAlgorithmParameterException e) { catch (InvalidAlgorithmParameterException ex) {
throw new IllegalStateException("Unable to initialize due to invalid decryption parameter spec", e); throw new IllegalStateException("Unable to initialize due to invalid decryption parameter spec", ex);
} }
} }
@ -133,11 +133,11 @@ final class CipherUtils {
try { try {
return cipher.doFinal(input); return cipher.doFinal(input);
} }
catch (IllegalBlockSizeException e) { catch (IllegalBlockSizeException ex) {
throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e); throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", ex);
} }
catch (BadPaddingException e) { catch (BadPaddingException ex) {
throw new IllegalStateException("Unable to invoke Cipher due to bad padding", e); throw new IllegalStateException("Unable to invoke Cipher due to bad padding", ex);
} }
} }

View File

@ -64,8 +64,8 @@ final class Digester {
try { try {
return MessageDigest.getInstance(algorithm); return MessageDigest.getInstance(algorithm);
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
throw new IllegalStateException("No such hashing algorithm", e); throw new IllegalStateException("No such hashing algorithm", ex);
} }
} }

View File

@ -104,7 +104,7 @@ public class LdapShaPasswordEncoder implements PasswordEncoder {
sha = MessageDigest.getInstance("SHA"); sha = MessageDigest.getInstance("SHA");
sha.update(Utf8.encode(rawPassword)); sha.update(Utf8.encode(rawPassword));
} }
catch (java.security.NoSuchAlgorithmException e) { catch (java.security.NoSuchAlgorithmException ex) {
throw new IllegalStateException("No SHA implementation available!"); throw new IllegalStateException("No SHA implementation available!");
} }

View File

@ -112,8 +112,8 @@ public class Pbkdf2PasswordEncoder implements PasswordEncoder {
try { try {
SecretKeyFactory.getInstance(algorithmName); SecretKeyFactory.getInstance(algorithmName);
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
throw new IllegalArgumentException("Invalid algorithm '" + algorithmName + "'.", e); throw new IllegalArgumentException("Invalid algorithm '" + algorithmName + "'.", ex);
} }
this.algorithm = algorithmName; this.algorithm = algorithmName;
} }
@ -163,8 +163,8 @@ public class Pbkdf2PasswordEncoder implements PasswordEncoder {
SecretKeyFactory skf = SecretKeyFactory.getInstance(this.algorithm); SecretKeyFactory skf = SecretKeyFactory.getInstance(this.algorithm);
return EncodingUtils.concatenate(salt, skf.generateSecret(spec).getEncoded()); return EncodingUtils.concatenate(salt, skf.generateSecret(spec).getEncoded());
} }
catch (GeneralSecurityException e) { catch (GeneralSecurityException ex) {
throw new IllegalStateException("Could not create hash", e); throw new IllegalStateException("Could not create hash", ex);
} }
} }

View File

@ -41,11 +41,11 @@ public class CryptoAssumptions {
Cipher.getInstance(cipherAlgorithm.toString()); Cipher.getInstance(cipherAlgorithm.toString());
aes256Available = Cipher.getMaxAllowedKeyLength("AES") >= 256; aes256Available = Cipher.getMaxAllowedKeyLength("AES") >= 256;
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException ex) {
throw new AssumptionViolatedException(cipherAlgorithm + " not available, skipping test", e); throw new AssumptionViolatedException(cipherAlgorithm + " not available, skipping test", ex);
} }
catch (NoSuchPaddingException e) { catch (NoSuchPaddingException ex) {
throw new AssumptionViolatedException(cipherAlgorithm + " padding not available, skipping test", e); throw new AssumptionViolatedException(cipherAlgorithm + " padding not available, skipping test", ex);
} }
Assume.assumeTrue("AES key length of 256 not allowed, skipping test", aes256Available); Assume.assumeTrue("AES key length of 256 not allowed, skipping test", aes256Available);

View File

@ -552,9 +552,9 @@ ReactiveJwtDecoder jwtDecoder() {
---- ----
[[webflux-oauth2resourceserver-opaque-minimaldependencies]] [[webflux-oauth2resourceserver-opaque-minimaldependencies]]
=== Minimal Dependencies for Introspection === Minimal Dependencies for Introspection
As described in <<oauth2resourceserver-jwt-minimaldependencies,Minimal Dependencies for JWT>> most of Resource Server support is collected in `spring-security-oauth2-resource-server`. As described in <<oauth2resourceserver-jwt-minimaldependencies,Minimal Dependencies for JWT>> most of Resource Server support is collected in `spring-security-oauth2-resource-server`.
However unless a custom <<webflux-oauth2resourceserver-opaque-introspector-bean,`ReactiveOpaqueTokenIntrospector`>> is provided, the Resource Server will fallback to ReactiveOpaqueTokenIntrospector. However unless a custom <<webflux-oauth2resourceserver-opaque-introspector-bean,`ReactiveOpaqueTokenIntrospector`>> is provided, the Resource Server will fallback to ReactiveOpaqueTokenIntrospector.
Meaning that both `spring-security-oauth2-resource-server` and `oauth2-oidc-sdk` are necessary in order to have a working minimal Resource Server that supports opaque Bearer Tokens. Meaning that both `spring-security-oauth2-resource-server` and `oauth2-oidc-sdk` are necessary in order to have a working minimal Resource Server that supports opaque Bearer Tokens.
Please refer to `spring-security-oauth2-resource-server` in order to determin the correct version for `oauth2-oidc-sdk`. Please refer to `spring-security-oauth2-resource-server` in order to determin the correct version for `oauth2-oidc-sdk`.
[[webflux-oauth2resourceserver-opaque-minimalconfiguration]] [[webflux-oauth2resourceserver-opaque-minimalconfiguration]]
@ -925,8 +925,8 @@ public class JwtOpaqueTokenIntrospector implements ReactiveOpaqueTokenIntrospect
public Mono<JWTClaimsSet> convert(JWT jwt) { public Mono<JWTClaimsSet> convert(JWT jwt) {
try { try {
return Mono.just(jwt.getJWTClaimsSet()); return Mono.just(jwt.getJWTClaimsSet());
} catch (Exception e) { } catch (Exception ex) {
return Mono.error(e); return Mono.error(ex);
} }
} }
} }

View File

@ -36,8 +36,8 @@ The pseudocode for `ExceptionTranslationFilter` looks something like this:
---- ----
try { try {
filterChain.doFilter(request, response); // <1> filterChain.doFilter(request, response); // <1>
} catch (AccessDeniedException | AuthenticationException e) { } catch (AccessDeniedException | AuthenticationException ex) {
if (!authenticated || e instanceof AuthenticationException) { if (!authenticated || ex instanceof AuthenticationException) {
startAuthentication(); // <2> startAuthentication(); // <2>
} else { } else {
accessDenied(); // <3> accessDenied(); // <3>

View File

@ -75,7 +75,7 @@ For example, the following would attempt to authenticate with the username "user
---- ----
try { try {
httpServletRequest.login("user","password"); httpServletRequest.login("user","password");
} catch(ServletException e) { } catch(ServletException ex) {
// fail to authenticate // fail to authenticate
} }
---- ----
@ -111,8 +111,8 @@ async.start(new Runnable() {
asyncResponse.setStatus(HttpServletResponse.SC_OK); asyncResponse.setStatus(HttpServletResponse.SC_OK);
asyncResponse.getWriter().write(String.valueOf(authentication)); asyncResponse.getWriter().write(String.valueOf(authentication));
async.complete(); async.complete();
} catch(Exception e) { } catch(Exception ex) {
throw new RuntimeException(e); throw new RuntimeException(ex);
} }
} }
}); });
@ -174,8 +174,8 @@ new Thread("AsyncThread") {
// Write to and commit the httpServletResponse // Write to and commit the httpServletResponse
httpServletResponse.getOutputStream().flush(); httpServletResponse.getOutputStream().flush();
} catch (Exception e) { } catch (Exception ex) {
e.printStackTrace(); ex.printStackTrace();
} }
} }
}.start(); }.start();

View File

@ -1055,9 +1055,9 @@ To do so, remember that `NimbusJwtDecoder` ships with a constructor that takes N
[[oauth2resourceserver-opaque-minimaldependencies]] [[oauth2resourceserver-opaque-minimaldependencies]]
=== Minimal Dependencies for Introspection === Minimal Dependencies for Introspection
As described in <<oauth2resourceserver-jwt-minimaldependencies,Minimal Dependencies for JWT>> most of Resource Server support is collected in `spring-security-oauth2-resource-server`. As described in <<oauth2resourceserver-jwt-minimaldependencies,Minimal Dependencies for JWT>> most of Resource Server support is collected in `spring-security-oauth2-resource-server`.
However unless a custom <<oauth2resourceserver-opaque-introspector,`OpaqueTokenIntrospector`>> is provided, the Resource Server will fallback to NimbusOpaqueTokenIntrospector. However unless a custom <<oauth2resourceserver-opaque-introspector,`OpaqueTokenIntrospector`>> is provided, the Resource Server will fallback to NimbusOpaqueTokenIntrospector.
Meaning that both `spring-security-oauth2-resource-server` and `oauth2-oidc-sdk` are necessary in order to have a working minimal Resource Server that supports opaque Bearer Tokens. Meaning that both `spring-security-oauth2-resource-server` and `oauth2-oidc-sdk` are necessary in order to have a working minimal Resource Server that supports opaque Bearer Tokens.
Please refer to `spring-security-oauth2-resource-server` in order to determin the correct version for `oauth2-oidc-sdk`. Please refer to `spring-security-oauth2-resource-server` in order to determin the correct version for `oauth2-oidc-sdk`.
[[oauth2resourceserver-opaque-minimalconfiguration]] [[oauth2resourceserver-opaque-minimalconfiguration]]
@ -1626,8 +1626,8 @@ public class JwtOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
try { try {
Jwt jwt = this.jwtDecoder.decode(token); Jwt jwt = this.jwtDecoder.decode(token);
return new DefaultOAuth2AuthenticatedPrincipal(jwt.getClaims(), NO_AUTHORITIES); return new DefaultOAuth2AuthenticatedPrincipal(jwt.getClaims(), NO_AUTHORITIES);
} catch (JwtException e) { } catch (JwtException ex) {
throw new OAuth2IntrospectionException(e); throw new OAuth2IntrospectionException(ex);
} }
} }
@ -1899,8 +1899,8 @@ public class TenantJWSKeySelector
private JWSKeySelector<SecurityContext> fromUri(String uri) { private JWSKeySelector<SecurityContext> fromUri(String uri) {
try { try {
return JWSAlgorithmFamilyJWSKeySelector.fromJWKSetURL(new URL(uri)); <4> return JWSAlgorithmFamilyJWSKeySelector.fromJWKSetURL(new URL(uri)); <4>
} catch (Exception e) { } catch (Exception ex) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(ex);
} }
} }
} }

View File

@ -3,7 +3,6 @@
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd"> "https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions> <suppressions>
<suppress files=".*" checks="SpringCatch" />
<suppress files=".*" checks="SpringHeader" /> <suppress files=".*" checks="SpringHeader" />
<suppress files=".*" checks="SpringHideUtilityClassConstructor" /> <suppress files=".*" checks="SpringHideUtilityClassConstructor" />
<suppress files=".*" checks="SpringJavadoc" /> <suppress files=".*" checks="SpringJavadoc" />

View File

@ -52,8 +52,8 @@ public class PythonInterpreterPreInvocationAdvice implements PreInvocationAuthor
try { try {
python.execfile(scriptResource.getInputStream()); python.execfile(scriptResource.getInputStream());
} }
catch (IOException e) { catch (IOException ex) {
throw new IllegalArgumentException("Couldn't run python script, " + script, e); throw new IllegalArgumentException("Couldn't run python script, " + script, ex);
} }
PyObject allowed = python.get("allow"); PyObject allowed = python.get("allow");

View File

@ -85,7 +85,7 @@ public class DefaultSpringSecurityContextSourceTests {
try { try {
ctx = this.contextSource.getContext("uid=Bob,ou=people,dc=springframework,dc=org", "bobspassword"); ctx = this.contextSource.getContext("uid=Bob,ou=people,dc=springframework,dc=org", "bobspassword");
} }
catch (Exception e) { catch (Exception ex) {
} }
assertThat(ctx).isNotNull(); assertThat(ctx).isNotNull();
// com.sun.jndi.ldap.LdapPoolManager.showStats(System.out); // com.sun.jndi.ldap.LdapPoolManager.showStats(System.out);

View File

@ -69,12 +69,12 @@ public class ApacheDSContainerTests {
try { try {
server1.destroy(); server1.destroy();
} }
catch (Throwable t) { catch (Throwable ex) {
} }
try { try {
server2.destroy(); server2.destroy();
} }
catch (Throwable t) { catch (Throwable ex) {
} }
} }
} }
@ -95,12 +95,12 @@ public class ApacheDSContainerTests {
try { try {
server1.destroy(); server1.destroy();
} }
catch (Throwable t) { catch (Throwable ex) {
} }
try { try {
server2.destroy(); server2.destroy();
} }
catch (Throwable t) { catch (Throwable ex) {
} }
} }
} }
@ -116,8 +116,8 @@ public class ApacheDSContainerTests {
server.afterPropertiesSet(); server.afterPropertiesSet();
fail("Expected an IllegalArgumentException to be thrown."); fail("Expected an IllegalArgumentException to be thrown.");
} }
catch (IllegalArgumentException e) { catch (IllegalArgumentException ex) {
assertThat(e).hasMessage("When LdapOverSsl is enabled, the keyStoreFile property must be set."); assertThat(ex).hasMessage("When LdapOverSsl is enabled, the keyStoreFile property must be set.");
} }
} }
@ -143,9 +143,9 @@ public class ApacheDSContainerTests {
server.afterPropertiesSet(); server.afterPropertiesSet();
fail("Expected a RuntimeException to be thrown."); fail("Expected a RuntimeException to be thrown.");
} }
catch (RuntimeException e) { catch (RuntimeException ex) {
assertThat(e).hasMessage("Server startup failed"); assertThat(ex).hasMessage("Server startup failed");
assertThat(e).hasRootCauseInstanceOf(UnrecoverableKeyException.class); assertThat(ex).hasRootCauseInstanceOf(UnrecoverableKeyException.class);
} }
} }
@ -187,7 +187,7 @@ public class ApacheDSContainerTests {
try { try {
server.destroy(); server.destroy();
} }
catch (Throwable t) { catch (Throwable ex) {
} }
} }
} }

View File

@ -75,9 +75,9 @@ public class UnboundIdContainerLdifTests {
this.appCtx = new AnnotationConfigApplicationContext(MalformedLdifConfig.class); this.appCtx = new AnnotationConfigApplicationContext(MalformedLdifConfig.class);
failBecauseExceptionWasNotThrown(IllegalStateException.class); failBecauseExceptionWasNotThrown(IllegalStateException.class);
} }
catch (Exception e) { catch (Exception ex) {
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class); assertThat(ex.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("Unable to load LDIF classpath:test-server-malformed.txt"); assertThat(ex.getMessage()).contains("Unable to load LDIF classpath:test-server-malformed.txt");
} }
} }
@ -87,9 +87,9 @@ public class UnboundIdContainerLdifTests {
this.appCtx = new AnnotationConfigApplicationContext(MissingLdifConfig.class); this.appCtx = new AnnotationConfigApplicationContext(MissingLdifConfig.class);
failBecauseExceptionWasNotThrown(IllegalStateException.class); failBecauseExceptionWasNotThrown(IllegalStateException.class);
} }
catch (Exception e) { catch (Exception ex) {
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class); assertThat(ex.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("Unable to load LDIF classpath:does-not-exist.ldif"); assertThat(ex.getMessage()).contains("Unable to load LDIF classpath:does-not-exist.ldif");
} }
} }

View File

@ -53,8 +53,8 @@ public final class LdapUtils {
ctx.close(); ctx.close();
} }
} }
catch (NamingException e) { catch (NamingException ex) {
logger.error("Failed to close context.", e); logger.error("Failed to close context.", ex);
} }
} }
@ -64,8 +64,8 @@ public final class LdapUtils {
ne.close(); ne.close();
} }
} }
catch (NamingException e) { catch (NamingException ex) {
logger.error("Failed to close enumeration.", e); logger.error("Failed to close enumeration.", ex);
} }
} }
@ -177,9 +177,9 @@ public final class LdapUtils {
try { try {
return new URI(url); return new URI(url);
} }
catch (URISyntaxException e) { catch (URISyntaxException ex) {
IllegalArgumentException iae = new IllegalArgumentException("Unable to parse url: " + url); IllegalArgumentException iae = new IllegalArgumentException("Unable to parse url: " + url);
iae.initCause(e); iae.initCause(ex);
throw iae; throw iae;
} }
} }

View File

@ -197,8 +197,8 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
extractStringAttributeValues(adapter, record, attr.getID()); extractStringAttributeValues(adapter, record, attr.getID());
} }
} }
catch (NamingException x) { catch (NamingException ex) {
org.springframework.ldap.support.LdapUtils.convertLdapException(x); org.springframework.ldap.support.LdapUtils.convertLdapException(ex);
} }
} }
else { else {
@ -316,7 +316,7 @@ public class SpringSecurityLdapTemplate extends LdapTemplate {
results.add(dca); results.add(dca);
} }
} }
catch (PartialResultException e) { catch (PartialResultException ex) {
LdapUtils.closeEnumeration(resultsEnum); LdapUtils.closeEnumeration(resultsEnum);
logger.info("Ignoring PartialResultException"); logger.info("Ignoring PartialResultException");
} }

View File

@ -127,20 +127,20 @@ public class BindAuthenticator extends AbstractLdapAuthenticator {
return result; return result;
} }
catch (NamingException e) { catch (NamingException ex) {
// This will be thrown if an invalid user name is used and the method may // This will be thrown if an invalid user name is used and the method may
// be called multiple times to try different names, so we trap the exception // be called multiple times to try different names, so we trap the exception
// unless a subclass wishes to implement more specialized behaviour. // unless a subclass wishes to implement more specialized behaviour.
if ((e instanceof org.springframework.ldap.AuthenticationException) if ((ex instanceof org.springframework.ldap.AuthenticationException)
|| (e instanceof org.springframework.ldap.OperationNotSupportedException)) { || (ex instanceof org.springframework.ldap.OperationNotSupportedException)) {
handleBindException(userDnStr, username, e); handleBindException(userDnStr, username, ex);
} }
else { else {
throw e; throw ex;
} }
} }
catch (javax.naming.NamingException e) { catch (javax.naming.NamingException ex) {
throw LdapUtils.convertLdapException(e); throw LdapUtils.convertLdapException(ex);
} }
finally { finally {
LdapUtils.closeContext(ctx); LdapUtils.closeContext(ctx);

Some files were not shown because too many files have changed in this diff Show More