Skip to content

Commit 891ff0d

Browse files
wog48GitHub Enterprise
authored andcommitted
Feature/user group at entity v2 (#383)
* Make OData operations/entities user group restrictable * Enable copy with user group restriction * Enable copy of complex properties * Switch to lazy loading cache * Declared properties via cache * Finalize entity type * Description Property via cache and visibility @ EdmEntityType * Update dependency
1 parent 7841a02 commit 891ff0d

File tree

92 files changed

+3015
-1307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3015
-1307
lines changed

additionalWords.directory

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ x
7676
y
7777
esc
7878
Clob
79+
Restrictable

jpa/odata-jpa-annotation/src/main/java/com/sap/olingo/jpa/metadata/core/edm/annotation/EdmAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@
7272
* @return
7373
*/
7474
String entitySetPath() default "";
75+
76+
/**
77+
* Restrict the access to the action to the give user groups. Default is unrestricted access.
78+
*/
79+
EdmVisibleFor visibleFor() default @EdmVisibleFor;
7580
}

jpa/odata-jpa-annotation/src/main/java/com/sap/olingo/jpa/metadata/core/edm/annotation/EdmEntityType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@
3737
*/
3838
Class<? extends EdmQueryExtensionProvider> extensionProvider() default EdmQueryExtensionProvider.class;
3939

40+
EdmVisibleFor visibleFor() default @EdmVisibleFor;
4041
}

jpa/odata-jpa-annotation/src/main/java/com/sap/olingo/jpa/metadata/core/edm/annotation/EdmFunction.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
/**
1010
* Metadata of a function, see <a href =
1111
* "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398010">
12-
* edm:Function.</a><p>
12+
* edm:Function.</a>
13+
* <p>
1314
* @author Oliver Grande
1415
*
1516
*/
@@ -42,7 +43,8 @@
4243
EdmGeospatial srid() default @EdmGeospatial();
4344

4445
/**
45-
* Define the return type for the function import.<p>
46+
* Define the return type for the function import.
47+
* <p>
4648
*
4749
* @return Class of java parameter (row) type. This can be either a simple type like <code> Integer.class</code> or
4850
* the POJO defining an Entity. If the type is not set and the
@@ -68,13 +70,15 @@
6870
String functionName() default "";
6971

7072
/**
71-
* Indicates that the Function is bound. <p>
73+
* Indicates that the Function is bound.
74+
* <p>
7275
* If isBound is false a function is treated as <i>unbound</i>, so it can be accessed either via a Function Import or
7376
* be used in <i>filter</i> or <i>orderby</i> expression. Otherwise the function is treated as bound.
7477
* For details see:
7578
* <a href =
7679
* "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398013"
77-
* />OData Version 4.0 Part 3 - 12.2.2 Attribute IsBound</a> <p>
80+
* />OData Version 4.0 Part 3 - 12.2.2 Attribute IsBound</a>
81+
* <p>
7882
* <b>If the function is java based isBound is ignored and always set to false</b>
7983
* @return
8084
*/
@@ -84,8 +88,10 @@
8488
* Indicates that a Function Import shall be generated into the Container. For details see:
8589
* <a href =
8690
* "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398042"
87-
* />OData Version 4.0 Part 3 - 13.6 Element edm:FunctionImport</a> <p>
88-
* hasFunctionImport is handled as follows:<p>
91+
* />OData Version 4.0 Part 3 - 13.6 Element edm:FunctionImport</a>
92+
* <p>
93+
* hasFunctionImport is handled as follows:
94+
* <p>
8995
* <ol>
9096
* <li>For <b>bound</b> functions hasFunctionImport is always treated as <b>false</b></li>
9197
* <li>For <b>unbound</b> functions in case hasFunctionImport is <b>true</b> a function import is generated, which
@@ -107,7 +113,8 @@
107113
* <p>
108114
* <a href =
109115
* "http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406398015"
110-
* />OData Version 4.0 Part 3 - 13.6 Element edm:FunctionImport</a> <p>
116+
* />OData Version 4.0 Part 3 - 13.6 Element edm:FunctionImport</a>
117+
* <p>
111118
*
112119
*/
113120
String entitySetPath() default "";
@@ -118,4 +125,9 @@
118125
* @return return type of this function
119126
*/
120127
ReturnType returnType();
128+
129+
/**
130+
* Restrict the access to the function to the give user groups. Default is unrestricted access.
131+
*/
132+
EdmVisibleFor visibleFor() default @EdmVisibleFor;
121133
}

