Skip to content

Commit b7272e3

Browse files
mcgilmanmarkap14
authored andcommitted
- Fixing process group audit advice. - Setting spring security user in background threads. - Removing unnecessary overloaded methods. This closes #2626. Signed-off-by: Mark Payne <markap14@hotmail.com>
1 parent 6fbe151 commit b7272e3

13 files changed

Lines changed: 174 additions & 336 deletions

File tree

nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ProcessGroupAuditor.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.ArrayList;
4343
import java.util.Collection;
4444
import java.util.Date;
45+
import java.util.Set;
4546
import java.util.concurrent.Future;
4647

4748
/**
@@ -63,7 +64,7 @@ public class ProcessGroupAuditor extends NiFiAuditor {
6364
* @throws java.lang.Throwable ex
6465
*/
6566
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && "
66-
+ "execution(org.apache.nifi.groups.ProcessGroup createProcessGroup(java.lang.String, org.apache.nifi.web.api.dto.ProcessGroupDTO))")
67+
+ "execution(org.apache.nifi.groups.ProcessGroup createProcessGroup(String, org.apache.nifi.web.api.dto.ProcessGroupDTO))")
6768
public ProcessGroup createProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
6869
// create the process group
6970
ProcessGroup processGroup = (ProcessGroup) proceedingJoinPoint.proceed();
@@ -177,9 +178,9 @@ public ProcessGroup updateProcessGroupAdvice(ProceedingJoinPoint proceedingJoinP
177178
* @throws Throwable ex
178179
*/
179180
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && "
180-
+ "execution(java.util.concurrent.Future<Void> scheduleComponents(java.lang.String, org.apache.nifi.controller.ScheduledState, java.util.Set)) && "
181-
+ "args(groupId, state)")
182-
public Future<Void> scheduleComponentsAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ScheduledState state) throws Throwable {
181+
+ "execution(java.util.concurrent.Future<Void> scheduleComponents(String, org.apache.nifi.controller.ScheduledState, java.util.Set<String>)) && "
182+
+ "args(groupId, state, componentIds)")
183+
public Future<Void> scheduleComponentsAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ScheduledState state, Set<String> componentIds) throws Throwable {
183184
final Operation operation;
184185

185186
final Future<Void> result = (Future<Void>) proceedingJoinPoint.proceed();
@@ -191,7 +192,7 @@ public Future<Void> scheduleComponentsAdvice(ProceedingJoinPoint proceedingJoinP
191192
operation = Operation.Stop;
192193
}
193194

194-
saveUpdateAction(NiFiUserUtils.getNiFiUser(), groupId, operation);
195+
saveUpdateAction(groupId, operation);
195196

196197
return result;
197198
}
@@ -206,9 +207,9 @@ public Future<Void> scheduleComponentsAdvice(ProceedingJoinPoint proceedingJoinP
206207
* @throws Throwable ex
207208
*/
208209
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && "
209-
+ "execution(java.util.concurrent.Future<Void> activateControllerServices(java.lang.String, org.apache.nifi.controller.service.ControllerServiceState, java.util.Set)) && "
210-
+ "args(groupId, state)")
211-
public Future<Void> activateControllerServicesAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ControllerServiceState state) throws Throwable {
210+
+ "execution(java.util.concurrent.Future<Void> activateControllerServices(String, org.apache.nifi.controller.service.ControllerServiceState, java.util.Collection<String>)) && "
211+
+ "args(groupId, state, serviceIds)")
212+
public Future<Void> activateControllerServicesAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ControllerServiceState state, Collection<String> serviceIds) throws Throwable {
212213
final Operation operation;
213214

214215
final Future<Void> result = (Future<Void>) proceedingJoinPoint.proceed();
@@ -220,7 +221,7 @@ public Future<Void> activateControllerServicesAdvice(ProceedingJoinPoint proceed
220221
operation = Operation.Disable;
221222
}
222223

223-
saveUpdateAction(NiFiUserUtils.getNiFiUser(), groupId, operation);
224+
saveUpdateAction(groupId, operation);
224225

225226
return result;
226227
}
@@ -229,17 +230,16 @@ public Future<Void> activateControllerServicesAdvice(ProceedingJoinPoint proceed
229230
* Audits the update of process group variable registry.
230231
*
231232
* @param proceedingJoinPoint join point
232-
* @param user the user performing the action
233233
* @param variableRegistry variable registry
234234
* @throws Throwable ex
235235
*/
236236
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && "
237-
+ "execution(org.apache.nifi.groups.ProcessGroup updateVariableRegistry(org.apache.nifi.authorization.user.NiFiUser, org.apache.nifi.web.api.dto.VariableRegistryDTO)) && "
238-
+ "args(user, variableRegistry)")
239-
public ProcessGroup updateVariableRegistryAdvice(final ProceedingJoinPoint proceedingJoinPoint, final NiFiUser user, final VariableRegistryDTO variableRegistry) throws Throwable {
237+
+ "execution(org.apache.nifi.groups.ProcessGroup updateVariableRegistry(org.apache.nifi.web.api.dto.VariableRegistryDTO)) && "
238+
+ "args(variableRegistry)")
239+
public ProcessGroup updateVariableRegistryAdvice(final ProceedingJoinPoint proceedingJoinPoint, final VariableRegistryDTO variableRegistry) throws Throwable {
240240
final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
241241

242-
saveUpdateAction(user, variableRegistry.getProcessGroupId(), Operation.Configure);
242+
saveUpdateAction(variableRegistry.getProcessGroupId(), Operation.Configure);
243243

244244
return updatedProcessGroup;
245245
}
@@ -249,7 +249,6 @@ public ProcessGroup updateVariableRegistryAdvice(final ProceedingJoinPoint proce
249249
public ProcessGroup updateProcessGroupFlowAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
250250
final Object[] args = proceedingJoinPoint.getArgs();
251251
final String groupId = (String) args[0];
252-
final NiFiUser user = (NiFiUser) args[1];
253252

254253
final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
255254
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
@@ -271,7 +270,7 @@ public ProcessGroup updateProcessGroupFlowAdvice(final ProceedingJoinPoint proce
271270
}
272271
}
273272

