Skip to content

Commit 55933d2

Browse files
cleanup
make sonarcloud happy
1 parent 82d9421 commit 55933d2

File tree

9 files changed

+29
-50
lines changed

9 files changed

+29
-50
lines changed

backend/src/main/java/org/cryptomator/hub/api/GroupDto.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.cryptomator.hub.entities.Group;
66

77
import java.util.List;
8-
import java.util.Set;
98

109
public final class GroupDto extends AuthorityDto {
1110

backend/src/main/java/org/cryptomator/hub/api/GroupsResource.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.cryptomator.hub.api;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4-
import com.fasterxml.jackson.annotation.JsonUnwrapped;
54
import jakarta.annotation.security.RolesAllowed;
65
import jakarta.inject.Inject;
76
import jakarta.transaction.Transactional;
@@ -11,6 +10,7 @@
1110
import jakarta.ws.rs.Consumes;
1211
import jakarta.ws.rs.DELETE;
1312
import jakarta.ws.rs.GET;
13+
import jakarta.ws.rs.InternalServerErrorException;
1414
import jakarta.ws.rs.NotFoundException;
1515
import jakarta.ws.rs.POST;
1616
import jakarta.ws.rs.PUT;
@@ -30,13 +30,10 @@
3030

3131
import java.net.URI;
3232
import java.util.List;
33-
import java.util.logging.Logger;
3433

3534
@Path("/groups")
3635
public class GroupsResource {
3736

38-
private static final Logger LOG = Logger.getLogger(GroupsResource.class.getName());
39-
4037
@Inject
4138
User.Repository userRepo;
4239
@Inject
@@ -111,7 +108,7 @@ public Response createGroup(@Valid @NotNull CreateGroupDto dto) {
111108

112109
Group group = groupRepo.findById(groupRepresentation.getId());
113110
if (group == null) {
114-
throw new RuntimeException("Group was created in Keycloak but not found in database after sync");
111+
throw new InternalServerErrorException("Group was created in Keycloak but not found in database after sync");
115112
}
116113

117114
return Response.created(URI.create("./" + group.getId()))

backend/src/main/java/org/cryptomator/hub/api/UsersResource.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import jakarta.transaction.Transactional;
88
import jakarta.validation.Valid;
99
import jakarta.validation.constraints.NotNull;
10-
import jakarta.ws.rs.Consumes;
1110
import jakarta.ws.rs.ClientErrorException;
11+
import jakarta.ws.rs.Consumes;
1212
import jakarta.ws.rs.DELETE;
1313
import jakarta.ws.rs.ForbiddenException;
1414
import jakarta.ws.rs.GET;
15+
import jakarta.ws.rs.InternalServerErrorException;
1516
import jakarta.ws.rs.NotFoundException;
1617
import jakarta.ws.rs.POST;
1718
import jakarta.ws.rs.PUT;
@@ -48,15 +49,12 @@
4849
import java.util.Set;
4950
import java.util.UUID;
5051
import java.util.function.Function;
51-
import java.util.logging.Logger;
5252
import java.util.stream.Collectors;
5353

5454
@Path("/users")
5555
@Produces(MediaType.TEXT_PLAIN)
5656
public class UsersResource {
5757

58-
private static final Logger LOG = Logger.getLogger(UsersResource.class.getName());
59-
6058
@Inject
6159
AccessToken.Repository accessTokenRepo;
6260
@Inject
@@ -336,7 +334,7 @@ public Response createUser(@Valid @NotNull CreateUserDto dto) {
336334

337335
User user = userRepo.findById(userRepresentation.getId());
338336
if (user == null) {
339-
throw new RuntimeException("User was created in Keycloak but not found in database after sync");
337+
throw new InternalServerErrorException("User was created in Keycloak but not found in database after sync");
340338
}
341339

342340
return Response.created(URI.create("./" + user.getId()))
@@ -374,9 +372,7 @@ public UserDto.WithDetails getUser(@PathParam("id") String userId) {
374372

375373
// Fetch vaults with roles for the user
376374
List<VaultResource.VaultDtoWithRole> vaults = user.accessibleVaults.stream()
377-
.map(eva -> {
378-
return VaultResource.VaultDtoWithRole.from(eva.getVault(), eva.getRole());
379-
})
375+
.map(eva -> VaultResource.VaultDtoWithRole.from(eva.getVault(), eva.getRole()))
380376
.toList();
381377

382378
// Fetch devices (modern devices)
@@ -385,6 +381,7 @@ public UserDto.WithDetails getUser(@PathParam("id") String userId) {
385381
.collect(Collectors.toSet());
386382

387383
// Fetch legacy devices
384+
@SuppressWarnings("removal")
388385
Set<DeviceResource.DeviceDto> legacyDevices = user.legacyDevices.stream()
389386
.map(DeviceResource.DeviceDto::fromEntity)
390387
.collect(Collectors.toSet());
@@ -435,14 +432,8 @@ public UserDto updateUser(@PathParam("id") String userId, @Valid @NotNull Update
435432
@APIResponse(responseCode = "403", description = "user has federated identity and cannot be deleted")
436433
@APIResponse(responseCode = "404", description = "user not found")
437434
public Response deleteUser(@PathParam("id") String userId) {
438-
try {
439-
keycloakAdminService.deleteUser(userId);
440-
return Response.noContent().build();
441-
} catch (ForbiddenException | NotFoundException e) {
442-
throw e;
443-
} catch (Exception e) {
444-
throw new RuntimeException("Failed to delete user", e);
445-
}
435+
keycloakAdminService.deleteUser(userId);
436+
return Response.noContent().build();
446437
}
447438

448439
public record CreateUserDto(

backend/src/main/java/org/cryptomator/hub/entities/User.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import jakarta.enterprise.context.ApplicationScoped;
77
import jakarta.persistence.Column;
88
import jakarta.persistence.DiscriminatorValue;
9-
import jakarta.persistence.ElementCollection;
109
import jakarta.persistence.Entity;
1110
import jakarta.persistence.FetchType;
1211
import jakarta.persistence.JoinColumn;
@@ -16,9 +15,7 @@
1615
import jakarta.persistence.OneToMany;
1716
import jakarta.persistence.OneToOne;
1817
import jakarta.persistence.Table;
19-
import org.hibernate.Hibernate;
2018
import org.hibernate.annotations.Immutable;
21-
import org.hibernate.annotations.JdbcTypeCode;
2219
import org.hibernate.annotations.Type;
2320

2421
import java.util.Collection;

backend/src/main/java/org/cryptomator/hub/keycloak/KeycloakAuthorityProvider.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import org.keycloak.admin.client.Keycloak;
77
import org.keycloak.admin.client.resource.RealmResource;
88
import org.keycloak.representations.idm.GroupRepresentation;
9-
import org.keycloak.representations.idm.RoleRepresentation;
109
import org.keycloak.representations.idm.UserRepresentation;
1110

1211
import java.util.ArrayList;
13-
import java.util.HashSet;
1412
import java.util.List;
1513
import java.util.Map;
1614
import java.util.Optional;

backend/src/main/java/org/cryptomator/hub/keycloak/KeycloakAuthorityPuller.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
import org.cryptomator.hub.entities.EffectiveGroupMembership;
99
import org.cryptomator.hub.entities.Group;
1010
import org.cryptomator.hub.entities.User;
11-
import org.keycloak.representations.idm.UserRepresentation;
1211

1312
import java.util.Arrays;
1413
import java.util.HashMap;
1514
import java.util.HashSet;
16-
import java.util.List;
1715
import java.util.Map;
1816
import java.util.Set;
1917
import java.util.function.Function;

backend/src/test/java/org/cryptomator/hub/api/GroupsResourceIT.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ void testGet(String method, String path) {
140140
public class GroupCrudOperations {
141141

142142
@BeforeEach
143-
public void resetMocks() {
143+
void resetMocks() {
144144
Mockito.reset(keycloakAdminService);
145145
}
146146

147147
@BeforeAll
148-
public void setup() throws SQLException {
148+
void setup() throws SQLException {
149149
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
150150
s.execute("""
151151
INSERT INTO "authority" ("id", "type", "name") VALUES ('newGroupId123', 'GROUP', 'New Group');
@@ -155,7 +155,7 @@ public void setup() throws SQLException {
155155
}
156156

157157
@AfterAll
158-
public void tearDown() throws SQLException {
158+
void tearDown() throws SQLException {
159159
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
160160
s.execute("""
161161
DELETE FROM "authority" WHERE "id" = 'newGroupId123';
@@ -165,7 +165,7 @@ public void tearDown() throws SQLException {
165165

166166
@Test
167167
@DisplayName("POST /groups returns 201 when group created successfully")
168-
public void testCreateGroupSuccess() {
168+
void testCreateGroupSuccess() {
169169
var groupRep = new GroupRepresentation();
170170
groupRep.setId("newGroupId123");
171171
groupRep.setName("New Group");
@@ -187,7 +187,7 @@ public void testCreateGroupSuccess() {
187187

188188
@Test
189189
@DisplayName("POST /groups returns 409 when group name already exists")
190-
public void testCreateGroupConflict() {
190+
void testCreateGroupConflict() {
191191
Mockito.when(keycloakAdminService.createGroup(
192192
Mockito.anyString(),
193193
Mockito.any()
@@ -205,7 +205,7 @@ public void testCreateGroupConflict() {
205205

206206
@Test
207207
@DisplayName("POST /groups returns 400 for invalid body")
208-
public void testCreateGroupInvalidBody() {
208+
void testCreateGroupInvalidBody() {
209209
var body = """
210210
{
211211
"pictureUrl": "http://example.com/pic.jpg"
@@ -218,7 +218,7 @@ public void testCreateGroupInvalidBody() {
218218

219219
@Test
220220
@DisplayName("GET /groups/{id} returns 200 for existing group")
221-
public void testGetGroupSuccess() {
221+
void testGetGroupSuccess() {
222222
var groupRep = new GroupRepresentation();
223223
groupRep.setId("group1");
224224
groupRep.setName("Group 1");
@@ -232,14 +232,14 @@ public void testGetGroupSuccess() {
232232

233233
@Test
234234
@DisplayName("GET /groups/{id} returns 404 for non-existing group")
235-
public void testGetGroupNotFound() {
235+
void testGetGroupNotFound() {
236236
when().get("/groups/nonexistent")
237237
.then().statusCode(404);
238238
}
239239

240240
@Test
241241
@DisplayName("PUT /groups/{id} returns 200 when update successful")
242-
public void testUpdateGroupSuccess() {
242+
void testUpdateGroupSuccess() {
243243
var groupRep = new GroupRepresentation();
244244
groupRep.setId("group1");
245245
groupRep.setName("Updated Group");
@@ -262,7 +262,7 @@ public void testUpdateGroupSuccess() {
262262

263263
@Test
264264
@DisplayName("PUT /groups/{id} returns 404 for non-existing group")
265-
public void testUpdateGroupNotFound() {
265+
void testUpdateGroupNotFound() {
266266
Mockito.when(keycloakAdminService.updateGroup(
267267
Mockito.eq("nonexistent"),
268268
Mockito.any(),
@@ -281,7 +281,7 @@ public void testUpdateGroupNotFound() {
281281

282282
@Test
283283
@DisplayName("DELETE /groups/{id} returns 204 when deleted successfully")
284-
public void testDeleteGroupSuccess() {
284+
void testDeleteGroupSuccess() {
285285
Mockito.doNothing().when(keycloakAdminService).deleteGroup("group2");
286286

287287
when().delete("/groups/group2")
@@ -292,7 +292,7 @@ public void testDeleteGroupSuccess() {
292292

293293
@Test
294294
@DisplayName("DELETE /groups/{id} returns 404 for non-existing group")
295-
public void testDeleteGroupNotFound() {
295+
void testDeleteGroupNotFound() {
296296
Mockito.doThrow(new NotFoundException("Group not found"))
297297
.when(keycloakAdminService).deleteGroup("nonexistent");
298298

@@ -302,7 +302,7 @@ public void testDeleteGroupNotFound() {
302302

303303
@Test
304304
@DisplayName("POST /groups/{groupId}/members/{userId} returns 204 when member added")
305-
public void testAddMemberSuccess() {
305+
void testAddMemberSuccess() {
306306
Mockito.doNothing().when(keycloakAdminService).addUserToGroup("group1", "user2");
307307

308308
when().post("/groups/group1/members/user2")
@@ -313,7 +313,7 @@ public void testAddMemberSuccess() {
313313

314314
@Test
315315
@DisplayName("POST /groups/{groupId}/members/{userId} returns 404 for non-existing group")
316-
public void testAddMemberGroupNotFound() {
316+
void testAddMemberGroupNotFound() {
317317
Mockito.doThrow(new NotFoundException("Group not found"))
318318
.when(keycloakAdminService).addUserToGroup("nonexistent", "user1");
319319

@@ -323,7 +323,7 @@ public void testAddMemberGroupNotFound() {
323323

324324
@Test
325325
@DisplayName("POST /groups/{groupId}/members/{userId} returns 404 for non-existing user")
326-
public void testAddMemberUserNotFound() {
326+
void testAddMemberUserNotFound() {
327327
Mockito.doThrow(new NotFoundException("User not found"))
328328
.when(keycloakAdminService).addUserToGroup("group1", "nonexistent");
329329

@@ -333,7 +333,7 @@ public void testAddMemberUserNotFound() {
333333

334334
@Test
335335
@DisplayName("DELETE /groups/{groupId}/members/{userId} returns 204 when member removed")
336-
public void testRemoveMemberSuccess() {
336+
void testRemoveMemberSuccess() {
337337
Mockito.doNothing().when(keycloakAdminService).removeUserFromGroup("group1", "user1");
338338

339339
when().delete("/groups/group1/members/user1")
@@ -344,7 +344,7 @@ public void testRemoveMemberSuccess() {
344344

345345
@Test
346346
@DisplayName("DELETE /groups/{groupId}/members/{userId} returns 404 for non-existing group")
347-
public void testRemoveMemberGroupNotFound() {
347+
void testRemoveMemberGroupNotFound() {
348348
Mockito.doThrow(new NotFoundException("Group not found"))
349349
.when(keycloakAdminService).removeUserFromGroup("nonexistent", "user1");
350350

@@ -354,7 +354,7 @@ public void testRemoveMemberGroupNotFound() {
354354

355355
@Test
356356
@DisplayName("DELETE /groups/{groupId}/members/{userId} returns 404 for non-existing user")
357-
public void testRemoveMemberUserNotFound() {
357+
void testRemoveMemberUserNotFound() {
358358
Mockito.doThrow(new NotFoundException("User not found"))
359359
.when(keycloakAdminService).removeUserFromGroup("group1", "nonexistent");
360360

backend/src/test/java/org/cryptomator/hub/api/UsersResourceIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.sql.SQLException;
3434
import java.time.Instant;
3535
import java.time.format.DateTimeFormatter;
36-
import java.util.Collections;
3736

3837
import static io.restassured.RestAssured.given;
3938
import static io.restassured.RestAssured.when;
@@ -185,7 +184,7 @@ public class AsAnonymous {
185184
"PUT, /users/me",
186185
"GET, /users"
187186
})
188-
public void testGet(String method, String path) {
187+
void testGet(String method, String path) {
189188
when().request(method, path)
190189
.then().statusCode(401);
191190
}

backend/src/test/java/org/cryptomator/hub/keycloak/KeycloakAuthorityProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Roles {
201201
private RoleResource roleResource2 = Mockito.mock(RoleResource.class);
202202

203203
@BeforeEach
204-
public void setup() {
204+
void setup() {
205205
Mockito.doReturn(rolesResource).when(realm).roles();
206206
Mockito.doReturn(roleResource1).when(rolesResource).get("role1");
207207
Mockito.doReturn(roleResource2).when(rolesResource).get("role2");

0 commit comments

Comments
 (0)