Skip to content

Commit 9670b48

Browse files
author
Yavor16
committed
add ane enable audit logging to all api-s and crud operations
LMCROSSITXSADEPLOY-2517
1 parent b207b1e commit 9670b48

File tree

52 files changed

+1041
-236
lines changed

Some content is hidden

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

52 files changed

+1041
-236
lines changed

multiapps-controller-core/src/main/java/module-info.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports org.cloudfoundry.multiapps.controller.core;
44
exports org.cloudfoundry.multiapps.controller.core.auditlogging;
5+
exports org.cloudfoundry.multiapps.controller.core.auditlogging.model;
56
exports org.cloudfoundry.multiapps.controller.core.auditlogging.impl;
67
exports org.cloudfoundry.multiapps.controller.core.cf;
78
exports org.cloudfoundry.multiapps.controller.core.cf.apps;

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/Messages.java

+54
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,60 @@ public final class Messages {
179179
public static final String PARSED_TOKEN_EXPIRES_IN_0 = "Parsed token expires in: {0}";
180180
public static final String PARSER_CHAIN_0 = "Parser chain: {0}";
181181

182+
// Audit log
183+
184+
public static final String RETRIEVE_CSRF_TOKEN_AUDIT_LOG_MESSAGE = "Retrieve a CSRF token";
185+
186+
public static final String LIST_FILES_AUDIT_LOG_MESSAGE = "List files in space with id: {0}";
187+
public static final String DELETE_SUBSCRIPTION_AUDIT_LOG_MESSAGE = "Delete subscription in space with id: {0}";
188+
public static final String DELETE_ENTRY_AUDIT_LOG_MESSAGE = "Delete entry in space with id: {0}";
189+
public static final String DELETE_OPERATION_AUDIT_LOG_MESSAGE = "Delete operation in space with id: {0}";
190+
public static final String UPLOAD_FILE_AUDIT_LOG_MESSAGE = "Upload file in space with id: {0}";
191+
public static final String UPLOAD_FILE_FROM_URL_AUDIT_LOG_MESSAGE = "Upload file from url in space with id: {0}";
192+
public static final String GET_INFO_FOR_UPLOAD_URL_JOB_AUDIT_LOG_MESSAGE = "Get info for upload from url job in space with id: {0}";
193+
194+
public static final String LIST_OPERATIONS_AUDIT_LOG_MESSAGE = "List operations for mta in space with id: {0}";
195+
public static final String LIST_OPERATION_ACTIONS_AUDIT_LOG_MESSAGE = "List operation action in space with id: {0}";
196+
public static final String EXECUTE_OPERATION_AUDIT_LOG_MESSAGE = "Execute operation in space with id: {0}";
197+
public static final String GET_OPERATION_LOGS_AUDIT_LOG_MESSAGE = "Get operation logs in space with id: {0}";
198+
public static final String GET_OPERATION_LOG_CONTENT_AUDIT_LOG_MESSAGE = "Get operation log content in space with id: {0}";
199+
public static final String START_OPERATION_AUDIT_LOG_MESSAGE = "Start {0} operation in space with id: {1}";
200+
public static final String GET_INFO_FOR_OPERATION = "Get info for operation in space with id: {0}";
201+
202+
public static final String LIST_MTA_AUDIT_LOG_MESSAGE = "List MTA in space with id: {0}";
203+
public static final String GET_MTA_AUDIT_LOG_MESSAGE = "Get MTA in space with id: {0}";
204+
205+
public static final String GET_INFO_FOR_API_AUDIT_LOG_CONFIG = "Get information for api";
206+
public static final String FETCH_TOKEN_AUDIT_LOG_MESSAGE = "Attempt to fetch access token for client: \"{0}\" in space: \"{1}\" for service \"{2}\"";
207+
public static final String FAILED_TO_FETCH_TOKEN_AUDIT_LOG_MESSAGE = "Failed to fetch access token for client: \"{0}\" in space: \"{1}\" for service \"{2}\"";
208+
209+
public static final String FETCH_TOKEN_AUDIT_LOG_CONFIG = "Access token fetch";
210+
211+
212+
// Audit log configuration
213+
public static final String GET_CSRF_TOKEN_AUDIT_LOG_CONFIG = "CSRF token get ";
214+
215+
public static final String FILE_INFO_AUDIT_LOG_CONFIG = "File info";
216+
public static final String SUBSCRIPTION_DELETE_AUDIT_LOG_CONFIG = "Subscription delete";
217+
public static final String ENTRY_DELETE_AUDIT_LOG_CONFIG = "Entry delete";
218+
public static final String OPERATION_DELETE_AUDIT_LOG_CONFIG = "Operation delete";
219+
public static final String FILE_UPLOAD_AUDIT_LOG_CONFIG = "File upload";
220+
public static final String FILE_UPLOAD_FROM_URL_AUDIT_LOG_CONFIG = "File upload from url";
221+
public static final String UPLOAD_FROM_URL_JOB_INFO_AUDIT_LOG_CONFIG = "Upload from url job info";
222+
223+
public static final String OPERATION_LIST_AUDIT_LOG_CONFIG = "Operation list";
224+
public static final String OPERATION_ACTIONS_LIST_AUDIT_LOG_CONFIG = "Operation actions list";
225+
public static final String EXECUTE_OPERATION_AUDIT_LOG_CONFIG = "Operation action execute";
226+
public static final String LIST_OPERATION_LOGS_AUDIT_LOG_CONFIG = "Operation logs list";
227+
public static final String GET_OPERATION_LOG_CONTENT_AUDIT_LOG_CONFIG = "Operation log content info";
228+
public static final String START_OPERATION_AUDIT_LOG_CONFIG = "Operation start";
229+
public static final String GET_OPERATION_INFO_AUDIT_LOG_CONFIG = "Operation info";
230+
231+
public static final String MTA_INFO_AUDIT_LOG_CONFIG= "MTA info";
232+
public static final String MTA_LIST_AUDIT_LOG_CONFIG = "MTA list";
233+
234+
public static final String API_INFO_AUDIT_LOG_CONFIG= "Api info";
235+
182236
private Messages() {
183237
}
184238
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.cloudfoundry.multiapps.controller.core.auditlogging;
2+
3+
import org.cloudfoundry.multiapps.controller.core.auditlogging.impl.AuditLoggingFacadeSLImpl;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import javax.inject.Inject;
8+
import javax.sql.DataSource;
9+
10+
@Configuration
11+
public class AuditLogBean {
12+
13+
@Bean
14+
@Inject
15+
public AuditLoggingFacade buildAuditLoggingFacade(DataSource dataSource, UserInfoProvider userInfoProvider) {
16+
return new AuditLoggingFacadeSLImpl(dataSource, userInfoProvider);
17+
}
18+
19+
@Bean
20+
@Inject
21+
public CsrfTokenApiServiceAuditLog buildCsrfTokenApiServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
22+
return new CsrfTokenApiServiceAuditLog(auditLoggingFacade);
23+
}
24+
25+
@Bean
26+
@Inject
27+
public FilesApiServiceAuditLog buildFilesApiServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
28+
return new FilesApiServiceAuditLog(auditLoggingFacade);
29+
}
30+
31+
@Bean
32+
@Inject
33+
public LoginAttemptAuditLog buildLoginAttemptAuditLog(AuditLoggingFacade auditLoggingFacade) {
34+
return new LoginAttemptAuditLog(auditLoggingFacade);
35+
}
36+
37+
@Bean
38+
@Inject
39+
public InfoApiServiceAuditLog buildInfoApiServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
40+
return new InfoApiServiceAuditLog(auditLoggingFacade);
41+
}
42+
43+
@Bean
44+
@Inject
45+
public MtasApiServiceAuditLog buildMtasApiServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
46+
return new MtasApiServiceAuditLog(auditLoggingFacade);
47+
}
48+
49+
@Bean
50+
@Inject
51+
public OperationsApiServiceAuditLog buildOperationsApiServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
52+
return new OperationsApiServiceAuditLog(auditLoggingFacade);
53+
}
54+
55+
@Bean
56+
@Inject
57+
public MtaConfigurationPurgerAuditLog buildMtaConfigurationPurgerAuditLog(AuditLoggingFacade auditLoggingFacade) {
58+
return new MtaConfigurationPurgerAuditLog(auditLoggingFacade);
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
11
package org.cloudfoundry.multiapps.controller.core.auditlogging;
22

3-
import java.util.Map;
4-
5-
import org.cloudfoundry.multiapps.mta.model.AuditableConfiguration;
3+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.ConfigurationChangeActions;
4+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.AuditLogConfiguration;
65

76
public interface AuditLoggingFacade {
87

9-
void logSecurityIncident(String message);
10-
11-
void logAboutToStart(String action);
12-
13-
void logAboutToStart(String action, Map<String, Object> parameters);
14-
15-
void logActionStarted(String action, boolean success);
16-
17-
void logConfig(AuditableConfiguration configuration);
18-
19-
void logConfigCreate(AuditableConfiguration configuration);
20-
21-
void logConfigUpdate(AuditableConfiguration configuration);
22-
23-
void logConfigDelete(AuditableConfiguration configuration);
24-
25-
void logConfigUpdated(boolean success);
26-
8+
void logSecurityIncident(AuditLogConfiguration configuration);
9+
void logDataAccessAuditLog(AuditLogConfiguration configuration);
10+
void logConfigurationChangeAuditLog(AuditLogConfiguration configuration, ConfigurationChangeActions configurationAction);
2711
}

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/auditlogging/AuditLoggingProvider.java

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.cloudfoundry.multiapps.controller.core.auditlogging;
2+
3+
import java.text.MessageFormat;
4+
5+
import org.cloudfoundry.multiapps.controller.core.Messages;
6+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.AuditLogConfiguration;
7+
8+
9+
public class AuthenticationAuditLog {
10+
11+
private final AuditLoggingFacade auditLoggingFacade;
12+
13+
public AuthenticationAuditLog(AuditLoggingFacade auditLoggingFacade) {
14+
this.auditLoggingFacade = auditLoggingFacade;
15+
}
16+
17+
public void logFetchTokenAttempt(String clientId, String spaceId, String serviceName) {
18+
String actionPerformed = MessageFormat.format(Messages.FETCH_TOKEN_AUDIT_LOG_MESSAGE, clientId, spaceId, serviceName);
19+
auditLoggingFacade.logSecurityIncident(new AuditLogConfiguration(clientId,
20+
spaceId,
21+
actionPerformed,
22+
Messages.FETCH_TOKEN_AUDIT_LOG_CONFIG));
23+
}
24+
25+
public void logFailedToFetchTokenAttempt(String clientId, String spaceId, String serviceName) {
26+
String actionPerformed = MessageFormat.format(Messages.FAILED_TO_FETCH_TOKEN_AUDIT_LOG_MESSAGE, clientId, spaceId, serviceName);
27+
auditLoggingFacade.logSecurityIncident(new AuditLogConfiguration(clientId,
28+
spaceId,
29+
actionPerformed,
30+
Messages.FETCH_TOKEN_AUDIT_LOG_CONFIG));
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.cloudfoundry.multiapps.controller.core.auditlogging;
2+
3+
import org.cloudfoundry.multiapps.controller.core.Messages;
4+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.AuditLogConfiguration;
5+
6+
public class CsrfTokenApiServiceAuditLog {
7+
8+
private final AuditLoggingFacade auditLoggingFacade;
9+
10+
public CsrfTokenApiServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
11+
this.auditLoggingFacade = auditLoggingFacade;
12+
}
13+
14+
public void logGetInfo(String username) {
15+
String performedAction = Messages.RETRIEVE_CSRF_TOKEN_AUDIT_LOG_MESSAGE;
16+
auditLoggingFacade.logDataAccessAuditLog(new AuditLogConfiguration(username,
17+
"",
18+
performedAction,
19+
Messages.GET_CSRF_TOKEN_AUDIT_LOG_CONFIG));
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package org.cloudfoundry.multiapps.controller.core.auditlogging;
2+
3+
import java.text.MessageFormat;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import java.util.Objects;
7+
8+
import org.cloudfoundry.multiapps.controller.api.model.FileMetadata;
9+
import org.cloudfoundry.multiapps.controller.core.Messages;
10+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.AuditLogConfiguration;
11+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.ConfigurationChangeActions;
12+
13+
public class FilesApiServiceAuditLog {
14+
15+
private static final String NAMESPACE_PROPERTY_NAME = "namespace";
16+
private static final String FILE_URL_PROPERTY_NAME = "fileUrl";
17+
private static final String JOB_ID_PROPERTY_NAME = "jobId";
18+
private static final String DIGEST_ALGORITHM_PROPERTY_NAME = "digestAlgorithm";
19+
private static final String FILE_ID_PROPERTY_NAME = "fileId";
20+
private static final String SIZE_PROPERTY_NAME = "size";
21+
private static final String DIGEST_PROPERTY_NAME = "digest";
22+
23+
private final AuditLoggingFacade auditLoggingFacade;
24+
25+
public FilesApiServiceAuditLog(AuditLoggingFacade auditLoggingFacade) {
26+
this.auditLoggingFacade = auditLoggingFacade;
27+
}
28+
29+
public void logGetFiles(String username, String spaceGuid, String namespace) {
30+
String performedAction = MessageFormat.format(Messages.LIST_FILES_AUDIT_LOG_MESSAGE, spaceGuid);
31+
auditLoggingFacade.logDataAccessAuditLog(new AuditLogConfiguration(username,
32+
spaceGuid,
33+
performedAction,
34+
Messages.FILE_INFO_AUDIT_LOG_CONFIG,
35+
createAuditLogGetFilesConfigurationIdentifier(namespace)));
36+
}
37+
38+
public void logUploadFile(String username, String spaceGuid, FileMetadata fileMetadata) {
39+
String performedAction = MessageFormat.format(Messages.UPLOAD_FILE_AUDIT_LOG_MESSAGE, spaceGuid);
40+
auditLoggingFacade.logConfigurationChangeAuditLog(new AuditLogConfiguration(username,
41+
spaceGuid,
42+
performedAction,
43+
Messages.FILE_UPLOAD_AUDIT_LOG_CONFIG,
44+
createFileMetadataConfigurationIdentifier(fileMetadata)),
45+
ConfigurationChangeActions.CONFIGURATION_CREATE);
46+
}
47+
48+
public void logStartUploadFromUrl(String username, String spaceGuid, String fileUrl) {
49+
String performedAction = MessageFormat.format(Messages.UPLOAD_FILE_FROM_URL_AUDIT_LOG_MESSAGE, spaceGuid);
50+
auditLoggingFacade.logConfigurationChangeAuditLog(new AuditLogConfiguration(username,
51+
spaceGuid,
52+
performedAction,
53+
Messages.FILE_UPLOAD_FROM_URL_AUDIT_LOG_CONFIG,
54+
createAuditLogStartUploadFromUrlConfigurationIdentifier(fileUrl)),
55+
ConfigurationChangeActions.CONFIGURATION_CREATE);
56+
}
57+
58+
public void logGetUploadFromUrlJob(String username, String spaceGuid, String namespace, String jobId) {
59+
String performedAction = MessageFormat.format(Messages.GET_INFO_FOR_UPLOAD_URL_JOB_AUDIT_LOG_MESSAGE, spaceGuid);
60+
auditLoggingFacade.logDataAccessAuditLog(new AuditLogConfiguration(username,
61+
spaceGuid,
62+
performedAction,
63+
Messages.UPLOAD_FROM_URL_JOB_INFO_AUDIT_LOG_CONFIG,
64+
createAuditLogGetUploadFromUrlJobConfigurationIdentifier(namespace,
65+
jobId)));
66+
}
67+
68+
private Map<String, String> createFileMetadataConfigurationIdentifier(FileMetadata fileMetadata) {
69+
Map<String, String> identifiers = new HashMap<>();
70+
71+
identifiers.put(FILE_ID_PROPERTY_NAME, fileMetadata.getId());
72+
identifiers.put(DIGEST_PROPERTY_NAME, fileMetadata.getDigest());
73+
identifiers.put(DIGEST_ALGORITHM_PROPERTY_NAME, fileMetadata.getDigestAlgorithm());
74+
identifiers.put(SIZE_PROPERTY_NAME, Objects.toString(fileMetadata.getSize()));
75+
identifiers.put(NAMESPACE_PROPERTY_NAME, fileMetadata.getNamespace());
76+
77+
return identifiers;
78+
}
79+
80+
private Map<String, String> createAuditLogGetFilesConfigurationIdentifier(String namespace) {
81+
Map<String, String> identifiers = new HashMap<>();
82+
83+
identifiers.put(NAMESPACE_PROPERTY_NAME, namespace);
84+
85+
return identifiers;
86+
}
87+
88+
private Map<String, String> createAuditLogGetUploadFromUrlJobConfigurationIdentifier(String namespace, String jobId) {
89+
Map<String, String> identifiers = new HashMap<>();
90+
91+
identifiers.put(NAMESPACE_PROPERTY_NAME, namespace);
92+
identifiers.put(JOB_ID_PROPERTY_NAME, jobId);
93+
94+
return identifiers;
95+
}
96+
97+
private Map<String, String> createAuditLogStartUploadFromUrlConfigurationIdentifier(String fileUrl) {
98+
Map<String, String> identifiers = new HashMap<>();
99+
100+
identifiers.put(FILE_URL_PROPERTY_NAME, fileUrl);
101+
102+
return identifiers;
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.cloudfoundry.multiapps.controller.core.auditlogging;
2+
3+
import java.util.Map;
4+
5+
import org.cloudfoundry.multiapps.controller.core.auditlogging.AuditLoggingFacade;
6+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.AuditLogConfiguration;
7+
import org.cloudfoundry.multiapps.controller.core.auditlogging.model.ConfigurationChangeActions;
8+
9+
public class FlowableSlmpResourceAuditLog {
10+
11+
private final AuditLoggingFacade auditLoggingFacade;
12+
13+
public FlowableSlmpResourceAuditLog(AuditLoggingFacade auditLoggingFacade) {
14+
this.auditLoggingFacade = auditLoggingFacade;
15+
}
16+
17+
public void auditLogConfigurationChange(String username, String spaceId, String action, String configuration,
18+
ConfigurationChangeActions configurationAction) {
19+
auditLoggingFacade.logConfigurationChangeAuditLog(new AuditLogConfiguration(username, spaceId, action, configuration),
20+
configurationAction);
21+
}
22+
23+
public void auditLogActionPerformed(String username, String spaceId, String action, String configuration) {
24+
auditLoggingFacade.logDataAccessAuditLog(new AuditLogConfiguration(username, spaceId, action, configuration));
25+
}
26+
27+
public void auditLogActionPerformed(String username, String spaceId, String action, String configuration,
28+
Map<String, String> parameters) {
29+
auditLoggingFacade.logDataAccessAuditLog(new AuditLogConfiguration(username, spaceId, action, configuration, parameters));
30+
}
31+
}

0 commit comments

Comments
 (0)