RANGER-474 : Ranger usersync should instantiate the right class based on SYNC_SOURCE
Signed-off-by: Velmurugan Periasamy <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/5ac45ecc Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/5ac45ecc Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/5ac45ecc Branch: refs/heads/tag-policy Commit: 5ac45ecc0c7a2dbfe0630441795a0bdaab5ec8b3 Parents: f72e949 Author: Gautam Borad <[email protected]> Authored: Wed May 13 08:53:17 2015 +0530 Committer: Velmurugan Periasamy <[email protected]> Committed: Sun May 17 16:00:34 2015 -0400 ---------------------------------------------------------------------- .../config/UserGroupSyncConfig.java | 26 +++++++++++++++++--- unixauthservice/scripts/setup.py | 1 + .../templates/ranger-ugsync-template.xml | 4 +++ 3 files changed, 28 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/5ac45ecc/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java ---------------------------------------------------------------------- diff --git a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java index e079939..5aba0e9 100644 --- a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java +++ b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java @@ -164,6 +164,7 @@ public class UserGroupSyncConfig { private static final String DEFAULT_POLICYMGR_USERNAME = "rangerusersync"; private static final String DEFAULT_POLICYMGR_PASSWORD = "rangerusersync"; + private static final String SYNC_SOURCE = "ranger.usersync.sync.source"; private Properties prop = new Properties() ; private static volatile UserGroupSyncConfig me = null ; @@ -364,8 +365,15 @@ public class UserGroupSyncConfig { public UserGroupSource getUserGroupSource() throws Throwable { String val = prop.getProperty(UGSYNC_SOURCE_CLASS_PARAM) ; - if(val == null) { - val = UGSYNC_SOURCE_CLASS; + if(val == null || val.trim().isEmpty()) { + String syncSource=getSyncSource(); + if(syncSource!=null && syncSource.equalsIgnoreCase("UNIX")){ + val = UGSYNC_SOURCE_CLASS; + }else if(syncSource!=null && syncSource.equalsIgnoreCase("LDAP")){ + val = LGSYNC_SOURCE_CLASS; + }else{ + val = UGSYNC_SOURCE_CLASS; + } } Class<UserGroupSource> ugSourceClass = (Class<UserGroupSource>)Class.forName(val); @@ -379,7 +387,7 @@ public class UserGroupSyncConfig { public UserGroupSink getUserGroupSink() throws Throwable { String val = prop.getProperty(UGSYNC_SINK_CLASS_PARAM) ; - if(val == null) { + if(val == null || val.trim().isEmpty()) { val = UGSYNC_SINK_CLASS; } @@ -679,4 +687,16 @@ public class UserGroupSyncConfig { public String getDefaultPolicyMgrPassword(){ return DEFAULT_POLICYMGR_PASSWORD; } + public String getSyncSource() { + String syncSource=null; + if(prop!=null && prop.containsKey(SYNC_SOURCE)){ + syncSource=prop.getProperty(SYNC_SOURCE); + if(syncSource==null||syncSource.trim().isEmpty()){ + syncSource=null; + }else{ + syncSource=syncSource.trim(); + } + } + return syncSource; + } } http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/5ac45ecc/unixauthservice/scripts/setup.py ---------------------------------------------------------------------- diff --git a/unixauthservice/scripts/setup.py b/unixauthservice/scripts/setup.py index 4a4e276..e45ea63 100755 --- a/unixauthservice/scripts/setup.py +++ b/unixauthservice/scripts/setup.py @@ -194,6 +194,7 @@ def convertInstallPropsToXML(props): else: print "ERROR: Invalid value (%s) defined for %s in install.properties. Only valid values are %s" % (syncSource, SYNC_SOURCE_KEY,SYNC_SOURCE_LIST) sys.exit(1) + ret['ranger.usersync.sync.source'] = syncSource del ret['SYNC_SOURCE'] else: print "ERROR: No value defined for SYNC_SOURCE in install.properties. valid values are %s" % (SYNC_SOURCE_KEY, SYNC_SOURCE_LIST) http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/5ac45ecc/unixauthservice/scripts/templates/ranger-ugsync-template.xml ---------------------------------------------------------------------- diff --git a/unixauthservice/scripts/templates/ranger-ugsync-template.xml b/unixauthservice/scripts/templates/ranger-ugsync-template.xml index fd19bca..268deb3 100644 --- a/unixauthservice/scripts/templates/ranger-ugsync-template.xml +++ b/unixauthservice/scripts/templates/ranger-ugsync-template.xml @@ -177,4 +177,8 @@ <name>ranger.usersync.policymgr.keystore</name> <value></value> </property> + <property> + <name>ranger.usersync.sync.source</name> + <value></value> + </property> </configuration>
