Making ldapconnection autocloseable

This commit is contained in:
Martin Stockhammer 2021-01-17 11:10:34 +01:00
parent d3b81be613
commit ed06b9d673
2 changed files with 38 additions and 4 deletions

View File

@ -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;
@ -319,9 +320,16 @@ public class DefaultRedbackRuntimeConfigurationService
{
if ( ldapConnection != null )
{
try
{
ldapConnection.close();
}
catch ( NamingException e )
{
log.error( "Could not close connection: {}", e.getMessage( ), e );
}
}
}
return Boolean.TRUE;
@ -370,13 +378,24 @@ 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 )
{
try
{
ldapConnection.close();
}
catch ( NamingException e )
{
log.error( "Could not close connection: {}", e.getMessage( ), e );
}
}
}
return Boolean.TRUE;

View File

@ -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;
@ -511,9 +512,16 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
finally
{
if ( ldapConnection != null )
{
try
{
ldapConnection.close( );
}
catch ( NamingException e )
{
log.error( "Could not close connection: {}", e.getMessage( ) );
}
}
ldapConnection = null;
}
@ -544,9 +552,16 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
finally
{
if ( ldapConnection != null )
{
try
{
ldapConnection.close( );
}
catch ( NamingException e )
{
log.error( "Could not close connection: {}", e.getMessage( ), e );
}
}
}
return Response.ok( ).build( );