Skip to content

Commit f3eb189

Browse files
CristianAmbrosinisonartech
authored andcommitted
SONAR-26524 Audit logs - generate audit traces for Jira project binding
1 parent baa0d98 commit f3eb189

5 files changed

Lines changed: 157 additions & 2 deletions

File tree

server/sonar-db-dao/src/main/java/org/sonar/db/audit/AuditPersister.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue;
2929
import org.sonar.db.audit.model.GroupPermissionNewValue;
3030
import org.sonar.db.audit.model.JiraOrganizationBindingNewValue;
31+
import org.sonar.db.audit.model.JiraProjectBindingNewValue;
3132
import org.sonar.db.audit.model.LicenseNewValue;
3233
import org.sonar.db.audit.model.PermissionTemplateNewValue;
3334
import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
@@ -172,4 +173,10 @@ public interface AuditPersister {
172173

173174
void jiraOrganizationBindingDelete(DbSession dbSession, JiraOrganizationBindingNewValue newValue);
174175

176+
void jiraProjectBindingAdd(DbSession dbSession, JiraProjectBindingNewValue newValue);
177+
178+
void jiraProjectBindingUpdate(DbSession dbSession, JiraProjectBindingNewValue newValue);
179+
180+
void jiraProjectBindingDelete(DbSession dbSession, JiraProjectBindingNewValue newValue);
181+
175182
}

server/sonar-db-dao/src/main/java/org/sonar/db/audit/NoOpAuditPersister.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.sonar.db.audit.model.DevOpsPermissionsMappingNewValue;
2929
import org.sonar.db.audit.model.GroupPermissionNewValue;
3030
import org.sonar.db.audit.model.JiraOrganizationBindingNewValue;
31+
import org.sonar.db.audit.model.JiraProjectBindingNewValue;
3132
import org.sonar.db.audit.model.LicenseNewValue;
3233
import org.sonar.db.audit.model.PermissionTemplateNewValue;
3334
import org.sonar.db.audit.model.PersonalAccessTokenNewValue;
@@ -362,4 +363,19 @@ public void jiraOrganizationBindingUpdate(DbSession dbSession, JiraOrganizationB
362363
public void jiraOrganizationBindingDelete(DbSession dbSession, JiraOrganizationBindingNewValue newValue) {
363364
// no op
364365
}
366+
367+
@Override
368+
public void jiraProjectBindingAdd(DbSession dbSession, JiraProjectBindingNewValue newValue) {
369+
// no op
370+
}
371+
372+
@Override
373+
public void jiraProjectBindingUpdate(DbSession dbSession, JiraProjectBindingNewValue newValue) {
374+
// no op
375+
}
376+
377+
@Override
378+
public void jiraProjectBindingDelete(DbSession dbSession, JiraProjectBindingNewValue newValue) {
379+
// no op
380+
}
365381
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* SonarQube
3+
* Copyright (C) 2009-2025 SonarSource Sàrl
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.db.audit.model;
21+
22+
import javax.annotation.CheckForNull;
23+
import javax.annotation.Nullable;
24+
25+
public class JiraProjectBindingNewValue extends NewValue {
26+
27+
@Nullable
28+
private String bindingId;
29+
30+
@Nullable
31+
private String sonarProjectId;
32+
33+
@Nullable
34+
private String jiraOrganizationBindingId;
35+
36+
@Nullable
37+
private String jiraProjectKey;
38+
39+
public JiraProjectBindingNewValue(String bindingId, String sonarProjectId, String jiraOrganizationBindingId, String jiraProjectKey) {
40+
this.bindingId = bindingId;
41+
this.sonarProjectId = sonarProjectId;
42+
this.jiraOrganizationBindingId = jiraOrganizationBindingId;
43+
this.jiraProjectKey = jiraProjectKey;
44+
}
45+
46+
@CheckForNull
47+
public String getBindingId() {
48+
return this.bindingId;
49+
}
50+
51+
@CheckForNull
52+
public String getSonarProjectId() {
53+
return this.sonarProjectId;
54+
}
55+
56+
@CheckForNull
57+
public String getJiraOrganizationBindingId() {
58+
return this.jiraOrganizationBindingId;
59+
}
60+
61+
@CheckForNull
62+
public String getJiraProjectKey() {
63+
return this.jiraProjectKey;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
StringBuilder sb = new StringBuilder("{");
69+
addField(sb, "\"bindingId\": ", this.bindingId, true);
70+
addField(sb, "\"sonarProjectId\": ", this.sonarProjectId, true);
71+
addField(sb, "\"jiraOrganizationBindingId\": ", this.jiraOrganizationBindingId, true);
72+
addField(sb, "\"jiraProjectKey\": ", this.jiraProjectKey, true);
73+
endString(sb);
74+
return sb.toString();
75+
}
76+
}
77+

server/sonar-db-dao/src/main/java/org/sonar/db/jira/dao/JiraProjectBindingDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public Optional<JiraProjectBindingDto> selectBySonarProjectId(DbSession dbSessio
6161
return Optional.ofNullable(getMapper(dbSession).selectBySonarProjectId(sonarProjectId));
6262
}
6363

64-
public void deleteBySonarProjectId(DbSession dbSession, String sonarProjectId) {
65-
getMapper(dbSession).deleteBySonarProjectId(sonarProjectId);
64+
public int deleteBySonarProjectId(DbSession dbSession, String sonarProjectId) {
65+
return getMapper(dbSession).deleteBySonarProjectId(sonarProjectId);
6666
}
6767

6868
public int countAll(DbSession dbSession) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* SonarQube
3+
* Copyright (C) 2009-2025 SonarSource Sàrl
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.db.audit.model;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
class JiraProjectBindingNewValueTest {
27+
28+
private static final String BINDING_ID = "binding-id-123";
29+
private static final String SONAR_PROJECT_ID = "sonar-project-id-456";
30+
private static final String JIRA_ORG_BINDING_ID = "00000000-0000-0000-0000-000000000001";
31+
private static final String JIRA_PROJECT_KEY = "JIRA-123";
32+
33+
@Test
34+
void toString_shouldFormatAllFieldsCorrectly() {
35+
var result = new JiraProjectBindingNewValue(
36+
BINDING_ID,
37+
SONAR_PROJECT_ID,
38+
JIRA_ORG_BINDING_ID,
39+
JIRA_PROJECT_KEY
40+
).toString();
41+
42+
assertThat(result).isEqualTo("{\"bindingId\": \"binding-id-123\", \"sonarProjectId\": \"sonar-project-id-456\", \"jiraOrganizationBindingId\": \"00000000-0000-0000-0000-000000000001\", \"jiraProjectKey\": \"JIRA-123\" }");
43+
}
44+
45+
@Test
46+
void getters_shouldReturnCorrectValues() {
47+
var newValue = new JiraProjectBindingNewValue(BINDING_ID, SONAR_PROJECT_ID, JIRA_ORG_BINDING_ID, JIRA_PROJECT_KEY);
48+
49+
assertThat(newValue.getBindingId()).isEqualTo(BINDING_ID);
50+
assertThat(newValue.getSonarProjectId()).isEqualTo(SONAR_PROJECT_ID);
51+
assertThat(newValue.getJiraOrganizationBindingId()).isEqualTo(JIRA_ORG_BINDING_ID);
52+
assertThat(newValue.getJiraProjectKey()).isEqualTo(JIRA_PROJECT_KEY);
53+
}
54+
}
55+

0 commit comments

Comments
 (0)