]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1718] ldap configuration editable with the ui.
authorOlivier Lamy <olamy@apache.org>
Tue, 4 Dec 2012 18:22:28 +0000 (18:22 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 4 Dec 2012 18:22:28 +0000 (18:22 +0000)
WORK IN PROGRESS !

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1417093 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ArchivaLdapConfiguration.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ArchivaRuntimeConfiguration.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/runtime/ArchivaRuntimeConfigurationAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultArchivaRuntimeConfigurationAdmin.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaRuntimeConfigurationService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js

index ee9ff6d4b44de3bb37b5607dcd1673693d6ac2fa..a66d8d6bbf8705ba9983657729e8ff1c2f60c488 100644 (file)
@@ -26,7 +26,7 @@ import java.util.Map;
  * @author Olivier Lamy
  * @since 1.4-M4
  */
-@XmlRootElement ( name = "archivaLdapConfiguration" )
+@XmlRootElement( name = "archivaLdapConfiguration" )
 public class ArchivaLdapConfiguration
 {
 
@@ -39,7 +39,7 @@ public class ArchivaLdapConfiguration
     /**
      * The LDAP port.
      */
-    private String port;
+    private int port;
 
     /**
      * ssl LDAP connection.
@@ -71,6 +71,11 @@ public class ArchivaLdapConfiguration
      */
     private String authenticationMethod;
 
+    /**
+     *
+     */
+    private boolean bindAuthenticatorEnabled;
+
     /**
      * Field extraProperties.
      */
@@ -91,12 +96,12 @@ public class ArchivaLdapConfiguration
         this.hostName = hostName;
     }
 
-    public String getPort()
+    public int getPort()
     {
         return port;
     }
 
-    public void setPort( String port )
+    public void setPort( int port )
     {
         this.port = port;
     }
@@ -170,4 +175,14 @@ public class ArchivaLdapConfiguration
     {
         this.extraProperties = extraProperties;
     }
+
+    public boolean isBindAuthenticatorEnabled()
+    {
+        return bindAuthenticatorEnabled;
+    }
+
+    public void setBindAuthenticatorEnabled( boolean bindAuthenticatorEnabled )
+    {
+        this.bindAuthenticatorEnabled = bindAuthenticatorEnabled;
+    }
 }
index f100d3c0449f8fbe67a0f966ca96acae1d770c2d..426b9b60374cade41201d71276e1430a9bc51bb5 100644 (file)
@@ -25,7 +25,7 @@ import java.io.Serializable;
  * @author Olivier Lamy
  * @since 1.4-M4
  */
