Skip to content

Commit

Permalink
RANGER-4398: security-zone API enhancements to support incremental up…
Browse files Browse the repository at this point in the history
…dates and resource pagination
  • Loading branch information
mneethiraj committed Sep 13, 2023
1 parent 4d9648b commit f3e8e0a
Show file tree
Hide file tree
Showing 12 changed files with 1,640 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.ranger.plugin.model;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Objects;

@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class RangerPrincipal implements java.io.Serializable {
private static final long serialVersionUID = 1L;

public enum PrincipalType { USER, GROUP, ROLE }

private PrincipalType type;
private String name;

public RangerPrincipal() {
this(null, null);
}

public RangerPrincipal(PrincipalType type, String name) {
setType(type);
setName(name);
}

public PrincipalType getType() {
return type;
}

public void setType(PrincipalType type) {
this.type = type;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public int hashCode() {
return Objects.hash(type, name);
}

@Override
public boolean equals(Object obj) {
final boolean ret;

if (this == obj) {
ret = true;
} else if (obj == null) {
ret = false;
} else if (getClass() != obj.getClass()) {
ret = false;
} else {
RangerPrincipal other = (RangerPrincipal) obj;

ret = Objects.equals(type, other.type) && Objects.equals(name, other.name);
}

return ret;
}

@Override
public String toString() {
return "{type=" + type + ", name=" + name + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import org.apache.ranger.plugin.model.RangerSecurityZoneV2.RangerSecurityZoneResourceBase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -147,14 +149,20 @@ public String toString() {
@JsonIgnoreProperties(ignoreUnknown=true)
public static class RangerSecurityZoneService implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private List<HashMap<String, List<String>>> resources;
private List<HashMap<String, List<String>>> resources;
private List<RangerSecurityZoneResourceBase> resourcesBaseInfo;

public RangerSecurityZoneService() {
this(null);
this(null, null);
}

public RangerSecurityZoneService(List<HashMap<String, List<String>>> resources) {
this(resources, null);
}

public RangerSecurityZoneService(List<HashMap<String, List<String>>> resources, List<RangerSecurityZoneResourceBase> resourcesBaseInfo) {
setResources(resources);
setResourcesBaseInfo(resourcesBaseInfo);
}

public List<HashMap<String, List<String>>> getResources() { return resources; }
Expand All @@ -163,22 +171,40 @@ public void setResources(List<HashMap<String, List<String>>> resources) {
this.resources = resources == null ? new ArrayList<>() : resources;
}

public List<RangerSecurityZoneResourceBase> getResourcesBaseInfo() { return resourcesBaseInfo; }

public void setResourcesBaseInfo(List<RangerSecurityZoneResourceBase> resourcesBaseInfo) {
this.resourcesBaseInfo = resourcesBaseInfo == null ? new ArrayList<>() : resourcesBaseInfo;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{resources={");
for (Map<String, List<String>> resource : resources) {
sb.append("[ ");
for (Map.Entry<String, List<String>> entry : resource.entrySet()) {
sb.append("{resource-def-name=").append(entry.getKey()).append(", values=").append(entry.getValue()).append("},");
sb.append("{resources=[");
if (resources != null) {
for (int i = 0; i < resources.size(); i++) {
HashMap<String, List<String>> resource = resources.get(i);
RangerSecurityZoneResourceBase baseInfo = (resourcesBaseInfo != null && resourcesBaseInfo.size() > i) ? resourcesBaseInfo.get(i) : null;

sb.append("{resource=");
if (resource != null) {
for (Map.Entry<String, List<String>> entry : resource.entrySet()) {
sb.append("{resource-def-name=").append(entry.getKey()).append(", values=").append(entry.getValue()).append("} ");
}
}
sb.append("} ");

sb.append("{baseInfo=");
if (baseInfo != null) {
baseInfo.toString(sb);
}
sb.append("} ");
}
sb.append(" ],");
}
sb.append("}}");
sb.append("]}");

return sb.toString();
}

}
}

Loading

0 comments on commit f3e8e0a

Please sign in to comment.