]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1807] Archiva wrapper fail to start
authorOlivier Lamy <olamy@apache.org>
Wed, 5 Nov 2014 10:39:00 +0000 (21:39 +1100)
committerOlivier Lamy <olamy@apache.org>
Wed, 5 Nov 2014 10:39:00 +0000 (21:39 +1100)
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/runtime/RedbackRuntimeConfigurationAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultRedbackRuntimeConfigurationAdmin.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaRbacManager.java

index 3bb9a11990391285936a7f11fdf2c47f3b766a6a..8fae6a66ad219e5b915ea033d41ff48d2a650113 100644 (file)
@@ -27,6 +27,11 @@ import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
  */
 public interface RedbackRuntimeConfigurationAdmin
 {
+
+    static final String DEFAULT_RBAC_MANAGER_IMPL = "jdo";
+
+    static final String DEFAULT_USER_MANAGER_IMPL = "jdo";
+
     RedbackRuntimeConfiguration getRedbackRuntimeConfiguration()
         throws RepositoryAdminException;
 
index 2ff43b3d0e2a2eb579b8e0a239f54c056340138b..34ed1b606ef38016d1702bdf215f395a5ea92822 100644 (file)
@@ -52,7 +52,7 @@ import java.util.Set;
  * @author Olivier Lamy
  * @since 1.4-M4
  */
-@Service("redbackRuntimeConfigurationAdmin#default")
+@Service( "redbackRuntimeConfigurationAdmin#default" )
 public class DefaultRedbackRuntimeConfigurationAdmin
     extends AbstractRepositoryAdmin
     implements RedbackRuntimeConfigurationAdmin, UserConfiguration
@@ -68,9 +68,9 @@ public class DefaultRedbackRuntimeConfigurationAdmin
 
     @Inject
     public DefaultRedbackRuntimeConfigurationAdmin( ArchivaConfiguration archivaConfiguration,//
-                                                    @Named(value = "userConfiguration#redback") //
+                                                    @Named( value = "userConfiguration#redback" ) //
                                                         UserConfiguration userConfiguration,
-                                                    @Named(value = "cache#users") Cache usersCache )
+                                                    @Named( value = "cache#users" ) Cache usersCache )
     {
         this.archivaConfiguration = archivaConfiguration;
         this.userConfiguration = userConfiguration;
@@ -92,7 +92,8 @@ public class DefaultRedbackRuntimeConfigurationAdmin
                 redbackRuntimeConfiguration = new RedbackRuntimeConfiguration();
                 // so migrate if available
                 String userManagerImpl =
-                    userConfiguration.getConcatenatedList( UserConfigurationKeys.USER_MANAGER_IMPL, "jdo" );
+                    userConfiguration.getConcatenatedList( UserConfigurationKeys.USER_MANAGER_IMPL, //
+                                                           DEFAULT_USER_MANAGER_IMPL );
                 if ( StringUtils.isNotEmpty( userManagerImpl ) )
                 {
                     String[] impls = StringUtils.split( userManagerImpl, ',' );
@@ -101,9 +102,14 @@ public class DefaultRedbackRuntimeConfigurationAdmin
                         redbackRuntimeConfiguration.getUserManagerImpls().add( impl );
                     }
                 }
+                else
+                {
+                    redbackRuntimeConfiguration.getUserManagerImpls().add( DEFAULT_USER_MANAGER_IMPL );
+                }
 
                 String rbacManagerImpls =
-                    userConfiguration.getConcatenatedList( UserConfigurationKeys.RBAC_MANAGER_IMPL, "jdo" );
+                    userConfiguration.getConcatenatedList( UserConfigurationKeys.RBAC_MANAGER_IMPL, //
+                                                           DEFAULT_RBAC_MANAGER_IMPL );
 
                 if ( StringUtils.isNotEmpty( rbacManagerImpls ) )
                 {
@@ -113,6 +119,10 @@ public class DefaultRedbackRuntimeConfigurationAdmin
                         redbackRuntimeConfiguration.getRbacManagerImpls().add( impl );
                     }
                 }
