From ed06b9d673a72ab9bb52297243a629dbb4f900a3 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 17 Jan 2021 11:10:34 +0100 Subject: [PATCH] Making ldapconnection autocloseable --- ...ultRedbackRuntimeConfigurationService.java | 23 +++++++++++++++++-- .../DefaultSecurityConfigurationService.java | 19 +++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java index 060de9ba3..81b58aa94 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java @@ -47,6 +47,7 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import javax.inject.Named; import javax.naming.InvalidNameException; +import javax.naming.NamingException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -320,7 +321,14 @@ public class DefaultRedbackRuntimeConfigurationService if ( ldapConnection != null ) { - ldapConnection.close(); + try + { + ldapConnection.close(); + } + catch ( NamingException e ) + { + log.error( "Could not close connection: {}", e.getMessage( ), e ); + } } } @@ -370,12 +378,23 @@ public class DefaultRedbackRuntimeConfigurationService log.warn( "fail to get ldapConnection: {}", e.getMessage(), e ); throw new ArchivaRestServiceException( e.getMessage(), e ); } + catch ( NamingException e ) + { + log.error( "Could not close connection: {}", e.getMessage( ), e ); + } finally { if ( ldapConnection != null ) { - ldapConnection.close(); + try + { + ldapConnection.close(); + } + catch ( NamingException e ) + { + log.error( "Could not close connection: {}", e.getMessage( ), e ); + } } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java index d5a435bf9..c8f9c6007 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java @@ -56,6 +56,7 @@ import javax.naming.AuthenticationException; import javax.naming.AuthenticationNotSupportedException; import javax.naming.CommunicationException; import javax.naming.InvalidNameException; +import javax.naming.NamingException; import javax.naming.NoPermissionException; import javax.naming.ServiceUnavailableException; import javax.ws.rs.core.Response; @@ -512,7 +513,14 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio { if ( ldapConnection != null ) { - ldapConnection.close( ); + try + { + ldapConnection.close( ); + } + catch ( NamingException e ) + { + log.error( "Could not close connection: {}", e.getMessage( ) ); + } } ldapConnection = null; } @@ -545,7 +553,14 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio { if ( ldapConnection != null ) { - ldapConnection.close( ); + try + { + ldapConnection.close( ); + } + catch ( NamingException e ) + { + log.error( "Could not close connection: {}", e.getMessage( ), e ); + } } } -- 2.39.5