not use a RuntimeException when fail to connect to ldap exception is not know by caller methods

git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1416978 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-04 15:06:42 +00:00
parent 2b060d6623
commit eed51a9447

View File

@ -94,23 +94,25 @@ public AuthenticationResult authenticate( AuthenticationDataSource s )
ctls.setDerefLinkFlag( true ); ctls.setDerefLinkFlag( true );
ctls.setSearchScope( SearchControls.SUBTREE_SCOPE ); ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
String filter = "(&(objectClass=" + mapper.getUserObjectClass() + ")" String filter = "(&(objectClass=" + mapper.getUserObjectClass() + ")" + ( mapper.getUserFilter() != null
+ ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + "(" + mapper.getUserIdAttribute() + "=" ? mapper.getUserFilter()
+ source.getPrincipal() + "))"; : "" ) + "(" + mapper.getUserIdAttribute() + "=" + source.getPrincipal() + "))";
log.debug( "Searching for users with filter: '{}' from base dn: {}", filter, mapper.getUserBaseDn() ); log.debug( "Searching for users with filter: '{}' from base dn: {}", filter, mapper.getUserBaseDn() );
LdapConnection ldapConnection = getLdapConnection(); LdapConnection ldapConnection = null;
LdapConnection authLdapConnection = null; LdapConnection authLdapConnection = null;
NamingEnumeration<SearchResult> results = null; NamingEnumeration<SearchResult> results = null;
try try
{ {
ldapConnection = getLdapConnection();
// check the cache for user's userDn in the ldap server // check the cache for user's userDn in the ldap server
String userDn = ldapCacheService.getLdapUserDn( source.getPrincipal() ); String userDn = ldapCacheService.getLdapUserDn( source.getPrincipal() );
if( userDn == null ) if ( userDn == null )
{ {
log.debug( "userDn for user {} not found in cache. Retrieving from ldap server..", source.getPrincipal() ); log.debug( "userDn for user {} not found in cache. Retrieving from ldap server..",
source.getPrincipal() );
DirContext context = ldapConnection.getDirContext(); DirContext context = ldapConnection.getDirContext();
@ -168,16 +170,9 @@ public boolean supportsDataSource( AuthenticationDataSource source )
} }
private LdapConnection getLdapConnection() private LdapConnection getLdapConnection()
throws LdapException
{ {
try return connectionFactory.getConnection();
{
return connectionFactory.getConnection();
}
catch ( LdapException e )
{
log.warn( "failed to get a ldap connection " + e.getMessage(), e );
throw new RuntimeException( "failed to get a ldap connection " + e.getMessage(), e );
}
} }
private void closeLdapConnection( LdapConnection ldapConnection ) private void closeLdapConnection( LdapConnection ldapConnection )