6
6
*/
7
7
package org .gridsuite .gateway .endpoints ;
8
8
9
- import lombok .NonNull ;
10
9
import org .gridsuite .gateway .ServiceURIsConfig ;
11
- import org .gridsuite .gateway .dto .AccessControlInfos ;
12
- import org .slf4j .Logger ;
13
- import org .slf4j .LoggerFactory ;
14
- import org .springframework .http .HttpMethod ;
15
- import org .springframework .http .server .RequestPath ;
16
- import org .springframework .http .server .reactive .ServerHttpRequest ;
17
10
import org .springframework .stereotype .Component ;
18
11
19
- import java .util .*;
20
12
21
13
/**
22
14
* @author Slimane Amar <slimane.amar at rte-france.com>
23
15
*/
24
16
@ Component (value = ExploreServer .ENDPOINT_NAME )
25
17
public class ExploreServer implements EndPointElementServer {
26
- private static final Logger LOGGER = LoggerFactory .getLogger (ExploreServer .class );
27
18
28
19
public static final String ENDPOINT_NAME = "explore" ;
29
20
@@ -36,11 +27,6 @@ public ExploreServer(ServiceURIsConfig servicesURIsConfig) {
36
27
this .servicesURIsConfig = servicesURIsConfig ;
37
28
}
38
29
39
- @ Override
40
- public UUID getElementUuidIfExist (@ NonNull RequestPath path ) {
41
- return (path .elements ().size () > 7 ) ? EndPointElementServer .getUuid (path .elements ().get (7 ).value ()) : null ;
42
- }
43
-
44
30
@ Override
45
31
public String getEndpointBaseUri () {
46
32
return servicesURIsConfig .getExploreServerBaseUri ();
@@ -50,57 +36,4 @@ public String getEndpointBaseUri() {
50
36
public String getEndpointName () {
51
37
return ENDPOINT_NAME ;
52
38
}
53
-
54
- @ Override
55
- public boolean hasElementsAccessControl () {
56
- return true ;
57
- }
58
-
59
- private UUID getUniqueOptionalUuidFromParam (@ NonNull ServerHttpRequest request , @ NonNull String queryParamName ) {
60
- List <String > ids = request .getQueryParams ().get (queryParamName );
61
- if (ids != null && ids .size () != 1 ) {
62
- throw new IllegalArgumentException ("There must be only one " + queryParamName );
63
- }
64
- if (ids != null ) {
65
- UUID uuid = EndPointElementServer .getUuid (ids .get (0 ));
66
- if (uuid == null ) {
67
- throw new IllegalArgumentException (queryParamName + " must be an UUID" );
68
- }
69
- return uuid ;
70
- }
71
- return null ;
72
- }
73
-
74
- @ Override
75
- public Optional <AccessControlInfos > getAccessControlInfos (@ NonNull ServerHttpRequest request ) {
76
- RequestPath path = Objects .requireNonNull (request .getPath ());
77
- UUID elementUuid = getElementUuidIfExist (path );
78
- if (Objects .requireNonNull (request .getMethod ()) != HttpMethod .POST ) {
79
- return EndPointElementServer .super .getAccessControlInfos (request );
80
- }
81
- // Elements creation
82
- if (elementUuid != null ) {
83
- return Optional .of (AccessControlInfos .create (List .of (elementUuid )));
84
- }
85
- try {
86
- List <UUID > uuidsToControl = new ArrayList <>();
87
- UUID duplicateFromUuid = getUniqueOptionalUuidFromParam (request , QUERY_PARAM_DUPLICATE_FROM_ID );
88
- if (duplicateFromUuid != null ) {
89
- uuidsToControl .add (duplicateFromUuid );
90
- }
91
- UUID parentDirectoryUuid = getUniqueOptionalUuidFromParam (request , QUERY_PARAM_PARENT_DIRECTORY_ID );
92
- if (parentDirectoryUuid != null ) {
93
- uuidsToControl .add (parentDirectoryUuid );
94
- }
95
- if (uuidsToControl .isEmpty ()) {
96
- // At least one of the param is required
97
- return Optional .empty ();
98
- }
99
- // Check resources access
100
- return Optional .of (AccessControlInfos .create (uuidsToControl ));
101
- } catch (IllegalArgumentException e ) {
102
- LOGGER .error (e .getMessage ());
103
- return Optional .empty ();
104
- }
105
- }
106
39
}
0 commit comments