Skip to content

Commit

Permalink
geoserver#226 Add subfield field
Browse files Browse the repository at this point in the history
  • Loading branch information
etj committed Oct 7, 2022
1 parent 4bbd8db commit 26347e5
Show file tree
Hide file tree
Showing 17 changed files with 330 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ src/gui/web/war/geofence/
**/gwt-unitCache/
**/geofence_db/
**/nbproject/

**/nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public class Rule implements Identifiable, Serializable, Prioritizable, IPRangeP
@Index(name = "idx_rule_request")
private String request;

@Column
private String subfield;

@Column
@Index(name = "idx_rule_workspace")
private String workspace;
Expand All @@ -130,19 +133,29 @@ public Rule() {
}

public Rule(long priority, String username, String rolename, GSInstance instance, IPAddressRange addressRange,
String service, String request, String workspace, String layer, GrantType access) {
String service, String request, String subfield, String workspace, String layer, GrantType access) {
this.priority = priority;
this.username = username;
this.rolename = rolename;
this.instance = instance;
this.addressRange = addressRange;
this.service = service;
this.request = request;
this.subfield = subfield;
this.workspace = workspace;
this.layer = layer;
this.access = access;
}

/**
* @deprecated need new subfield argument
*/
@Deprecated
public Rule(long priority, String username, String rolename, GSInstance instance, IPAddressRange addressRange,
String service, String request, String workspace, String layer, GrantType access) {
this(priority, username, rolename, instance, addressRange, service, request, null, workspace, layer, access);
}

public Long getId() {
return id;
}
Expand Down Expand Up @@ -217,6 +230,14 @@ public void setRequest(String request) {
this.request = request;
}

public String getSubfield() {
return subfield;
}

public void setSubfield(String subfield) {
this.subfield = subfield;
}

