Skip to content

Commit

Permalink
Per-entity CRUD filters for update/delete operations #502
Browse files Browse the repository at this point in the history
.. renaming create/update/delete filters to "authorizers".
The new name is more appropriate as they fail entire requests,
not just exclude disallowed operations

.. moving from "filter" to "access" package
  • Loading branch information
andrus committed Dec 5, 2021
1 parent 49c6004 commit 8a6da3f
Show file tree
Hide file tree
Showing 37 changed files with 212 additions and 211 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.agrest.cayenne.compiler;

import io.agrest.compiler.AnnotationsAgEntityBuilder;
import io.agrest.filter.CreateFilter;
import io.agrest.filter.DeleteFilter;
import io.agrest.filter.ReadFilter;
import io.agrest.filter.UpdateFilter;
import io.agrest.access.CreateAuthorizer;
import io.agrest.access.DeleteAuthorizer;
import io.agrest.access.ReadFilter;
import io.agrest.access.UpdateAuthorizer;
import io.agrest.meta.AgAttribute;
import io.agrest.meta.AgDataMap;
import io.agrest.meta.AgEntity;
Expand Down Expand Up @@ -207,9 +207,9 @@ protected AgEntity<T> buildEntity() {
relationships,
rootDataResolver != null ? rootDataResolver : ThrowingRootDataResolver.getInstance(),
ReadFilter.allowsAllFilter(),
CreateFilter.allowsAllFilter(),
UpdateFilter.allowsAllFilter(),
DeleteFilter.allowsAllFilter());
CreateAuthorizer.allowsAllFilter(),
UpdateAuthorizer.allowsAllFilter(),
DeleteAuthorizer.allowsAllFilter());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.agrest.Ag;
import io.agrest.DataResponse;
import io.agrest.filter.PropertyFilteringRulesBuilder;
import io.agrest.access.PropertyFilteringRulesBuilder;
import io.agrest.cayenne.cayenne.main.E2;
import io.agrest.cayenne.cayenne.main.E3;
import io.agrest.cayenne.cayenne.main.E4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.agrest.cayenne.cayenne.main.E4;
import io.agrest.cayenne.unit.AgCayenneTester;
import io.agrest.cayenne.unit.DbTest;
import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;
import io.agrest.meta.AgEntity;
import io.bootique.junit5.BQTestTool;
import org.apache.cayenne.Cayenne;
Expand Down
2 changes: 1 addition & 1 deletion agrest-engine/src/main/java/io/agrest/ResourceEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.agrest.base.protocol.Exp;
import io.agrest.base.protocol.Sort;
import io.agrest.encoder.EntityEncoderFilter;
import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;
import io.agrest.meta.AgAttribute;
import io.agrest.meta.AgEntity;

Expand Down
4 changes: 2 additions & 2 deletions agrest-engine/src/main/java/io/agrest/SelectBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import io.agrest.constraints.Constraint;
import io.agrest.encoder.Encoder;
import io.agrest.encoder.EntityEncoderFilter;
import io.agrest.filter.ReadFilter;
import io.agrest.filter.PropertyFilter;
import io.agrest.access.ReadFilter;
import io.agrest.access.PropertyFilter;
import io.agrest.meta.AgEntity;
import io.agrest.meta.AgEntityOverlay;
import io.agrest.processor.Processor;
Expand Down
2 changes: 1 addition & 1 deletion agrest-engine/src/main/java/io/agrest/UpdateBuilder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.agrest;

import io.agrest.constraints.Constraint;
import io.agrest.filter.PropertyFilter;
import io.agrest.access.PropertyFilter;
import io.agrest.meta.AgEntity;
import io.agrest.meta.AgEntityOverlay;
import io.agrest.processor.Processor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.agrest.access;

import io.agrest.EntityUpdate;