+                else
+                {
+                    redbackRuntimeConfiguration.getRbacManagerImpls().add( DEFAULT_RBAC_MANAGER_IMPL );
+                }
 
                 // now ldap
 
@@ -132,16 +142,13 @@ public class DefaultRedbackRuntimeConfigurationAdmin
 
                 ldapConfiguration.setBaseGroupsDn(
                     userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_GROUPS_BASEDN,
-                                                           ldapConfiguration.getBaseDn() )
-                );
+                                                           ldapConfiguration.getBaseDn() ) );
 
                 ldapConfiguration.setContextFactory(
                     userConfiguration.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY,
                                                  isSunContextFactoryAvailable()
                                                      ? "com.sun.jndi.ldap.LdapCtxFactory"
-                                                     : ""
-                    )
-                );
+                                                     : "" ) );
                 ldapConfiguration.setBindDn(
                     userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BINDDN, null ) );
                 ldapConfiguration.setPassword(
index 0628eb12b35d386ebfc6cca14a49fd99ad31f9a9..143f3c21bec1eb7e1e3497dceed20843e8b81f90 100644 (file)
@@ -98,6 +98,11 @@ public class ArchivaRbacManager
             List<String> rbacManagerIds =
                 redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getRbacManagerImpls();
 
+            if ( rbacManagerIds.isEmpty() )
+            {
+                rbacManagerIds.add( RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL );
+            }
+
             log.info( "use rbacManagerIds: '{}'", rbacManagerIds );
 
             this.rbacManagersPerId = new LinkedHashMap<>( rbacManagerIds.size() );
@@ -111,7 +116,7 @@ public class ArchivaRbacManager
         }
         catch ( RepositoryAdminException e )
         {
-            // revert to a default one ?
+
             log.error( e.getMessage(), e );
             throw new RuntimeException( e.getMessage(), e );
         }
@@ -126,7 +131,9 @@ public class ArchivaRbacManager
                 return rbacManager;
             }
         }
-        return this.rbacManagersPerId.values().iterator().next();
+        return this.rbacManagersPerId.isEmpty() ? applicationContext.getBean(
+            "rbacManager#" + RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL, RBACManager.class ) //
+            : this.rbacManagersPerId.values().iterator().next();
     }
 
     @Override
@@ -294,7 +301,7 @@ public class ArchivaRbacManager
     @Override
     public Permission createPermission( String name, String operationName, String resourceIdentifier )
         throws RbacManagerException
-  {
+    {
         return getRbacManagerForWrite().createPermission( name, operationName, resourceIdentifier );
     }
 
@@ -418,7 +425,7 @@ public class ArchivaRbacManager
         if ( lastException != null && allFailed )
         {
             throw new RbacManagerException( lastException.getMessage(), lastException );
-       }
+        }
     }
 
     @Override
@@ -609,7 +616,7 @@ public class ArchivaRbacManager
                     return r;
                 }
             }
-          catch ( Exception e )
+            catch ( Exception e )
             {
                 lastException = e;
             }
@@ -700,7 +707,7 @@ public class ArchivaRbacManager
                 {
                     userAssignment = rbacManager.saveUserAssignment( userAssignment );
                     allFailed = false;
-               }
+                }
             }
             catch ( Exception e )
             {
@@ -793,7 +800,7 @@ public class ArchivaRbacManager
     {
         for ( RBACManager rbacManager : rbacManagersPerId.values() )
         {
-           try
+            try
             {
                 boolean exists = rbacManager.userAssignmentExists( assignment );
                 if ( exists )
@@ -929,7 +936,7 @@ public class ArchivaRbacManager
             }
             catch ( Exception e )
             {
-            lastException = e;
+                lastException = e;
             }
         }