274-
saveUpdateAction(user, groupId, operation);
273+
saveUpdateAction(groupId, operation);
275274

276275
return updatedProcessGroup;
277276
}
@@ -294,23 +293,24 @@ public ProcessGroup updateVersionControlInformationAdvice(final ProceedingJoinPo
294293
operation = Operation.CommitLocalChanges;
295294
}
296295

297-
saveUpdateAction(NiFiUserUtils.getNiFiUser(), vciDto.getGroupId(), operation);
296+
saveUpdateAction(vciDto.getGroupId(), operation);
298297

299298
return updatedProcessGroup;
300299
}
301300

302301
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && "
303-
+ "execution(org.apache.nifi.groups.ProcessGroup disconnectVersionControl(java.lang.String)) && "
302+
+ "execution(org.apache.nifi.groups.ProcessGroup disconnectVersionControl(String)) && "
304303
+ "args(groupId)")
305304
public ProcessGroup disconnectVersionControlAdvice(final ProceedingJoinPoint proceedingJoinPoint, final String groupId) throws Throwable {
306305
final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
307306

308-
saveUpdateAction(NiFiUserUtils.getNiFiUser(), groupId, Operation.StopVersionControl);
307+
saveUpdateAction(groupId, Operation.StopVersionControl);
309308

310309
return updatedProcessGroup;
311310
}
312311

