apache ranger2.0 添加策略roles没有搜索功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache ranger2.0 添加策略roles没有搜索功能相关的知识,希望对你有一定的参考价值。

参考技术A 1.出现的问题如下

在输入roles name后,候选项没有更新。在看源码是发现是调用的RoleREST.java接口没有获取传入的name参数

2.解决

org.apache.ranger.rest.RoleREST 类  /roles方法

改为如下:

@GET

@Path("/roles")

public RangerRoleList getAllRoles(@Context HttpServletRequest request, @PathParam("name") String name)

    RangerRoleList ret = new RangerRoleList();

    if (LOG.isDebugEnabled())

        LOG.debug("==> getAllRoles()");

    

    String name = request.getParameter("name");

    SearchFilter filter = searchUtil.getSearchFilter(request, roleService.sortFields);

    List<RangerRole> roles;

    try 

        ensureAdminAccess(null, null);

        roles = roleStore.getRoles(filter);

        ret.setRoleList(roles);

        List res = new LinkedList<>();

        if (name != null)

            name = name.trim();

        

        if (name != null && name.length() > 0)

            for (RangerRole rs : roles)

                int index = rs.getName().indexOf(name);

                if (index > 0)

                    res.add(rs);

                

            

            roles = res;

        

        ret.setRoleList(roles);

        if (roles != null)

            ret.setTotalCount(roles.size());

            ret.setSortBy(filter.getSortBy());

            ret.setSortType(filter.getSortType());

            ret.setResultSize(roles.size());

        

     catch(WebApplicationException excp)

        throw excp;

     catch(Throwable excp)

        LOG.error("getRoles() failed", excp);

        throw restErrorUtil.createRESTException(excp.getMessage());

    

    if (LOG.isDebugEnabled())

        LOG.debug("<== getAllRoles():" + ret);

    

    return ret;



改完后从新编译 成功后 替换 admin包下的RoleREST.class 类 。

替换完后,重启即可解决

apache ranger源码编译

官方文档 http://ranger.apache.org/quick_start_guide.html

Quick Start Guide

Build Process

1. Check out the code from GIT repository

    git clone https://gitbox.apache.org/repos/asf/ranger.git

    cd ranger 

Alternatively, you can checkout the code from github:

    git clone https://github.com/apache/ranger

    cd ranger 

2. Please execute the following Maven command:

    $ export JAVA_HOME=%jdk 7 Home%

    $ mvn clean 

    $ mvn -DskipTests=false clean compile package install assembly:assembly 

3. After the above build command execution, you should see the following TAR files in the target folder:

ranger-%version-number%-%module-name%.tar.gz

 

Create an Apache Release

1. Checkout from ranger release branch

$ git checkout ranger-%version%

 

2. Run maven commands to build and validate the build is working fine (See Build Process: step 2):

    $ export JAVA_HOME=%jdk 7 Home%

    $ mvn clean 

    $ mvn -DskipTests=false clean compile package install assembly:assembly 

3. Clean all generated files for building the source build

$ mvn clean

 

4. Create a TAR source file using the following command:

$ ant -f release-build.xml -Dranger-release-version=%version-number%

 

5. Now, the following files are ready to be published for release:

     ./target/apache-ranger-%version-number%.tar.gz
    ./target/apache-ranger-%version-number%.tar.gz.asc
    ./target/apache-ranger-%version-number%.tar.gz.mds

实战

编译环境:

root@greenvm-v1:~/Downloads/ranger# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
root@greenvm-v1:~/Downloads/ranger# mvn -v
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: /home/h/pkg/mvn
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /home/h/pkg/jdk1.8.0_181/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-31-generic", arch: "amd64", family: "unix"

编译命令:

mvn -DskipTests clean compile package install assembly:assembly

编译结果:(我这里是导入ubuntu系统中idea编译的,方便查看源码)

 

以上是关于apache ranger2.0 添加策略roles没有搜索功能的主要内容,如果未能解决你的问题,请参考以下文章

如何在 ASP.NET Core for JWT 中添加角色策略?

AWS EMR内置Ranger插件使用的IAM Role及其设计策略

AWS EMR内置Ranger插件使用的IAM Role及其设计策略

AWS EMR内置Ranger插件使用的IAM Role及其设计策略

Terraform:将 AWS 托管策略附加到角色的正确方法?

创建角色会出错