Upport authentication to remote repository
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 2 Mar 2012 16:40:22 +0000 (16:40 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 2 Mar 2012 16:40:22 +0000 (16:40 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5137 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.aether/src/main/java/org/argeo/slc/aether/spring/RemoteRepositoryFactory.java

index d945b3a56458b8f6e42941bff21f860a8350160e..e674112863bf407481e6b4521ce391b52680b460 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.slc.aether.spring;
 
+import org.sonatype.aether.repository.Authentication;
 import org.sonatype.aether.repository.RemoteRepository;
 import org.springframework.beans.factory.BeanNameAware;
 import org.springframework.beans.factory.FactoryBean;
@@ -10,9 +11,18 @@ public class RemoteRepositoryFactory implements BeanNameAware, FactoryBean {
        private String id;
        private String url;
        private String type = "default";
+       private String username;
+       private String password;
 
        public Object getObject() throws Exception {
-               return new RemoteRepository(id != null ? id : beanName, type, url);
+               RemoteRepository remoteRepository = new RemoteRepository(
+                               id != null ? id : beanName, type, url);
+               if (username != null) {
+                       Authentication authentication = new Authentication(username,
+                                       password);
+                       remoteRepository.setAuthentication(authentication);
+               }
+               return remoteRepository;
        }
 
        public Class<?> getObjectType() {
@@ -40,4 +50,12 @@ public class RemoteRepositoryFactory implements BeanNameAware, FactoryBean {
                this.type = type;
        }
 
+       public void setUsername(String username) {
+               this.username = username;
+       }
+
+       public void setPassword(String password) {
+               this.password = password;
+       }
+
 }