11
11
import com .provectus .kafka .ui .model .rbac .AccessContext ;
12
12
import com .provectus .kafka .ui .model .rbac .permission .ClusterConfigAction ;
13
13
import com .provectus .kafka .ui .service .BrokerService ;
14
+ import com .provectus .kafka .ui .service .audit .AuditService ;
14
15
import com .provectus .kafka .ui .service .rbac .AccessControlService ;
15
16
import java .util .List ;
17
+ import java .util .Map ;
18
+ import javax .annotation .Nullable ;
16
19
import lombok .RequiredArgsConstructor ;
17
20
import lombok .extern .slf4j .Slf4j ;
18
21
import org .springframework .http .ResponseEntity ;
27
30
public class BrokersController extends AbstractController implements BrokersApi {
28
31
private final BrokerService brokerService ;
29
32
private final ClusterMapper clusterMapper ;
33
+
34
+ private final AuditService auditService ;
30
35
private final AccessControlService accessControlService ;
31
36
32
37
@ Override
33
38
public Mono <ResponseEntity <Flux <BrokerDTO >>> getBrokers (String clusterName ,
34
39
ServerWebExchange exchange ) {
35
- Mono < Void > validateAccess = accessControlService . validateAccess ( AccessContext .builder ()
40
+ var context = AccessContext .builder ()
36
41
.cluster (clusterName )
37
- .build ());
42
+ .operationName ("getBrokers" )
43
+ .build ();
38
44
39
45
var job = brokerService .getBrokers (getCluster (clusterName )).map (clusterMapper ::toBrokerDto );
40
-
41
- return validateAccess .thenReturn (ResponseEntity .ok (job ));
46
+ return accessControlService .validateAccess (context )
47
+ .thenReturn (ResponseEntity .ok (job ))
48
+ .doOnEach (sig -> auditService .audit (context , sig ));
42
49
}
43
50
44
51
@ Override
45
52
public Mono <ResponseEntity <BrokerMetricsDTO >> getBrokersMetrics (String clusterName , Integer id ,
46
53
ServerWebExchange exchange ) {
47
- Mono < Void > validateAccess = accessControlService . validateAccess ( AccessContext .builder ()
54
+ var context = AccessContext .builder ()
48
55
.cluster (clusterName )
49
- .build ());
56
+ .operationName ("getBrokersMetrics" )
57
+ .operationParams (Map .of ("id" , id ))
58
+ .build ();
50
59
51
- return validateAccess .then (
52
- brokerService .getBrokerMetrics (getCluster (clusterName ), id )
53
- .map (clusterMapper ::toBrokerMetrics )
54
- .map (ResponseEntity ::ok )
55
- .onErrorReturn (ResponseEntity .notFound ().build ())
56
- );
60
+ return accessControlService .validateAccess (context )
61
+ .then (
62
+ brokerService .getBrokerMetrics (getCluster (clusterName ), id )
63
+ .map (clusterMapper ::toBrokerMetrics )
64
+ .map (ResponseEntity ::ok )
65
+ .onErrorReturn (ResponseEntity .notFound ().build ())
66
+ )
67
+ .doOnEach (sig -> auditService .audit (context , sig ));
57
68
}
58
69
59
70
@ Override
60
71
public Mono <ResponseEntity <Flux <BrokersLogdirsDTO >>> getAllBrokersLogdirs (String clusterName ,
61
- List <Integer > brokers ,
72
+ @ Nullable List <Integer > brokers ,
62
73
ServerWebExchange exchange ) {
63
- Mono <Void > validateAccess = accessControlService .validateAccess (AccessContext .builder ()
74
+
75
+ List <Integer > brokerIds = brokers == null ? List .of () : brokers ;
76
+
77
+ var context = AccessContext .builder ()
64
78
.cluster (clusterName )
65
- .build ());
79
+ .operationName ("getAllBrokersLogdirs" )
80
+ .operationParams (Map .of ("brokerIds" , brokerIds ))
81
+ .build ();
66
82
67
- return validateAccess .thenReturn (ResponseEntity .ok (
68
- brokerService .getAllBrokersLogdirs (getCluster (clusterName ), brokers )));
83
+ return accessControlService .validateAccess (context )
84
+ .thenReturn (ResponseEntity .ok (
85
+ brokerService .getAllBrokersLogdirs (getCluster (clusterName ), brokerIds )))
86
+ .doOnEach (sig -> auditService .audit (context , sig ));
69
87
}
70
88
71
89
@ Override
72
90
public Mono <ResponseEntity <Flux <BrokerConfigDTO >>> getBrokerConfig (String clusterName ,
73
91
Integer id ,
74
92
ServerWebExchange exchange ) {
75
- Mono < Void > validateAccess = accessControlService . validateAccess ( AccessContext .builder ()
93
+ var context = AccessContext .builder ()
76
94
.cluster (clusterName )
77
95
.clusterConfigActions (ClusterConfigAction .VIEW )
78
- .build ());
96
+ .operationName ("getBrokerConfig" )
97
+ .operationParams (Map .of ("brokerId" , id ))
98
+ .build ();
79
99
80
- return validateAccess .thenReturn (
100
+ return accessControlService . validateAccess ( context ) .thenReturn (
81
101
ResponseEntity .ok (
82
102
brokerService .getBrokerConfig (getCluster (clusterName ), id )
83
103
.map (clusterMapper ::toBrokerConfig ))
84
- );
104
+ ). doOnEach ( sig -> auditService . audit ( context , sig )) ;
85
105
}
86
106
87
107
@ Override
88
108
public Mono <ResponseEntity <Void >> updateBrokerTopicPartitionLogDir (String clusterName ,
89
109
Integer id ,
90
110
Mono <BrokerLogdirUpdateDTO > brokerLogdir ,
91
111
ServerWebExchange exchange ) {
92
- Mono < Void > validateAccess = accessControlService . validateAccess ( AccessContext .builder ()
112
+ var context = AccessContext .builder ()
93
113
.cluster (clusterName )
94
114
.clusterConfigActions (ClusterConfigAction .VIEW , ClusterConfigAction .EDIT )
95
- .build ());
115
+ .operationName ("updateBrokerTopicPartitionLogDir" )
116
+ .operationParams (Map .of ("brokerId" , id ))
117
+ .build ();
96
118
97
- return validateAccess .then (
119
+ return accessControlService . validateAccess ( context ) .then (
98
120
brokerLogdir
99
121
.flatMap (bld -> brokerService .updateBrokerLogDir (getCluster (clusterName ), id , bld ))
100
122
.map (ResponseEntity ::ok )
101
- );
123
+ ). doOnEach ( sig -> auditService . audit ( context , sig )) ;
102
124
}
103
125
104
126
@ Override
@@ -107,16 +129,18 @@ public Mono<ResponseEntity<Void>> updateBrokerConfigByName(String clusterName,
107
129
String name ,
108
130
Mono <BrokerConfigItemDTO > brokerConfig ,
109
131
ServerWebExchange exchange ) {
110
- Mono < Void > validateAccess = accessControlService . validateAccess ( AccessContext .builder ()
132
+ var context = AccessContext .builder ()
111
133
.cluster (clusterName )
112
134
.clusterConfigActions (ClusterConfigAction .VIEW , ClusterConfigAction .EDIT )
113
- .build ());
135
+ .operationName ("updateBrokerConfigByName" )
136
+ .operationParams (Map .of ("brokerId" , id ))
137
+ .build ();
114
138
115
- return validateAccess .then (
139
+ return accessControlService . validateAccess ( context ) .then (
116
140
brokerConfig
117
141
.flatMap (bci -> brokerService .updateBrokerConfigByName (
118
142
getCluster (clusterName ), id , name , bci .getValue ()))
119
143
.map (ResponseEntity ::ok )
120
- );
144
+ ). doOnEach ( sig -> auditService . audit ( context , sig )) ;
121
145
}
122
146
}
0 commit comments