Author: olamy
Date: Tue Dec  4 15:06:42 2012
New Revision: 1416978

URL: http://svn.apache.org/viewvc?rev=1416978&view=rev
Log:
not use a RuntimeException when fail to connect to ldap exception is not know 
by caller methods

Modified:
    
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java

Modified: 
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java
URL: 
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java?rev=1416978&r1=1416977&r2=1416978&view=diff
==============================================================================
--- 
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java
 (original)
+++ 
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java
 Tue Dec  4 15:06:42 2012
@@ -94,23 +94,25 @@ public class LdapBindAuthenticator
         ctls.setDerefLinkFlag( true );
         ctls.setSearchScope( SearchControls.SUBTREE_SCOPE );
 
-        String filter = "(&(objectClass=" + mapper.getUserObjectClass() + ")"
-            + ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) 
+ "(" + mapper.getUserIdAttribute() + "="
-            + source.getPrincipal() + "))";
+        String filter = "(&(objectClass=" + mapper.getUserObjectClass() + ")" 
+ ( mapper.getUserFilter() != null
+            ? mapper.getUserFilter()
+            : "" ) + "(" + mapper.getUserIdAttribute() + "=" + 
source.getPrincipal() + "))";
 
         log.debug( "Searching for users with filter: '{}' from base dn: {}", 
filter, mapper.getUserBaseDn() );
-                                                              
-        LdapConnection ldapConnection = getLdapConnection();
+
+        LdapConnection ldapConnection = null;
         LdapConnection authLdapConnection = null;
         NamingEnumeration<SearchResult> results = null;
         try
         {
+            ldapConnection = getLdapConnection();
             // check the cache for user's userDn in the ldap server
             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();
 
@@ -168,16 +170,9 @@ public class LdapBindAuthenticator
     }
 
     private LdapConnection getLdapConnection()
+        throws LdapException
     {
-        try
-        {
-            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 );
-        }
+        return connectionFactory.getConnection();
     }
 
     private void closeLdapConnection( LdapConnection ldapConnection )


Reply via email to