From ca9678f51e93ba1d36006a86d210901883ed1463 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Tue, 30 Jun 2009 18:37:32 +0000 Subject: [PATCH] CSPACE-229 to enable authn on the client, system properties required are cspace.auth=true cspace.user={username} and cspace.password={password} --- .../client/CollectionSpaceClient.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java index f50212f96..af6f4b37e 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java @@ -8,8 +8,10 @@ import org.slf4j.LoggerFactory; public abstract class CollectionSpaceClient { - static final String AUTH_PROPERTY = "org.collectionspace.auth"; - static final String SSL_PROPERTY = "org.collectionspace.ssl"; + static final String USER_PROPERTY = "cspace.user"; + static final String PASSWORD_PROPERTY = "cspace.password"; + static final String AUTH_PROPERTY = "cspace.auth"; + static final String SSL_PROPERTY = "cspace.ssl"; static final String URL_PROPERTY = "org.collectionspace.url"; /* static final String URL_PROPERTY_SCHEME = "org.collectionspace.url.schme"; @@ -40,9 +42,20 @@ public abstract class CollectionSpaceClient { useAuth = Boolean.getBoolean(AUTH_PROPERTY); if(useAuth){ httpClient = new HttpClient(); + String user = System.getProperty(USER_PROPERTY); + if(user == null || "".equals(user)){ + user = "test"; + } + String password = System.getProperty(PASSWORD_PROPERTY); + if(password == null || "".equals(password)){ + password = "test"; + } + if(logger.isDebugEnabled()){ + logger.debug("using user=" + user + " password=" + password); + } httpClient.getState().setCredentials( new AuthScope(HOST, PORT, AuthScope.ANY_REALM), - new UsernamePasswordCredentials("test", "test")); + new UsernamePasswordCredentials(user, password)); httpClient.getParams().setAuthenticationPreemptive(true); if(logger.isDebugEnabled()){ logger.debug("set up httpClient for authentication"); -- 2.47.3