1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.audit.event;
17
18
19 import org.openehealth.ipf.commons.audit.AuditException;
20 import org.openehealth.ipf.commons.audit.codes.*;
21
22 import java.util.Collections;
23
24
25
26
27
28
29
30
31
32
33
34 public class AuditLogUsedBuilder extends BaseAuditMessageBuilder<AuditLogUsedBuilder> {
35
36 public AuditLogUsedBuilder(EventOutcomeIndicator outcome) {
37 this(outcome, null);
38 }
39
40 public AuditLogUsedBuilder(EventOutcomeIndicator outcome,
41 String eventOutcomeDescription) {
42 super();
43 setEventIdentification(outcome,
44 eventOutcomeDescription,
45 EventActionCode.Read,
46 EventIdCode.AuditLogUsed,
47 null
48 );
49 }
50
51
52
53
54
55
56
57
58
59
60 public AuditLogUsedBuilder addAccessingParticipant(String userId,
61 String altUserId,
62 String userName,
63 boolean userIsRequestor,
64 String networkId) {
65 return addActiveParticipant(
66 userId,
67 altUserId,
68 userName,
69 userIsRequestor,
70 Collections.emptyList(),
71 networkId);
72 }
73
74
75
76
77
78
79 public AuditLogUsedBuilder addAuditLogIdentity(String auditLogUri) {
80 return addParticipantObjectIdentification(
81 ParticipantObjectIdTypeCode.URI,
82 "Security Audit Log",
83 null,
84 Collections.emptyList(),
85 auditLogUri,
86 ParticipantObjectTypeCode.System,
87 ParticipantObjectTypeCodeRole.SecurityResource,
88 null,
89 null);
90 }
91
92 @Override
93 public void validate() {
94 super.validate();
95 if (getMessage().getActiveParticipants().isEmpty() || getMessage().getActiveParticipants().size() > 2) {
96 throw new AuditException("Must have one or two participants that started the Application");
97 }
98 if (getMessage().findParticipantObjectIdentifications(poi -> ParticipantObjectIdTypeCode.URI.equals(poi.getParticipantObjectTypeCode())).size() != 1) {
99 throw new AuditException("Must have exactly Audit Log Identity Participating Object ");
100 }
101 }
102 }