/**
* @since 4.8
*/
final class AllowAllCreateAuthorizer<T> implements CreateAuthorizer<T> {

static final AllowAllCreateAuthorizer instance = new AllowAllCreateAuthorizer();

private AllowAllCreateAuthorizer() {
}

@Override
public boolean isAllowed(EntityUpdate<T> update) {
return true;
}

@Override
public boolean allowsAll() {
return true;
}

@Override
public CreateAuthorizer<T> andThen(CreateAuthorizer<T> another) {
return another;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.agrest.access;

/**
* @since 4.8
*/
final class AllowAllDeleteAuthorizer<T> implements DeleteAuthorizer<T> {

static final AllowAllDeleteAuthorizer instance = new AllowAllDeleteAuthorizer();

private AllowAllDeleteAuthorizer() {
}

@Override
public boolean isAllowed(T object) {
return true;
}

@Override
public boolean allowsAll() {
return true;
}

@Override
public DeleteAuthorizer<T> andThen(DeleteAuthorizer<T> another) {
return another;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.agrest.filter;
package io.agrest.access;

/**
* @since 4.8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.agrest.access;

import io.agrest.EntityUpdate;

/**
* @since 4.8
*/
final class AllowAllUpdateAuthorizer<T> implements UpdateAuthorizer<T> {

static final AllowAllUpdateAuthorizer instance = new AllowAllUpdateAuthorizer();

private AllowAllUpdateAuthorizer() {
}

@Override
public boolean isAllowed(T object, EntityUpdate<T> update) {
return true;
}

@Override
public boolean allowsAll() {
return true;
}

@Override
public UpdateAuthorizer<T> andThen(UpdateAuthorizer<T> another) {
return another;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.agrest.filter;
package io.agrest.access;

import io.agrest.EntityUpdate;

/**
* Per-entity filter used to implement object CREATE access policies.
* Per-entity predicate-like object used to implement object CREATE access policies.
*
* @since 4.8
*/
public interface CreateFilter<T> {
public interface CreateAuthorizer<T> {

static <T> CreateFilter<T> allowsAllFilter() {
return AllowAllCreateFilter.instance;
static <T> CreateAuthorizer<T> allowsAllFilter() {
return AllowAllCreateAuthorizer.instance;
}

boolean isAllowed(EntityUpdate<T> update);
Expand All @@ -22,7 +22,7 @@ default boolean allowsAll() {
return false;
}

default CreateFilter<T> andThen(CreateFilter<T> another) {
default CreateAuthorizer<T> andThen(CreateAuthorizer<T> another) {
if (another.allowsAll()) {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.agrest.filter;
package io.agrest.access;

/**
* Per-entity filter used to implement object DELETE access policies.
* Per-entity predicate-like object used to implement object DELETE access policies.
*
* @since 4.8
*/
public interface DeleteFilter<T> {
public interface DeleteAuthorizer<T> {

static <T> DeleteFilter<T> allowsAllFilter() {
return AllowAllDeleteFilter.instance;
static <T> DeleteAuthorizer<T> allowsAllFilter() {
return AllowAllDeleteAuthorizer.instance;
}

boolean isAllowed(T object);
Expand All @@ -20,7 +20,7 @@ default boolean allowsAll() {
return false;
}

default DeleteFilter<T> andThen(DeleteFilter<T> another) {
default DeleteAuthorizer<T> andThen(DeleteAuthorizer<T> another) {
if (another.allowsAll()) {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.agrest.filter;
package io.agrest.access;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.agrest.filter;
package io.agrest.access;

import io.agrest.PathConstants;
import io.agrest.meta.AgEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.agrest.filter;
package io.agrest.access;

/**
* Per-entity filter used to implement object READ access policies.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.agrest.filter;
package io.agrest.access;

import io.agrest.EntityUpdate;

/**
* Per-entity filter used to implement object UPDATE access policies.
* Per-entity predicate-like object used to implement object UPDATE access policies.
*
* @since 4.8
*/
public interface UpdateFilter<T> {
public interface UpdateAuthorizer<T> {

static <T> UpdateFilter<T> allowsAllFilter() {
return AllowAllUpdateFilter.instance;
static <T> UpdateAuthorizer<T> allowsAllFilter() {
return AllowAllUpdateAuthorizer.instance;
}

boolean isAllowed(T object, EntityUpdate<T> update);
Expand All @@ -22,7 +22,7 @@ default boolean allowsAll() {
return false;
}

default UpdateFilter<T> andThen(UpdateFilter<T> another) {
default UpdateAuthorizer<T> andThen(UpdateAuthorizer<T> another) {
if (another.allowsAll()) {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import io.agrest.annotation.AgRelationship;
import io.agrest.base.reflect.BeanAnalyzer;
import io.agrest.base.reflect.PropertyGetter;
import io.agrest.filter.CreateFilter;
import io.agrest.filter.DeleteFilter;
import io.agrest.filter.ReadFilter;
import io.agrest.filter.UpdateFilter;
import io.agrest.access.CreateAuthorizer;
import io.agrest.access.DeleteAuthorizer;
import io.agrest.access.ReadFilter;
import io.agrest.access.UpdateAuthorizer;
import io.agrest.meta.AgDataMap;
import io.agrest.meta.AgEntity;
import io.agrest.meta.AgEntityOverlay;
Expand Down Expand Up @@ -222,9 +222,9 @@ protected AgEntity<T> buildEntity() {
relationships,
rootDataResolver != null ? rootDataResolver : ThrowingRootDataResolver.getInstance(),
ReadFilter.allowsAllFilter(),
CreateFilter.allowsAllFilter(),
UpdateFilter.allowsAllFilter(),
DeleteFilter.allowsAllFilter());
CreateAuthorizer.allowsAllFilter(),
UpdateAuthorizer.allowsAllFilter(),
DeleteAuthorizer.allowsAllFilter());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.agrest.constraints;

import io.agrest.base.protocol.Exp;
import io.agrest.filter.PropertyFilter;
import io.agrest.access.PropertyFilter;
import io.agrest.meta.AgAttribute;
import io.agrest.meta.AgEntity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.agrest.constraints;

import io.agrest.filter.PropertyFilter;
import io.agrest.access.PropertyFilter;
import io.agrest.meta.AgEntity;

import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.agrest.constraints;

import io.agrest.PathConstants;
import io.agrest.filter.PropertyFilter;
import io.agrest.access.PropertyFilter;
import io.agrest.base.protocol.Exp;
import io.agrest.meta.AgEntity;
import io.agrest.meta.AgRelationship;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.core.JsonGenerator;
import io.agrest.ResourceEntity;
import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.agrest.encoder;

import io.agrest.ResourceEntity;
import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;

/**
* @since 3.4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.agrest.encoder;

import com.fasterxml.jackson.core.JsonGenerator;
import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.agrest.encoder;

import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;

/**
* @param <T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.core.JsonGenerator;
import io.agrest.ResourceEntity;
import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.agrest.encoder;

import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.agrest.encoder;

import com.fasterxml.jackson.core.JsonGenerator;
import io.agrest.filter.ReadFilter;
import io.agrest.access.ReadFilter;

import java.io.IOException;
import java.util.List;
Expand Down
Loading

0 comments on commit 8a6da3f

Please sign in to comment.