Search in sources :

Example 26 with RangerRole

use of org.apache.ranger.plugin.model.RangerRole in project ranger by apache.

the class RolePredicateUtil method addPredicateForPartialRoleName.

private Predicate addPredicateForPartialRoleName(final String roleNamePartial, List<Predicate> predicates) {
    if (StringUtils.isEmpty(roleNamePartial)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerRole) {
                RangerRole role = (RangerRole) object;
                ret = StringUtils.containsIgnoreCase(role.getName(), roleNamePartial);
                if (!ret) {
                    List<RangerRole.RoleMember> roles = role.getRoles();
                    for (RangerRole.RoleMember member : roles) {
                        ret = StringUtils.containsIgnoreCase(role.getName(), roleNamePartial);
                        if (ret) {
                            break;
                        }
                    }
                }
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerRole(org.apache.ranger.plugin.model.RangerRole) Predicate(org.apache.commons.collections.Predicate)

Example 27 with RangerRole

use of org.apache.ranger.plugin.model.RangerRole in project ranger by apache.

the class RolePredicateUtil method addPredicateForRoleId.

private Predicate addPredicateForRoleId(final String roleId, List<Predicate> predicates) {
    if (StringUtils.isEmpty(roleId)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerRole) {
                RangerRole role = (RangerRole) object;
                ret = StringUtils.equals(roleId, role.getId().toString());
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerRole(org.apache.ranger.plugin.model.RangerRole) Predicate(org.apache.commons.collections.Predicate)

Example 28 with RangerRole

use of org.apache.ranger.plugin.model.RangerRole in project ranger by apache.

the class RolePredicateUtil method addPredicateForPartialUserName.

private Predicate addPredicateForPartialUserName(final String userNamePartial, List<Predicate> predicates) {
    if (StringUtils.isEmpty(userNamePartial)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerRole) {
                RangerRole role = (RangerRole) object;
                List<RangerRole.RoleMember> users = role.getUsers();
                for (RangerRole.RoleMember member : users) {
                    ret = StringUtils.containsIgnoreCase(member.getName(), userNamePartial);
                    if (ret) {
                        break;
                    }
                }
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerRole(org.apache.ranger.plugin.model.RangerRole) Predicate(org.apache.commons.collections.Predicate)

Example 29 with RangerRole

use of org.apache.ranger.plugin.model.RangerRole in project ranger by apache.

the class RolePredicateUtil method addPredicateForGroupName.

private Predicate addPredicateForGroupName(final String groupName, List<Predicate> predicates) {
    if (StringUtils.isEmpty(groupName)) {
        return null;
    }
    Predicate ret = new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            if (object == null) {
                return false;
            }
            boolean ret = false;
            if (object instanceof RangerRole) {
                RangerRole role = (RangerRole) object;
                List<RangerRole.RoleMember> groups = role.getGroups();
                for (RangerRole.RoleMember member : groups) {
                    ret = StringUtils.equals(member.getName(), groupName);
                    if (ret) {
                        break;
                    }
                }
            }
            return ret;
        }
    };
    if (predicates != null) {
        predicates.add(ret);
    }
    return ret;
}
Also used : RangerRole(org.apache.ranger.plugin.model.RangerRole) Predicate(org.apache.commons.collections.Predicate)

Example 30 with RangerRole

use of org.apache.ranger.plugin.model.RangerRole in project ranger by apache.

the class RangerRolesUtil method addContainedRoles.

private void addContainedRoles(Set<RangerRole> allRoles, Set<RangerRole> roles, RangerRole role) {
    List<RangerRole.RoleMember> roleMembers = role.getRoles();
    for (RangerRole.RoleMember roleMember : roleMembers) {
        RangerRole containedRole = getContainedRole(roles, roleMember.getName());
        if (containedRole != null && !allRoles.contains(containedRole)) {
            allRoles.add(containedRole);
            addContainedRoles(allRoles, roles, containedRole);
        }
    }
}
Also used : RangerRole(org.apache.ranger.plugin.model.RangerRole)

Aggregations

RangerRole (org.apache.ranger.plugin.model.RangerRole)37 Predicate (org.apache.commons.collections.Predicate)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)5 IOException (java.io.IOException)4 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)4 HiveAccessControlException (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException)4 HiveAuthzPluginException (org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException)4 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)4 RangerAccessResult (org.apache.ranger.plugin.policyengine.RangerAccessResult)4 RangerRoles (org.apache.ranger.plugin.util.RangerRoles)4 UserSessionBase (org.apache.ranger.common.UserSessionBase)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 PrivilegedAction (java.security.PrivilegedAction)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2