jpa/odata-jpa-annotation/src/main/java/com/sap/olingo/jpa/metadata/core/edm/annotation/EdmVisibleFor.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,28 @@
77
import java.lang.annotation.Target;
88

99
/**
10-
* The annotation can be used to assign attributes or properties to field or visibility groups. In case such a group is
11-
* provided during a GET request all properties that are assigned to that group and all properties that are assigned to
12-
* no group, or in other words that are not annotated, get selected. For properties that belong to another group are
13-
* requested, a null value is returned.
10+
* The annotation can be used to assign on the one hand attributes or properties and n the other hand entities to user
11+
* or visibility groups.
12+
* <ul>
13+
* <li>In case an entity is annotated, the entity and navigation targeting the entity are only visible and accessible if
14+
* one of the given groups are available.</li>
15+
* <li>In case an attribute is annotated and such a group is provided during a GET request all properties that are
16+
* assigned to that group and all properties that are assigned to no group, or in other words that are not annotated,
17+
* get selected. For properties that belong to another group are requested, a null value is returned.
1418
* <p>
1519
*
16-
* <b>Note:</b> Keys, mandatory fields as well as association or navigation properties can not be annotated
17-
*
20+
* <b>Note:</b> Keys, mandatory fields as well as association or navigation properties can not be annotated</li>
21+
* </ul>
1822
* @author Oliver Grande
1923
*
2024
*/
2125
@Retention(RUNTIME)
22-
@Target(FIELD)
26+
@Target({ FIELD })
2327
public @interface EdmVisibleFor {
2428
/**
25-
* List of field groups an attribute or property belongs to.
29+
* List of user groups an attribute or property or entity belongs to.
2630
* @return
2731
*/
28-
String[] value();
32+
String[] value() default {};
2933

3034
}

jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/api/JPAEdmProvider.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@
3535
import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAEdmNameBuilder;
3636
import com.sap.olingo.jpa.metadata.core.edm.mapper.api.JPAServiceDocument;
3737
import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAException;
38+
import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException;
3839
import com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPADefaultEdmNameBuilder;
3940
import com.sap.olingo.jpa.metadata.core.edm.mapper.impl.JPAServiceDocumentFactory;
4041

