3
3
import org .eclipse .edc .policy .engine .spi .AtomicConstraintFunction ;
4
4
import org .eclipse .edc .policy .engine .spi .PolicyContext ;
5
5
import org .eclipse .edc .policy .model .Operator ;
6
- import org .eclipse .edc .policy .model .Permission ;
7
6
import org .eclipse .edc .policy .model .Rule ;
8
7
import org .eclipse .edc .spi .agent .ParticipantAgent ;
9
8
import org .eclipse .edc .spi .monitor .Monitor ;
10
9
11
10
import java .util .Arrays ;
12
- import java .util .Collection ;
13
11
import java .util .Map ;
14
12
import java .util .Objects ;
15
13
16
14
import static java .lang .String .format ;
17
15
18
- public class ConnectorIdConstraintFunction <R extends Rule > implements AtomicConstraintFunction <R > {
16
+ public class ClientClaimConstraintFunction <R extends Rule > implements AtomicConstraintFunction <R > {
19
17
20
18
private final Monitor monitor ;
19
+ private final String clientClaimName ;
20
+ private final boolean verbose ;
21
21
22
- public ConnectorIdConstraintFunction (Monitor monitor ) {
22
+ public ClientClaimConstraintFunction (Monitor monitor , String clientClaimName , boolean verbose ) {
23
23
this .monitor = monitor ;
24
+ this .clientClaimName = clientClaimName ;
25
+ this .verbose = verbose ;
24
26
}
25
27
26
28
@ Override
@@ -36,27 +38,30 @@ public boolean evaluate(Operator operator, Object rightValue, R rule, PolicyCont
36
38
return false ;
37
39
}
38
40
39
- for (Map .Entry <String , Object > e : contextData .getClaims ().entrySet ()) {
40
- monitor .info (format ("Found claim %s : %s" , e .getKey (), e .getValue ()));
41
- }
41
+ if (verbose ) {
42
+ for (Map .Entry <String , Object > e : contextData .getClaims ().entrySet ()) {
43
+ monitor .info (format ("Found claim %s : %s" , e .getKey (), e .getValue ()));
44
+ }
42
45
43
- for (Map .Entry <String , String > e : contextData .getAttributes ().entrySet ()) {
44
- monitor .info (format ("Found attribute %s : %s" , e .getKey (), e .getValue ()));
46
+ for (Map .Entry <String , String > e : contextData .getAttributes ().entrySet ()) {
47
+ monitor .info (format ("Found attribute %s : %s" , e .getKey (), e .getValue ()));
48
+ }
45
49
}
46
50
47
- String clientIdClaim = (String ) contextData .getClaims ().get ("client_id" );
51
+ String clientClaim = (String ) contextData .getClaims ().get (clientClaimName );
48
52
49
- if (clientIdClaim == null ) {
53
+ if (clientClaim == null ) {
54
+ monitor .info (format ("Required claim %s not found." , clientClaimName ));
50
55
return false ;
51
56
}
52
57
53
- monitor .info (format ("Evaluating constraint: connectorId %s %s %s" , clientIdClaim , operator , rightValue ));
58
+ monitor .info (format ("Evaluating constraint: %s %s %s %s" , clientClaimName , clientClaim , operator , rightValue ));
54
59
55
60
return switch (operator ) {
56
- case EQ -> Objects .equals (clientIdClaim , rightValue );
57
- case NEQ -> !Objects .equals (clientIdClaim , rightValue );
58
- case IN , IS_ANY_OF -> Arrays .asList (((String ) rightValue ).split ("," )).contains (clientIdClaim );
59
- case IS_NONE_OF -> !Arrays .asList (((String ) rightValue ).split ("," )).contains (clientIdClaim );
61
+ case EQ -> Objects .equals (clientClaim , rightValue );
62
+ case NEQ -> !Objects .equals (clientClaim , rightValue );
63
+ case IN , IS_ANY_OF -> Arrays .asList (((String ) rightValue ).split ("," )).contains (clientClaim );
64
+ case IS_NONE_OF -> !Arrays .asList (((String ) rightValue ).split ("," )).contains (clientClaim );
60
65
default -> false ;
61
66
};
62
67
}
0 commit comments