]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4262: Added code to read env variables for Nuxeo username and password that...
authorRichard Millet <richard.millet@berkeley.edu>
Tue, 9 Aug 2011 22:48:35 +0000 (22:48 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Tue, 9 Aug 2011 22:48:35 +0000 (22:48 +0000)
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoConnector.java

index 0de8fedf1bc8d1c6b69ec1216481f3ec423ccc1b..ae1ee63e206d45b1dc464d884e44aa869ab09cd8 100644 (file)
@@ -46,6 +46,8 @@ public class NuxeoConnector {
     public final static String NUXEO_CLIENT_DIR = "nuxeo-client";
     private Logger logger = LoggerFactory.getLogger(NuxeoConnector.class);
     private static final NuxeoConnector self = new NuxeoConnector();
+       private static final String NUXEO_CLIENT_USERNAME = "NUXEO_CLIENT_USERNAME";
+       private static final String NUXEO_CLIENT_PASSWORD = "NUXEO_CLIENT_PASSWORD";
     private NuxeoApp app;
     private NuxeoClient client;
     private volatile boolean initialized = false; //use volatile for lazy initialization in singleton
@@ -58,6 +60,22 @@ public class NuxeoConnector {
         return self;
     }
 
+    private String getClientUserName(RepositoryClientConfigType repositoryClientConfig) {
+       String username = System.getenv(NUXEO_CLIENT_USERNAME);
+       if (username == null) {
+               username = repositoryClientConfig.getUser();
+       }
+       return username;
+    }
+    
+    private String getClientPassword(RepositoryClientConfigType repositoryClientConfig) {
+       String password = System.getenv(NUXEO_CLIENT_PASSWORD);
+       if (password == null) {
+               password = repositoryClientConfig.getPassword();
+       }
+       return password;
+    }
+    
     /**
      * initialize initialize the Nuxeo connector. It makes sure that the connector
      * is initialized in a thread-safe manner and not initialized more than once.
@@ -81,8 +99,11 @@ public class NuxeoConnector {
                         }
                         loadBundles();
                         client = NuxeoClient.getInstance();
-                        DefaultLoginHandler loginHandler = new DefaultLoginHandler(
-                                repositoryClientConfig.getUser(), repositoryClientConfig.getPassword());
+                        String username = getClientUserName(repositoryClientConfig);
+                        String password = getClientPassword(repositoryClientConfig);
+//                        DefaultLoginHandler loginHandler = new DefaultLoginHandler(
+//                                repositoryClientConfig.getUser(), repositoryClientConfig.getPassword());
+                        DefaultLoginHandler loginHandler = new DefaultLoginHandler(username, password);
                         client.setLoginHandler(loginHandler);
                         client.connect(repositoryClientConfig.getHost(),
                                 repositoryClientConfig.getPort());