]> source.dussan.org Git - archiva.git/commitdiff
Improving error handling for LDAP configuration
authorMartin Stockhammer <martin_s@apache.org>
Sun, 2 Oct 2016 13:20:56 +0000 (15:20 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 2 Oct 2016 13:20:56 +0000 (15:20 +0200)
Error is only displayed, if LDAP is used as repository. The error
messages are more detailed and internationalized.

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java
archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties

index 5d3aa8e40e2a2d3c47c6da80a19c7f7cca2ad837..e319c36291df2abb0384d75bdf43f9f5eeafea47 100644 (file)
@@ -132,6 +132,20 @@ public class DefaultRedbackRuntimeConfigurationService
                 rbacManagerChanged || ( redbackRuntimeConfiguration.getRbacManagerImpls().toString().hashCode()
                     != redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getRbacManagerImpls().toString().hashCode() );
 
+            boolean ldapConfigured = false;
+            for (String um : redbackRuntimeConfiguration.getUserManagerImpls()) {
+                if (um.contains("ldap")) {
+                    ldapConfigured=true;
+                }
+            }
+            if (!ldapConfigured) {
+                for (String rbm : redbackRuntimeConfiguration.getRbacManagerImpls()) {
+                    if (rbm.contains("ldap")) {
+                        ldapConfigured = true;
+                    }
+                }
+            }
+
             redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
 
             if ( userManagerChanged )
@@ -149,8 +163,15 @@ public class DefaultRedbackRuntimeConfigurationService
                 roleManager.initialize();
             }
 
-            ldapConnectionFactory.initialize();
-
+            if (ldapConfigured) {
+                try {
+                    ldapConnectionFactory.initialize();
+                } catch (Exception e) {
+                    ArchivaRestServiceException newEx = new ArchivaRestServiceException(e.getMessage(), e);
+                    newEx.setErrorKey("error.ldap.connectionFactory.init.failed");
+                    throw newEx;
+                }
+            }
             Collection<PasswordRule> passwordRules = applicationContext.getBeansOfType( PasswordRule.class ).values();
 
             for ( PasswordRule passwordRule : passwordRules )
@@ -184,16 +205,27 @@ public class DefaultRedbackRuntimeConfigurationService
             usersCache.setMaxElementsOnDisk(
                 redbackRuntimeConfiguration.getUsersCacheConfiguration().getMaxElementsOnDisk() );
 
-            ldapUserMapper.initialize();
+            if (ldapConfigured) {
+                try {
+                    ldapUserMapper.initialize();
+                } catch (Exception e) {
+                    ArchivaRestServiceException newEx = new ArchivaRestServiceException(e.getMessage(), e);
+                    newEx.setErrorKey("error.ldap.userMapper.init.failed");
+                    throw newEx;
+                }
+            }
 
             //check repositories roles are here !!!
 
             return Boolean.TRUE;
         }
-        catch ( Exception e )
+        catch (ArchivaRestServiceException e) {
+            log.error(e.getMessage(), e);
+            throw e;
+        } catch ( Exception e )
         {
             log.error( e.getMessage(), e );
-            throw new ArchivaRestServiceException( e.getMessage(), e );
+            throw new ArchivaRestServiceException(e.getMessage(), e);
         }
     }
 
index 34672bd6b04f79253bece237b6c19b521cd9ddb0..b5784b64b2655f4de4b684ecb9addc568f5d1181 100644 (file)
@@ -612,6 +612,7 @@ redback-runtime-configuration.title=Redback Runtime Configuration
 redback-runtime-configuration.updated=Redback Runtime Configuration updated.
 archiva.redback.usermanager.ldap=LDAP User Manager
 archiva.redback.usermanager.jdo=Database User Manager
+archiva.redback.usermanager.jpa=Database JPA User Manager
 redback.runtime.properties.help.title=Property Description
 security.policy.password.rule.alphacount.enabled.help.content=Minimum of letter characters in the password.
 security.policy.password.rule.reuse.enabled.help.content=Prevent reuse of previous passwords.
@@ -672,6 +673,7 @@ redback.runtime.users.cache.title=Users Cache
 
 archiva.redback.rbacmanager.ldap=LDAP RBac Manager
 archiva.redback.rbacmanager.jdo=Database RBac Manager
+archiva.redback.rbackmanager.jpa=Database JPA RBac Manager
 archiva.redback.rbacmanager.cached=Cached RBac Manager
 redback.runtime.rbac-managers.impls.chose=RbacManager(s) chosen
 redback.runtime.rbac-managers.impls.available=Available RbacManagers
@@ -717,3 +719,6 @@ navigation.next=Next
 navigation.first=First
 navigation.last=Last
 
+# Error messages for LDAP configuration
+error.ldap.connectionFactory.init.failed=Could not initialize LDAP connection factory. Check your LDAP configuration.
+error.ldap.userMapper.init.failed=Could not initialize LDAP user mapper. Check your LDAP configuration.