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 Sep 29, 2022
1 parent 4bbd8db commit 545d03b
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 174 deletions.
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 @@ -59,6 +59,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 +83,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 +102,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 +119,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 +131,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 +145,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 +224,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 +274,10 @@ public TextFilter getRequest() {
return request;
}

public TextFilter getSubfield() {
return subfield;
}

public TextFilter getService() {
return service;
}
Expand Down Expand Up @@ -316,6 +336,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 +358,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 +375,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 @@ -58,19 +58,19 @@ public class RuleReaderServiceImpl implements RuleReaderService {
private UserResolver userResolver;
private AuthorizationService authorizationService;

/**
* @deprecated
*/
@Override
@Deprecated
public List<ShortRule> getMatchingRules(
String userName, String profileName, String instanceName,
String sourceAddress,
String service, String request,
String workspace, String layer) {

return getMatchingRules(new RuleFilter(userName, profileName, instanceName, sourceAddress, service, request, workspace, layer));
}
// /**
// * @deprecated
// */
// @Override
// @Deprecated
// public List<ShortRule> getMatchingRules(
// String userName, String profileName, String instanceName,
// String sourceAddress,
// String service, String request, String subfield,
// String workspace, String layer) {
//
// return getMatchingRules(new RuleFilter(userName, profileName, instanceName, sourceAddress, service, request, subfield, workspace, layer));
// }

/**
* <B>TODO: REFACTOR</B>
Expand Down Expand Up @@ -100,17 +100,17 @@ public List<ShortRule> getMatchingRules(RuleFilter filter) {
}


/**
* @deprecated
*/
@Override
@Deprecated
public AccessInfo getAccessInfo(String userName, String roleName, String instanceName,
String sourceAddress,
String service, String request,
String workspace, String layer) {
return getAccessInfo(new RuleFilter(userName, roleName, instanceName, sourceAddress, service, request, workspace, layer));
}
// /**
// * @deprecated
// */
// @Override
// @Deprecated
// public AccessInfo getAccessInfo(String userName, String roleName, String instanceName,
// String sourceAddress,
// String service, String request, String subfield,
// String workspace, String layer) {
// return getAccessInfo(new RuleFilter(userName, roleName, instanceName, sourceAddress, service, request, subfield, workspace, layer));
// }

@Override
public AccessInfo getAccessInfo(RuleFilter filter)
Expand Down
Loading

0 comments on commit 545d03b

Please sign in to comment.