313-
private void saveUpdateAction(final NiFiUser user, final String groupId, final Operation operation) throws Throwable {
312+
private void saveUpdateAction(final String groupId, final Operation operation) throws Throwable {
313+
NiFiUser user = NiFiUserUtils.getNiFiUser();
314314
ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
315315
ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
316316

@@ -335,7 +335,7 @@ private void saveUpdateAction(final NiFiUser user, final String groupId, final O
335335
* @throws Throwable ex
336336
*/
337337
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && "
338-
+ "execution(void deleteProcessGroup(java.lang.String)) && "
338+
+ "execution(void deleteProcessGroup(String)) && "
339339
+ "args(groupId)")
340340
public void removeProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId) throws Throwable {
341341
// get the process group before removing it

nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -548,14 +548,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
548548
*/
549549
ProcessorDiagnosticsEntity getProcessorDiagnostics(String id);
550550

551-
/**
552-
* Gets the Processor transfer object for the specified id, as it is visible to the given user
553-
*
554-
* @param id Id of the processor to return
555-
* @return The Processor transfer object
556-
*/
557-
ProcessorEntity getProcessor(String id, NiFiUser user);
558-
559551
/**
560552
* Gets the processor status.
561553
*
@@ -802,15 +794,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
802794
*/
803795
PortEntity getInputPort(String inputPortId);
804796

805-
/**
806-
* Gets an input port as it is available to the given user
807-
*
808-
* @param inputPortId The input port id
809-
* @param user the user
810-
* @return port
811-
*/
812-
PortEntity getInputPort(String inputPortId, NiFiUser user);
813-
814797
/**
815798
* Gets all input ports in a given group.
816799
*
@@ -880,15 +863,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
880863
*/
881864
PortEntity getOutputPort(String outputPortId);
882865

883-
/**
884-
* Gets an output port as it is available to the given user
885-
*
886-
* @param outputPortId The output port id
887-
* @param user the user
888-
* @return port
889-
*/
890-
PortEntity getOutputPort(String outputPortId, NiFiUser user);
891-
892866
/**
893867
* Gets all output ports in a given group.
894868
*
@@ -1001,15 +975,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
1001975
*/
1002976
VariableRegistryEntity updateVariableRegistry(Revision revision, VariableRegistryDTO variableRegistryDto);
1003977

1004-
/**
1005-
* Updates the variable registry on behalf of the given user
1006-
*
1007-
* @param user the user who performed the action
1008-
* @param revision Revision to compare with current base revision
1009-
* @param variableRegistryDto the Variable Registry
1010-
*/
1011-
VariableRegistryEntity updateVariableRegistry(NiFiUser user, Revision revision, VariableRegistryDTO variableRegistryDto);
1012-
1013978
/**
1014979
* Determines which components will be affected by updating the given Variable Registry.
1015980
*
@@ -1063,17 +1028,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
10631028
*/
10641029
ActivateControllerServicesEntity activateControllerServices(String processGroupId, ControllerServiceState state, Map<String, Revision> serviceRevisions);
10651030

1066-
/**
1067-
* Enables or disables the controller services with the given IDs & Revisions on behalf of the given user
1068-
*
1069-
* @param user the user performing the action
1070-
* @param processGroupId the ID of the process group
1071-
* @param state the desired state of the services
1072-
* @param serviceRevisions a mapping of Controller Service ID to current Revision
1073-
* @return snapshot
1074-
*/
1075-
ActivateControllerServicesEntity activateControllerServices(NiFiUser user, String processGroupId, ControllerServiceState state, Map<String, Revision> serviceRevisions);
1076-
10771031
/**
10781032
* Schedules all applicable components under the specified ProcessGroup on behalf of the currently logged in user.
10791033
*
@@ -1084,17 +1038,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
10841038
*/
10851039
ScheduleComponentsEntity scheduleComponents(String processGroupId, ScheduledState state, Map<String, Revision> componentRevisions);
10861040

1087-
/**
1088-
* Schedules all applicable components under the specified ProcessGroup on behalf of the given user.
1089-
*
1090-
* @param user the user performing the action
1091-
* @param processGroupId The ProcessGroup id
1092-
* @param state schedule state
1093-
* @param componentRevisions components and their revision
1094-
* @return snapshot
1095-
*/
1096-
ScheduleComponentsEntity scheduleComponents(NiFiUser user, String processGroupId, ScheduledState state, Map<String, Revision> componentRevisions);
1097-
10981041
/**
10991042
* Updates the specified process group.
11001043
*
@@ -1161,16 +1104,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
11611104
*/
11621105
RemoteProcessGroupEntity getRemoteProcessGroup(String remoteProcessGroupId);
11631106

1164-
/**
1165-
* Gets a remote process group as it is visible to the given user
1166-
*
1167-
* @param remoteProcessGroupId The id of the remote process group
1168-
* @param user the user requesting the action
1169-
* @return group
1170-
*/
1171-
RemoteProcessGroupEntity getRemoteProcessGroup(String remoteProcessGroupId, NiFiUser user);
1172-
1173-
11741107
/**
11751108
* Gets all remote process groups in the a given parent group.
11761109
*
@@ -1179,15 +1112,6 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
11791112
*/
11801113
Set<RemoteProcessGroupEntity> getRemoteProcessGroups(String groupId);
11811114

1182-
/**
1183-
* Gets all remote process groups in the a given parent group as they are visible to the given user
1184-
*
1185-
* @param groupId The id of the parent group
1186-
* @param user the user making the request
1187-
* @return group
1188-
*/
1189-
Set<RemoteProcessGroupEntity> getRemoteProcessGroups(String groupId, NiFiUser user);
1190-
11911115
/**
11921116
* Gets the remote process group status.
11931117
*
@@ -1456,10 +1380,9 @@ VersionControlInformationEntity setVersionControlInformation(Revision processGro
14561380
*
14571381
* @param processGroupId the ID of the Process Group to update
14581382
* @param updatedSnapshot the snapshot to update the Process Group to
1459-
* @param user the user making the request
14601383
* @return the set of all components that would be affected by updating the Process Group
14611384
*/
1462-
Set<AffectedComponentEntity> getComponentsAffectedByVersionChange(String processGroupId, VersionedFlowSnapshot updatedSnapshot, NiFiUser user);
1385+
Set<AffectedComponentEntity> getComponentsAffectedByVersionChange(String processGroupId, VersionedFlowSnapshot updatedSnapshot);
14631386

14641387
/**
14651388
* Verifies that the Process Group with the given identifier can be updated to the proposed flow
@@ -1499,7 +1422,6 @@ VersionControlInformationEntity setVersionControlInformation(Revision processGro
14991422
/**
15001423
* Updates the Process group with the given ID to match the new snapshot
15011424
*
1502-
* @param user the user performing the request
15031425
* @param revision the revision of the Process Group
15041426
* @param groupId the ID of the Process Group
15051427
* @param versionControlInfo the Version Control information
@@ -1510,7 +1432,7 @@ VersionControlInformationEntity setVersionControlInformation(Revision processGro
15101432
* update the contents of that Process Group
15111433
* @return the Process Group
15121434
*/
1513-
ProcessGroupEntity updateProcessGroupContents(NiFiUser user, Revision revision, String groupId, VersionControlInformationDTO versionControlInfo, VersionedFlowSnapshot snapshot,
1435+
ProcessGroupEntity updateProcessGroupContents(Revision revision, String groupId, VersionControlInformationDTO versionControlInfo, VersionedFlowSnapshot snapshot,
15141436
String componentIdSeed, boolean verifyNotModified, boolean updateSettings, boolean updateDescendantVersionedFlows);
15151437

15161438
// ----------------------------------------
@@ -1784,17 +1706,6 @@ ProcessGroupEntity updateProcessGroupContents(NiFiUser user, Revision revision,
17841706
*/
17851707
Set<ControllerServiceEntity> getControllerServices(String groupId, boolean includeAncestorGroups, boolean includeDescendantGroups);
17861708

1787-
/**
1788-
* Gets all controller services that belong to the given group and its parent/ancestor groups
1789-
*
1790-
* @param groupId the id of the process group of interest
1791-
* @param includeAncestorGroups if true, parent and ancestor groups' services will be returned as well
1792-
* @param includeDescendantGroups if true, child and descendant groups' services will be returned as well
1793-
* @param user the user that is retrieving the Controller Services
1794-
* @return services
1795-
*/
1796-
Set<ControllerServiceEntity> getControllerServices(String groupId, boolean includeAncestorGroups, boolean includeDescendantGroups, NiFiUser user);
1797-
17981709
/**
17991710
* Gets the specified controller service.
18001711
*
@@ -1803,15 +1714,6 @@ ProcessGroupEntity updateProcessGroupContents(NiFiUser user, Revision revision,
18031714
*/
18041715
ControllerServiceEntity getControllerService(String controllerServiceId);
18051716

1806-
/**
1807-
* Gets the specified controller service as it is visible to the given user
1808-
*
1809-
* @param controllerServiceId id
1810-
* @param user the user making the request
1811-
* @return service
1812-
*/
1813-
ControllerServiceEntity getControllerService(String controllerServiceId, NiFiUser user);
1814-
18151717
/**
18161718
* Get the descriptor for the specified property of the specified controller service.
18171719
*

0 commit comments

Comments
 (0)