use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem in project ranger by apache.
the class PatchForUpdatingPolicyJson_J10019 method buildLists.
private void buildLists(List<? extends RangerPolicyItem> policyItems, Set<String> accesses, Set<String> conditions, Set<String> users, Set<String> groups) {
for (RangerPolicyItem item : policyItems) {
for (RangerPolicyItemAccess policyAccess : item.getAccesses()) {
accesses.add(policyAccess.getType());
}
for (RangerPolicyItemCondition policyCondition : item.getConditions()) {
conditions.add(policyCondition.getType());
}
users.addAll(item.getUsers());
groups.addAll(item.getGroups());
}
}
use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem in project ranger by apache.
the class RangerBaseService method addCustomRangerDefaultPolicies.
private void addCustomRangerDefaultPolicies(List<RangerPolicy> ret, Map<String, RangerPolicy.RangerPolicyResource> policyResourceMap, String policyPropertyPrefix) throws Exception {
String policyName = configs.get(policyPropertyPrefix + PROP_DEFAULT_POLICY_NAME_SUFFIX);
String description = configs.get(policyPropertyPrefix + "description");
if (StringUtils.isEmpty(description)) {
description = "Policy for " + policyName;
}
RangerPolicy policy = new RangerPolicy();
policy.setName(policyName);
policy.setIsEnabled(true);
policy.setVersion(1L);
policy.setIsAuditEnabled(true);
policy.setService(serviceName);
policy.setDescription(description);
policy.setName(policyName);
policy.setResources(policyResourceMap);
for (int i = 1; ; i++) {
String policyItemPropertyPrefix = policyPropertyPrefix + "policyItem." + i + ".";
String policyItemUsers = configs.get(policyItemPropertyPrefix + "users");
String policyItemGroups = configs.get(policyItemPropertyPrefix + "groups");
String policyItemRoles = configs.get(policyItemPropertyPrefix + "roles");
String policyItemAccessTypes = configs.get(policyItemPropertyPrefix + "accessTypes");
String isDelegateAdmin = configs.get(policyItemPropertyPrefix + "isDelegateAdmin");
if (StringUtils.isEmpty(policyItemAccessTypes) || (StringUtils.isEmpty(policyItemUsers) && StringUtils.isEmpty(policyItemGroups) && StringUtils.isEmpty(policyItemRoles))) {
break;
}
RangerPolicyItem policyItem = new RangerPolicyItem();
policyItem.setDelegateAdmin(Boolean.parseBoolean(isDelegateAdmin));
if (StringUtils.isNotBlank(policyItemUsers)) {
policyItem.setUsers(Arrays.asList(policyItemUsers.split(",")));
}
if (StringUtils.isNotBlank(policyItemGroups)) {
policyItem.setGroups(Arrays.asList(policyItemGroups.split(",")));
}
if (StringUtils.isNotBlank(policyItemRoles)) {
policyItem.setRoles(Arrays.asList(policyItemRoles.split(",")));
}
if (StringUtils.isNotBlank(policyItemAccessTypes)) {
for (String accessType : Arrays.asList(policyItemAccessTypes.split(","))) {
RangerPolicyItemAccess polAccess = new RangerPolicyItemAccess(accessType, true);
policyItem.getAccesses().add(polAccess);
}
}
policy.getPolicyItems().add(policyItem);
}
LOG.info(getServiceName() + ": adding default policy: name=" + policy.getName());
ret.add(policy);
}
use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem in project ranger by apache.
the class AbstractPredicateUtil method addPredicateForUserName.
private Predicate addPredicateForUserName(final String userName, List<Predicate> predicates) {
if (StringUtils.isEmpty(userName)) {
return null;
}
Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}
boolean ret = false;
if (object instanceof RangerPolicy) {
RangerPolicy policy = (RangerPolicy) object;
List<?>[] policyItemsList = new List<?>[] { policy.getPolicyItems(), policy.getDenyPolicyItems(), policy.getAllowExceptions(), policy.getDenyExceptions(), policy.getDataMaskPolicyItems(), policy.getRowFilterPolicyItems() };
for (List<?> policyItemsObj : policyItemsList) {
@SuppressWarnings("unchecked") List<RangerPolicyItem> policyItems = (List<RangerPolicyItem>) policyItemsObj;
for (RangerPolicyItem policyItem : policyItems) {
if (!policyItem.getUsers().isEmpty()) {
for (String user : policyItem.getUsers()) {
if (StringUtils.containsIgnoreCase(user, userName)) {
ret = true;
break;
}
}
}
}
if (ret) {
break;
}
}
} else {
ret = true;
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem in project ranger by apache.
the class RangerServiceOzone method getDefaultRangerPolicies.
@Override
public List<RangerPolicy> getDefaultRangerPolicies() throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> RangerServiceOzone.getDefaultRangerPolicies() ");
}
List<RangerPolicy> ret = super.getDefaultRangerPolicies();
for (RangerPolicy defaultPolicy : ret) {
if (defaultPolicy.getName().startsWith("all")) {
RangerPolicyItem policyItemOwner = new RangerPolicyItem();
policyItemOwner.setUsers(Collections.singletonList(RangerPolicyEngine.RESOURCE_OWNER));
policyItemOwner.setAccesses(Collections.singletonList(new RangerPolicyItemAccess(ACCESS_TYPE_ALL)));
policyItemOwner.setDelegateAdmin(true);
defaultPolicy.getPolicyItems().add(policyItemOwner);
if (StringUtils.isNotBlank(lookUpUser)) {
RangerPolicyItem policyItemForLookupUser = new RangerPolicyItem();
List<RangerPolicy.RangerPolicyItemAccess> accessListForLookupUser = new ArrayList<RangerPolicy.RangerPolicyItemAccess>();
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_READ));
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_WRITE));
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_CREATE));
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_LIST));
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_DELETE));
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_READ_ACL));
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_WRITE_ACL));
accessListForLookupUser.add(new RangerPolicyItemAccess(ACCESS_TYPE_ALL));
policyItemForLookupUser.setUsers(Collections.singletonList(lookUpUser));
policyItemForLookupUser.setAccesses(accessListForLookupUser);
policyItemForLookupUser.setDelegateAdmin(false);
defaultPolicy.getPolicyItems().add(policyItemForLookupUser);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== RangerServiceOzone.getDefaultRangerPolicies() : " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem in project ranger by apache.
the class ValidationTestUtils method createPolicyItems.
List<RangerPolicyItem> createPolicyItems(Object[] data) {
List<RangerPolicyItem> policyItems = new ArrayList<>();
for (Object object : data) {
@SuppressWarnings("unchecked") Map<String, Object[]> map = (Map<String, Object[]>) object;
RangerPolicyItem policyItem = mock(RangerPolicyItem.class);
List<String> usersList = null;
if (map.containsKey("users")) {
usersList = Arrays.asList((String[]) map.get("users"));
}
when(policyItem.getUsers()).thenReturn(usersList);
List<String> groupsList = null;
if (map.containsKey("groups")) {
groupsList = Arrays.asList((String[]) map.get("groups"));
}
when(policyItem.getGroups()).thenReturn(groupsList);
String[] accesses = (String[]) map.get("accesses");
Boolean[] isAllowedFlags = (Boolean[]) map.get("isAllowed");
List<RangerPolicyItemAccess> accessesList = null;
if (accesses != null && isAllowedFlags != null) {
accessesList = new ArrayList<>();
for (int i = 0; i < accesses.length; i++) {
String access = accesses[i];
Boolean isAllowed = isAllowedFlags[i];
RangerPolicyItemAccess itemAccess = mock(RangerPolicyItemAccess.class);
when(itemAccess.getType()).thenReturn(access);
when(itemAccess.getIsAllowed()).thenReturn(isAllowed);
accessesList.add(itemAccess);
}
}
when(policyItem.getAccesses()).thenReturn(accessesList);
policyItems.add(policyItem);
}
return policyItems;
}
Aggregations