-@XmlRootElement (name = "archivaRuntimeConfiguration")
+@XmlRootElement(name = "archivaRuntimeConfiguration")
 public class ArchivaRuntimeConfiguration
     implements Serializable
 {
@@ -33,6 +33,11 @@ public class ArchivaRuntimeConfiguration
 
     private ArchivaLdapConfiguration archivaLdapConfiguration;
 
+    /**
+     * flag to know if redback configuration has been checked/migrated.
+     */
+    private boolean migratedFromRedbackConfiguration = false;
+
     public ArchivaRuntimeConfiguration()
     {
         // no op
@@ -57,4 +62,24 @@ public class ArchivaRuntimeConfiguration
     {
         this.archivaLdapConfiguration = archivaLdapConfiguration;
     }
+
+    public boolean isMigratedFromRedbackConfiguration()
+    {
+        return migratedFromRedbackConfiguration;
+    }
+
+    public void setMigratedFromRedbackConfiguration( boolean migratedFromRedbackConfiguration )
+    {
+        this.migratedFromRedbackConfiguration = migratedFromRedbackConfiguration;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "ArchivaRuntimeConfiguration{" +
+            "userManagerImpl='" + userManagerImpl + '\'' +
+            ", archivaLdapConfiguration=" + archivaLdapConfiguration +
+            ", migratedFromRedbackConfiguration=" + migratedFromRedbackConfiguration +
+            '}';
+    }
 }
index 5139f974d9eed8856a9a33aa06470d0efbcde601..9cf37ee566a59dcab9f1d7aa7acee6a9d9e630e3 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
  */
 public interface ArchivaRuntimeConfigurationAdmin
 {
-    ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
+    ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
         throws RepositoryAdminException;
 
     void updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
index 76e33f990ffec9ad46b2974267a060c7d749f3d6..aada4b2f295b19b3fbec25e06e363675ae08f463 100644 (file)
@@ -18,7 +18,9 @@ package org.apache.archiva.admin.repository.runtime;
  * under the License.
  */
 
+import net.sf.beanlib.provider.replicator.BeanReplicator;
 import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.beans.ArchivaLdapConfiguration;
 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
 import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
@@ -26,20 +28,72 @@ import org.apache.archiva.configuration.Configuration;
 import org.apache.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.archiva.configuration.RuntimeConfiguration;
 import org.apache.archiva.redback.components.registry.RegistryException;
+import org.apache.archiva.redback.configuration.UserConfiguration;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+
 /**
  * @author Olivier Lamy
  * @since 1.4-M4
  */
-@Service ( "archivaRuntimeConfigurationAdmin#default" )
+@Service( "archivaRuntimeConfigurationAdmin#default" )
 public class DefaultArchivaRuntimeConfigurationAdmin
     extends AbstractRepositoryAdmin
     implements ArchivaRuntimeConfigurationAdmin
 {
 
+    @Inject
+    @Named( value = "userConfiguration" )
+    UserConfiguration userConfiguration;
+
+    @PostConstruct
+    public void initialize()
+        throws RepositoryAdminException
+    {
+        ArchivaRuntimeConfiguration archivaRuntimeConfiguration = getArchivaRuntimeConfiguration();
+        // migrate or not data from redback
+        if ( !archivaRuntimeConfiguration.isMigratedFromRedbackConfiguration() )
+        {
+            // so migrate if available
+            String userManagerImpl = userConfiguration.getString( "user.manager.impl" );
+            if ( StringUtils.isNotEmpty( userManagerImpl ) )
+            {
+                archivaRuntimeConfiguration.setUserManagerImpl( userManagerImpl );
+            }
+
+            // now ldap
+
+            ArchivaLdapConfiguration archivaLdapConfiguration =
+                archivaRuntimeConfiguration.getArchivaLdapConfiguration();
+            if ( archivaLdapConfiguration == null )
+            {
+                archivaLdapConfiguration = new ArchivaLdapConfiguration();
+                archivaRuntimeConfiguration.setArchivaLdapConfiguration( archivaLdapConfiguration );
+            }
+
+            archivaLdapConfiguration.setHostName( userConfiguration.getString( "ldap.config.hostname", null ) );
+            archivaLdapConfiguration.setPort( userConfiguration.getInt( "ldap.config.port", -1 ) );
+            archivaLdapConfiguration.setSsl( userConfiguration.getBoolean( "ldap.config.ssl", false ) );
+            archivaLdapConfiguration.setBaseDn( userConfiguration.getConcatenatedList( "ldap.config.base.dn", null ) );
+            archivaLdapConfiguration.setContextFactory(
+                userConfiguration.getString( "ldap.config.context.factory", null ) );
+            archivaLdapConfiguration.setBindDn( userConfiguration.getConcatenatedList( "ldap.config.bind.dn", null ) );
+            archivaLdapConfiguration.setPassword( userConfiguration.getString( "ldap.config.password", null ) );
+            archivaLdapConfiguration.setAuthenticationMethod(
+                userConfiguration.getString( "ldap.config.authentication.method", null ) );
+
+            archivaRuntimeConfiguration.setMigratedFromRedbackConfiguration( true );
+
+            updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
+        }
+
+    }
 
-    public ArchivaRuntimeConfiguration getArchivaRuntimeConfigurationAdmin()
+    public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
         throws RepositoryAdminException
     {
         return build( getArchivaConfiguration().getConfiguration().getRuntimeConfiguration() );
@@ -67,15 +121,11 @@ public class DefaultArchivaRuntimeConfigurationAdmin
 
     private ArchivaRuntimeConfiguration build( RuntimeConfiguration runtimeConfiguration )
     {
-        ArchivaRuntimeConfiguration archivaRuntimeConfiguration = new ArchivaRuntimeConfiguration();
-        archivaRuntimeConfiguration.setUserManagerImpl( runtimeConfiguration.getUserManagerImpl() );
-        return archivaRuntimeConfiguration;
+        return new BeanReplicator().replicateBean( runtimeConfiguration, ArchivaRuntimeConfiguration.class );
     }
 
     private RuntimeConfiguration build( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
     {
-        RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration();
-        runtimeConfiguration.setUserManagerImpl( archivaRuntimeConfiguration.getUserManagerImpl() );
-        return runtimeConfiguration;
+        return new BeanReplicator().replicateBean( archivaRuntimeConfiguration, RuntimeConfiguration.class );
     }
 }
index df0b6eeb7d48e7edc3918e7306d3bb8b53fbf125..88a7d51d8ec88064e949e0eb96a604a5a02ef573 100644 (file)
@@ -60,7 +60,7 @@ public class DefaultArchivaRuntimeConfigurationService
     {
         try
         {
-            return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfigurationAdmin();
+            return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration();
         }
         catch ( RepositoryAdminException e )
         {
@@ -75,7 +75,7 @@ public class DefaultArchivaRuntimeConfigurationService
         {
             // has user manager impl changed ?
             boolean userManagerChanged = !StringUtils.equals( archivaRuntimeConfiguration.getUserManagerImpl(),
-                                                              archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfigurationAdmin().getUserManagerImpl() );
+                                                              archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration().getUserManagerImpl() );
             archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
 
             if ( userManagerChanged )
index 5a2a08e9b6be6e97ac8690b041e002d9e9f04603..c6ef0b6007f817092b3883e1d9e48a6d3a63bbc2 100644 (file)
@@ -48,7 +48,7 @@ public class ArchivaConfigurableUsersManager
         try
         {
             String userManagerImplStr =
-                archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfigurationAdmin().getUserManagerImpl();
+                archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration().getUserManagerImpl();
             log.info( "use userManagerImpl: '{}'", userManagerImplStr );
             UserManager userManagerImpl =
                 applicationContext.getBean( "userManager#" + userManagerImplStr, UserManager.class );
index 6a2378e0b8f87c34f41c1a8fce4d055b76f5dd83..343ddef077a37b71828edb2aa912131ade812542 100644 (file)
@@ -253,12 +253,13 @@ require(["jquery","jquery.tmpl","i18n","knockout"], function(jquery,jqueryTmpl,i
       $.log("displayRedbackError with array");
       for(var i=0; i<obj.errorMessages.length; i++ ) {
         if(obj.errorMessages[i].errorKey) {
-          $.log("displayRedbackError with array loop");
           displayErrorMessage($.i18n.prop( obj.errorMessages[i].errorKey, obj.errorMessages[i].args ),idToAppend);
         }
+        if(obj.errorMessages[i].message) {
+          displayErrorMessage(obj.errorMessages[i].message,idToAppend);
+        }
       }
     } else {
-      $.log("displayRedbackError no array");
       displayErrorMessage($.i18n.prop( obj.errorMessages.errorKey, obj.errorMessages.args ),idToAppend);
     }
   }
@@ -301,7 +302,9 @@ require(["jquery","jquery.tmpl","i18n","knockout"], function(jquery,jqueryTmpl,i
       displayErrorMessage($.i18n.prop( data.errorKey ),idToAppend);
     } else if (data.errorMessages){
       $.each(data.errorMessages, function(index, value) {
-        displayErrorMessage( $.i18n.prop(data.errorMessages[index].errorKey,data.errorMessages[index].args?data.errorMessages[index].args:null),idToAppend);
+        if(data.errorMessages[index].errorKey) {
+          displayErrorMessage( $.i18n.prop(data.errorMessages[index].errorKey,data.errorMessages[index].args?data.errorMessages[index].args:null),idToAppend);
+        }
       });
     } else {
       $.log("print data.errorMessage:"+data.errorMessage);
@@ -396,6 +399,13 @@ require(["jquery","jquery.tmpl","i18n","knockout"], function(jquery,jqueryTmpl,i
   // utils javascript string extensions
   //------------------------------------
 
+  String.prototype.isEmpty = function(str) {
+    return ($.trim(this ).length < 1);
+  }
+  String.prototype.isNotEmpty = function(str) {
+    return ($.trim(this ).length > 0);
+  }
+
   String.prototype.endsWith = function(str) {
     return (this.match(str+"$")==str)
   }