public String getWorkspace() {
return workspace;
}
Expand Down Expand Up @@ -285,6 +306,9 @@ public String toString() {
if (request != null) {
sb.append(" req:").append(request);
}
if (subfield != null) {
sb.append(" sub:").append(subfield);
}

if (workspace != null) {
sb.append(" ws:").append(workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected Search getDupSearch(Rule rule) {
addSearchField(search, "instance", rule.getInstance());
addSearchField(search, "service", rule.getService());
addSearchField(search, "request", rule.getRequest());
addSearchField(search, "subfield", rule.getSubfield());
addSearchField(search, "workspace", rule.getWorkspace());
addSearchField(search, "layer", rule.getLayer());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@
public interface RuleReaderService
{

/**
* Return info on resource accessibility.
* <P>
* All parameters reference instances by name.<BR>
* <LI>If a given parameter is "<TT>*</TT>", it will match <B>any</B> value in the related {@link Rule} field.</LI>
* <LI>If a given parameter is <TT>null</TT>, it will match only null (default) values in the related {@link Rule} field.</LI>
* </UL>
* In order to have a better control on the query, please use {@link #getAccessInfo(RuleFilter filter) }.
*
* @deprecated Use {@link #getAccessInfo(RuleFilter filter) }
*/
AccessInfo getAccessInfo(String userName,
String profileName,
String instanceName,
String sourceAddress,
String service,
String request,
String workspace,
String layer);
// /**
// * Return info on resource accessibility.
// * <P>
// * All parameters reference instances by name.<BR>
// * <LI>If a given parameter is "<TT>*</TT>", it will match <B>any</B> value in the related {@link Rule} field.</LI>
// * <LI>If a given parameter is <TT>null</TT>, it will match only null (default) values in the related {@link Rule} field.</LI>
// * </UL>
// * In order to have a better control on the query, please use {@link #getAccessInfo(RuleFilter filter) }.
// *
// * @deprecated Use {@link #getAccessInfo(RuleFilter filter) }
// */
// AccessInfo getAccessInfo(String userName,
// String profileName,
// String instanceName,
// String sourceAddress,
// String service,
// String request,
// String workspace,
// String layer);

/**
* Return info on resource accessibility.
Expand All @@ -53,31 +53,31 @@ AccessInfo getAccessInfo(String userName,
*/
AccessInfo getAdminAuthorization(RuleFilter filter);

/**
* Return the unprocessed {@link Rule} list matching a given filter, sorted
* by priority.
* <P>
* Use {@link getAccessInfo(String,String,String,String,String,String,String) getAccessInfo}
* if you need the resulting coalesced access info.
* <P>
* Differently from {@link RuleAdminService#getList(String,String,String,String,String,String,String,Integer,Integer) RuleAdminService.getList(...)},
* when a param is set, it will match
* all the rules with the corresponding matching field,
* plus all the rules having that field set to <T>null</TT>.
* <BR>Null params will only match null values.
* <BR>The "*" string will always match.
*
* @deprecated Use {@link #getMatchingRules(RuleFilter filter) }
*/

List<ShortRule> getMatchingRules(String userName,
String profileName,
String instanceName,
String sourceAddress,
String service,
String request,
String workspace,
String layer);
// /**
// * Return the unprocessed {@link Rule} list matching a given filter, sorted
// * by priority.
// * <P>
// * Use {@link getAccessInfo(String,String,String,String,String,String,String) getAccessInfo}
// * if you need the resulting coalesced access info.
// * <P>
// * Differently from {@link RuleAdminService#getList(String,String,String,String,String,String,String,Integer,Integer) RuleAdminService.getList(...)},
// * when a param is set, it will match
// * all the rules with the corresponding matching field,
// * plus all the rules having that field set to <T>null</TT>.
// * <BR>Null params will only match null values.
// * <BR>The "*" string will always match.
// *
// * @deprecated Use {@link #getMatchingRules(RuleFilter filter) }
// */
//
// List<ShortRule> getMatchingRules(String userName,
// String profileName,
// String instanceName,
// String sourceAddress,
// String service,
// String request,
// String workspace,
// String layer);

/**
* Return the unprocessed {@link Rule} list matching a given filter, sorted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*
* @author ETj (etj at geo-solutions.it)
*/
public class AccessInfo implements Serializable {
public class AccessInfo implements Serializable, Cloneable {

private static final long serialVersionUID = -9108763358187355342L;
private static final long serialVersionUID = -9108763358187355343L;

/**
* Default "allow everything" AccessInfo
Expand Down Expand Up @@ -174,4 +174,14 @@ public String toString() {

return sb.toString();
}

@Override
public AccessInfo clone() {
try {
return (AccessInfo) super.clone();
} catch (CloneNotSupportedException ex) {
throw new IllegalStateException("Unexpected exception", ex);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public class RuleFilter implements Serializable, Cloneable {

private static final long serialVersionUID = 5629211135629700043L;
private static final long serialVersionUID = 5629211135629700044L;

public enum FilterType {

Expand All @@ -41,7 +41,18 @@ public enum FilterType {

public enum SpecialFilterType {

/**
* ANY will not add any costraints on the field.
* This means that all values on that field will be allowed.
* Pay attention when using this type, since it may allow rules you do not intended to retrieve.
* You may mean to use the ANY value.
*/
ANY(FilterType.ANY),
/**
* DEFAULT will create an IS NULL filter on the field.
* This means only the default rules for a given field will be returned.
* This is probably the value you want to use.
*/
DEFAULT(FilterType.DEFAULT);
private FilterType relatedType;

Expand All @@ -59,6 +70,7 @@ public FilterType getRelatedType() {
private final TextFilter sourceAddress;
private final TextFilter service;
private final TextFilter request;
private final TextFilter subfield;
private final TextFilter workspace;
private final TextFilter layer;

Expand All @@ -82,6 +94,7 @@ public RuleFilter(SpecialFilterType type) {
sourceAddress = new TextFilter(ft);
service = new TextFilter(ft, true);
request = new TextFilter(ft, true);
subfield = new TextFilter(ft, true);
workspace = new TextFilter(ft);
layer = new TextFilter(ft);
}
Expand All @@ -100,6 +113,8 @@ public RuleFilter(SpecialFilterType type, boolean includeDefault) {
service.setIncludeDefault(includeDefault);
request = new TextFilter(ft, true);
request.setIncludeDefault(includeDefault);
subfield = new TextFilter(ft, true);
subfield.setIncludeDefault(includeDefault);
workspace = new TextFilter(ft);
workspace.setIncludeDefault(includeDefault);
layer = new TextFilter(ft);
Expand All @@ -115,7 +130,7 @@ public RuleFilter(SpecialFilterType type, boolean includeDefault) {
*/
public RuleFilter(String userName, String groupName, String instanceName,
String sourceAddress,
String service, String request,
String service, String request, String subfield,
String workspace, String layer) {
this(SpecialFilterType.DEFAULT);

Expand All @@ -127,6 +142,7 @@ public RuleFilter(String userName, String groupName, String instanceName,

this.service.setHeuristically(service);
this.request.setHeuristically(request);
this.subfield.setHeuristically(subfield);
this.workspace.setHeuristically(workspace);
this.layer.setHeuristically(layer);
}
Expand All @@ -140,6 +156,7 @@ public RuleFilter(RuleFilter source) {
sourceAddress = source.sourceAddress.clone();
service = source.service.clone();
request = source.request.clone();
subfield = source.subfield.clone();
workspace = source.workspace.clone();
layer = source.layer.clone();
} catch (CloneNotSupportedException ex) {
Expand Down Expand Up @@ -218,6 +235,16 @@ public RuleFilter setRequest(SpecialFilterType type) {
return this;
}

public RuleFilter setSubfield(String name) {
subfield.setText(name);
return this;
}

public RuleFilter setSubfield(SpecialFilterType type) {
subfield.setType(type);
return this;
}

public RuleFilter setWorkspace(String name) {
workspace.setText(name);
return this;
Expand Down Expand Up @@ -258,6 +285,10 @@ public TextFilter getRequest() {
return request;
}

public TextFilter getSubfield() {
return subfield;
}

public TextFilter getService() {
return service;
}
Expand Down Expand Up @@ -316,6 +347,9 @@ public boolean equals(Object obj) {
if (this.request != other.request && (this.request == null || !this.request.equals(other.request))) {
return false;
}
if (this.subfield != other.subfield && (this.subfield == null || !this.subfield.equals(other.subfield))) {
return false;
}
if (this.workspace != other.workspace && (this.workspace == null || !this.workspace.equals(other.workspace))) {
return false;
}
Expand All @@ -335,6 +369,7 @@ public int hashCode() {
hash = 37 * hash + (this.sourceAddress != null ? this.sourceAddress.hashCode() : 0);
hash = 37 * hash + (this.service != null ? this.service.hashCode() : 0);
hash = 37 * hash + (this.request != null ? this.request.hashCode() : 0);
hash = 37 * hash + (this.subfield != null ? this.subfield.hashCode() : 0);
hash = 37 * hash + (this.workspace != null ? this.workspace.hashCode() : 0);
hash = 37 * hash + (this.layer != null ? this.layer.hashCode() : 0);
//NOTE: ipaddress not in hashcode bc it is not used for caching
Expand All @@ -351,6 +386,7 @@ public String toString() {
sb.append(" ip:").append(sourceAddress);
sb.append(" serv:").append(service);
sb.append(" req:").append(request);
if(subfield != null) sb.append(" sub:").append(subfield);
sb.append(" ws:").append(workspace);
sb.append(" layer:").append(layer);
sb.append(']');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class ShortRule implements Serializable
{

private static final long serialVersionUID = -9127101015688510863L;
private static final long serialVersionUID = -9127101015688510864L;

private Long id;
private Long priority;
Expand All @@ -34,6 +34,7 @@ public class ShortRule implements Serializable

private String service;
private String request;
private String subfield;
private String workspace;
private String layer;

Expand Down Expand Up @@ -62,6 +63,7 @@ public ShortRule(Rule rule)
setAddressRange(rule.getAddressRange().toString());
}
setRequest(rule.getRequest());
setSubfield(rule.getSubfield());
setWorkspace(rule.getWorkspace());
setLayer(rule.getLayer());
setAccess(rule.getAccess());
Expand Down Expand Up @@ -156,6 +158,14 @@ public void setRequest(String request)
this.request = request;
}

public String getSubfield() {
return subfield;
}

public void setSubfield(String subfield) {
this.subfield = subfield;
}

public String getService()
{
return service;
Expand Down Expand Up @@ -225,6 +235,10 @@ public String toString()
{
sb.append(" req:").append(request);
}
if (subfield != null)
{
sb.append(" sub:").append(subfield);
}

if (workspace != null)
{
Expand Down
Loading

0 comments on commit 26347e5

Please sign in to comment.