4142
public class JPAEdmProvider extends CsdlAbstractEdmProvider {
42-
4343
private final JPAEdmNameBuilder nameBuilder;
4444
private final JPAServiceDocument serviceDocument;
45+
private final List<String> userGroups;
4546

4647
// http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part3-csdl/odata-v4.0-errata02-os-part3-csdl-complete.html#_Toc406397930
4748
public JPAEdmProvider(@Nonnull final String namespace, @Nonnull final EntityManagerFactory emf,
@@ -68,8 +69,27 @@ public JPAEdmProvider(final Metamodel jpaMetamodel, final JPAEdmMetadataPostProc
6869
super();
6970
this.nameBuilder = nameBuilder;
7071
// After this call either a schema exists or an exception has been thrown
71-
this.serviceDocument = new JPAServiceDocumentFactory(nameBuilder, jpaMetamodel, postProcessor, packageName,
72-
annotationProvider).getServiceDocument();
72+
this.serviceDocument = new JPAServiceDocumentFactory().getServiceDocument(nameBuilder, jpaMetamodel, postProcessor,
73+
packageName, annotationProvider);
74+
this.userGroups = List.of();
75+
}
76+
77+
private JPAEdmProvider(JPAEdmProvider source, List<String> userGroups) throws ODataJPAModelException {
78+
this.nameBuilder = source.nameBuilder;
79+
this.serviceDocument = new JPAServiceDocumentFactory().asUserGroupRestricted(source.serviceDocument, userGroups);
80+
this.userGroups = userGroups;
81+
}
82+
83+
public JPAEdmProvider asUserGroupRestricted(List<String> userGroups) {
84+
try {
85+
return new JPAEdmProvider(this, userGroups);
86+
} catch (ODataJPAModelException e) {
87+
throw new ODataJPAModelCopyException("Could not create restricted metadata", e);
88+
}
89+
}
90+
91+
List<String> getUserGroups() {
92+
return userGroups;
7393
}
7494

7595
/**
@@ -330,4 +350,5 @@ public JPAEdmNameBuilder getEdmNameBuilder() {
330350
protected final FullQualifiedName buildFQN(final String name) {
331351
return new FullQualifiedName(nameBuilder.getNamespace(), name);
332352
}
353+
333354
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.sap.olingo.jpa.metadata.api;
2+
3+
import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException;
4+
5+
public class ODataJPAModelCopyException extends RuntimeException {
6+
7+
private static final long serialVersionUID = -1695284009828517502L;
8+
9+
public ODataJPAModelCopyException(final String message, final ODataJPAModelException exception) {
10+
super(message, exception);
11+
}
12+
}

jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAEntityType.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.sap.olingo.jpa.metadata.core.edm.annotation.EdmQueryExtensionProvider;
99
import com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException;
1010

11-
public interface JPAEntityType extends JPAStructuredType, JPAAnnotatable {
11+
public interface JPAEntityType extends JPAStructuredType, JPAAnnotatable, JPAUserGroupRestrictable {
1212
/**
1313
* Searches for a Collection Property defined by the name used in the OData metadata in all the collection properties
1414
* that are available for this type via the OData service. That is:
@@ -25,7 +25,7 @@ public interface JPAEntityType extends JPAStructuredType, JPAAnnotatable {
2525

2626
/**
2727
*
28-
* @return Mime type of streaming content
28+
* @return Mime type of streaming content. Empty if no stream property exists
2929
* @throws ODataJPAModelException
3030
*/
3131
public String getContentType() throws ODataJPAModelException;
@@ -78,6 +78,7 @@ public interface JPAEntityType extends JPAStructuredType, JPAAnnotatable {
7878
/**
7979
*
8080
* @return Name of the database table. The table name is composed from schema name and table name
81+
* @throws ODataJPAModelException
8182
*/
8283
public String getTableName();
8384

jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.apache.olingo.commons.api.edm.provider.CsdlReturnType;
44

5-
public interface JPAOperation extends JPAElement {
5+
public interface JPAOperation extends JPAElement, JPAUserGroupRestrictable {
66
/**
77
*
88
* @return The return or result parameter of the function

jpa/odata-jpa-metadata/src/main/java/com/sap/olingo/jpa/metadata/core/edm/mapper/api/JPAStructuredType.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ public Optional<JPAAttribute> getAttribute(@Nonnull final UriResourceProperty ur
152152
* Determines if the structured type has a super type, that will be part of OData metadata. That is, the method will
153153
* return null in case the entity has a MappedSuperclass.
154154
* @return Determined super type or null
155+
* @throws ODataJPAModelException
155156
*/
156157
@CheckForNull
157-
public JPAStructuredType getBaseType();
158+
public JPAStructuredType getBaseType() throws ODataJPAModelException;
158159

159-
public List<JPAPath> searchChildPath(final JPAPath selectItemPath);
160+
public List<JPAPath> searchChildPath(final JPAPath selectItemPath) throws ODataJPAModelException;
160161
}

0 commit comments

Comments
 (0)