1.简介
Ranger作为大数据组件的权限管理工具,在大数据平台领域有很重要的地位。但由于Ranger是一个独立的组件,组件的注册,策略的修改等,都需要登录到ranger,才能进行操作,很不利于大数据平台的统一管理与操作。所以,平台需要通过内部接口集成ranger的能力。相比以往,需要手动调用http接口,最新的2.1.0版本中已经提供具体的更加方便的访问接口(对Http接口进行了二次封装)。
2.引入jar
<dependency>
<groupId>org.apache.ranger</groupId>
<artifactId>ranger-intg</artifactId>
<version>2.1.0</version>
</dependency>
3.具体的接入代码
String username = "admin";
String password = "admin";
String host = "http://192.168.x.x:6080";
RangerClient rancherClient = new RangerClient(host, username, password);
String rangerServiceJson = "{\"name\":\"test2\",\"displayName\":\"\",\"description\":\"\",\"isEnabled\":true,\"tagService\":\"\",\"configs\":{\"username\":\"work\",\"password\":\"work\",\"fs.default.name\":\"hdfs://192.168.x.x:9000\",\"hadoop.security.authorization\":false,\"hadoop.security.authentication\":\"simple\",\"hadoop.security.auth_to_local\":\"\",\"dfs.datanode.kerberos.principal\":\"\",\"dfs.namenode.kerberos.principal\":\"\",\"dfs.secondary.namenode.kerberos.principal\":\"\",\"hadoop.rpc.protection\":\"authentication\",\"commonNameForCertificate\":\"\"},\"type\":\"hdfs\"}";
RangerService rangerService = gson.fromJson(rangerServiceJson, RangerService.class);
RangerService service = rancherClient.createService(rangerService);
System.out.println(gson.toJson(service));
|