Skip to content

Commit

Permalink
Refactor constants and enums
Browse files Browse the repository at this point in the history
  • Loading branch information
pvannierop committed Jun 3, 2024
1 parent 0e11b75 commit 750b7f5
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 138 deletions.
20 changes: 0 additions & 20 deletions src/main/java/org/radarbase/appserver/config/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,4 @@ AuthAspect getAuthAspect(
return new AuthAspect<>(authValidator, authorization);
}

public interface AuthEntities {
String MEASUREMENT = "MEASUREMENT";
String PROJECT = "PROJECT";
String SUBJECT = "SUBJECT";
String SOURCE = "SOURCE";
}

public interface AuthPermissions {
String READ = "READ";
String CREATE = "CREATE";
String UPDATE = "UPDATE";
String UPLOAD = "UPLOAD";
}

public enum AuthPermission {
READ,
CREATE,
UPDATE,
UPLOAD
}
}
18 changes: 18 additions & 0 deletions src/main/java/org/radarbase/appserver/config/AuthEntities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.radarbase.appserver.config;

public enum AuthEntities {
MEASUREMENT(Constants.MEASUREMENT),
PROJECT(Constants.PROJECT),
SUBJECT(Constants.SUBJECT),
SOURCE(Constants.SOURCE);

AuthEntities(String entityValue) {
}

public static class Constants {
public static final String MEASUREMENT = "MEASUREMENT";
public static final String PROJECT = "PROJECT";
public static final String SUBJECT = "SUBJECT";
public static final String SOURCE = "SOURCE";
}
}
18 changes: 18 additions & 0 deletions src/main/java/org/radarbase/appserver/config/AuthPermission.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.radarbase.appserver.config;

public enum AuthPermission {
READ(Constants.READ),
CREATE(Constants.CREATE),
UPDATE(Constants.UPDATE),
UPLOAD(Constants.UPLOAD);

AuthPermission(String permissionValue) {
}

public static class Constants {
public static final String READ = "READ";
public static final String CREATE = "CREATE";
public static final String UPDATE = "UPDATE";
public static final String UPLOAD = "UPLOAD";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.radarbase.appserver.config;

import org.radarbase.appserver.config.AuthConfig.AuthPermission;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.net.URISyntaxException;
import java.time.LocalDateTime;
import jakarta.validation.Valid;
import org.radarbase.appserver.config.AuthConfig.AuthEntities;
import org.radarbase.appserver.config.AuthConfig.AuthPermissions;
import org.radarbase.appserver.config.AuthEntities;
import org.radarbase.appserver.config.AuthPermission;
import org.radarbase.appserver.dto.fcm.FcmDataMessageDto;
import org.radarbase.appserver.dto.fcm.FcmDataMessages;
import org.radarbase.appserver.service.FcmDataMessageService;
Expand Down Expand Up @@ -59,20 +59,20 @@ public FcmDataMessageController(FcmDataMessageService dataMessageService) {
}

@GetMapping("/" + PathsUtil.MESSAGING_DATA_PATH)
@Authorized(permission = AuthPermissions.READ, entity = AuthEntities.PROJECT)
@Authorized(permission = AuthPermission.Constants.READ, entity = AuthEntities.Constants.PROJECT)
public ResponseEntity<FcmDataMessages> getAllDataMessages() {
return ResponseEntity.ok(this.dataMessageService.getAllDataMessages());
}

@Authorized(permission = AuthPermissions.READ, entity = AuthEntities.SUBJECT)
@Authorized(permission = AuthPermission.Constants.READ, entity = AuthEntities.Constants.SUBJECT)
@GetMapping("/" + PathsUtil.MESSAGING_DATA_PATH + "/{id}")
public ResponseEntity<FcmDataMessageDto> getDataMessageUsingId(@Valid @PathVariable Long id) {
return ResponseEntity.ok(this.dataMessageService.getDataMessageById(id));
}

// TODO: get notifications/data messages based on other params. Maybe use projections ?
@GetMapping("/" + PathsUtil.MESSAGING_DATA_PATH + "/filtered")
@Authorized(permission = AuthPermissions.READ, entity = AuthEntities.PROJECT)
@Authorized(permission = AuthPermission.Constants.READ, entity = AuthEntities.Constants.PROJECT)
public ResponseEntity<FcmDataMessages> getFilteredDataMessages(
@Valid @RequestParam(value = "type", required = false) String type,
@Valid @RequestParam(value = "delivered", required = false) boolean delivered,
Expand All @@ -86,8 +86,8 @@ public ResponseEntity<FcmDataMessages> getFilteredDataMessages(
}

@Authorized(
permission = AuthPermissions.READ,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.READ,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@GetMapping(
value =
Expand All @@ -108,8 +108,8 @@ public ResponseEntity<FcmDataMessages> getDataMessagesUsingProjectIdAndSubjectId
}

@Authorized(
permission = AuthPermissions.READ,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.READ,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.PROJECT)
@GetMapping(
"/"
Expand All @@ -124,8 +124,8 @@ public ResponseEntity<FcmDataMessages> getDataMessagesUsingProjectId(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PostMapping(
"/"
Expand All @@ -151,8 +151,8 @@ public ResponseEntity<FcmDataMessageDto> addSingleDataMessage(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PostMapping(
"/"
Expand All @@ -175,8 +175,8 @@ public ResponseEntity<FcmDataMessages> addBatchDataMessages(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PutMapping(
"/"
Expand All @@ -199,8 +199,8 @@ public ResponseEntity<FcmDataMessageDto> updateDataMessage(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@DeleteMapping(
"/"
Expand All @@ -223,8 +223,8 @@ public ResponseEntity deleteDataMessagesForUser(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@DeleteMapping(
"/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.net.URISyntaxException;
import java.time.LocalDateTime;
import jakarta.validation.Valid;
import org.radarbase.appserver.config.AuthConfig.AuthEntities;
import org.radarbase.appserver.config.AuthConfig.AuthPermissions;
import org.radarbase.appserver.config.AuthEntities;
import org.radarbase.appserver.config.AuthPermission;
import org.radarbase.appserver.dto.fcm.FcmNotificationDto;
import org.radarbase.appserver.dto.fcm.FcmNotifications;
import org.radarbase.appserver.service.FcmNotificationService;
Expand Down Expand Up @@ -58,19 +58,19 @@ public FcmNotificationController(FcmNotificationService notificationService) {
this.notificationService = notificationService;
}

@Authorized(permission = AuthPermissions.READ, entity = AuthEntities.PROJECT)
@Authorized(permission = AuthPermission.Constants.READ, entity = AuthEntities.Constants.PROJECT)
@GetMapping("/" + PathsUtil.MESSAGING_NOTIFICATION_PATH)
public ResponseEntity<FcmNotifications> getAllNotifications() {
return ResponseEntity.ok(this.notificationService.getAllNotifications());
}

@Authorized(permission = AuthPermissions.UPDATE, entity = AuthEntities.SUBJECT)
@Authorized(permission = AuthPermission.Constants.UPDATE, entity = AuthEntities.Constants.SUBJECT)
@GetMapping("/" + PathsUtil.MESSAGING_NOTIFICATION_PATH + "/{id}")
public ResponseEntity<FcmNotificationDto> getNotificationUsingId(@Valid @PathVariable Long id) {
return ResponseEntity.ok(this.notificationService.getNotificationById(id));
}
// TODO: get notifications based on other params. Maybe use projections ?
@Authorized(permission = AuthPermissions.READ, entity = AuthEntities.PROJECT)
@Authorized(permission = AuthPermission.Constants.READ, entity = AuthEntities.Constants.PROJECT)
@GetMapping("/" + PathsUtil.MESSAGING_NOTIFICATION_PATH + "/filtered")
public ResponseEntity<FcmNotifications> getFilteredNotifications(
@Valid @RequestParam(value = "type", required = false) String type,
Expand All @@ -85,8 +85,8 @@ public ResponseEntity<FcmNotifications> getFilteredNotifications(
}

@Authorized(
permission = AuthPermissions.READ,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.READ,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@GetMapping(
value =
Expand All @@ -107,8 +107,8 @@ public ResponseEntity<FcmNotifications> getNotificationsUsingProjectIdAndSubject
}

@Authorized(
permission = AuthPermissions.READ,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.READ,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.PROJECT)
@GetMapping(
"/"
Expand All @@ -123,8 +123,8 @@ public ResponseEntity<FcmNotifications> getNotificationsUsingProjectId(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PostMapping(
"/"
Expand All @@ -151,8 +151,8 @@ public ResponseEntity<FcmNotificationDto> addSingleNotification(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PostMapping(
"/"
Expand All @@ -175,8 +175,8 @@ public ResponseEntity<FcmNotifications> scheduleUserNotifications(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PostMapping(
"/"
Expand All @@ -202,8 +202,8 @@ public ResponseEntity<FcmNotificationDto> scheduleUserNotification(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PostMapping(
"/"
Expand All @@ -227,8 +227,8 @@ public ResponseEntity<FcmNotifications> addBatchNotifications(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PutMapping(
"/"
Expand All @@ -251,8 +251,8 @@ public ResponseEntity<FcmNotificationDto> updateNotification(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@DeleteMapping(
"/"
Expand All @@ -275,8 +275,8 @@ public ResponseEntity deleteNotificationsForUser(
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@DeleteMapping(
"/"
Expand All @@ -300,8 +300,8 @@ public ResponseEntity deleteNotificationUsingProjectIdAndSubjectIdAndNotificatio
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermission.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@DeleteMapping(
"/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

package org.radarbase.appserver.controller;

import org.radarbase.appserver.config.AuthConfig;
import org.radarbase.appserver.config.AuthEntities;
import org.radarbase.appserver.config.AuthPermission;
import org.radarbase.appserver.service.GithubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand All @@ -46,8 +47,8 @@ public GithubEndpoint(GithubService githubService) {
}

@Authorized(
permission = AuthConfig.AuthPermissions.READ,
entity = AuthConfig.AuthEntities.SUBJECT)
permission = AuthPermission.Constants.READ,
entity = AuthEntities.Constants.SUBJECT)
@GetMapping("/" +
PathsUtil.GITHUB_PATH
+ "/" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import java.util.List;
import javax.naming.SizeLimitExceededException;
import org.radarbase.appserver.config.AuthConfig.AuthEntities;
import org.radarbase.appserver.config.AuthConfig.AuthPermissions;
import org.radarbase.appserver.config.AuthEntities;
import org.radarbase.appserver.config.AuthPermission;
import org.radarbase.appserver.dto.NotificationStateEventDto;
import org.radarbase.appserver.service.NotificationStateEventService;
import org.springframework.http.ResponseEntity;
Expand All @@ -48,7 +48,7 @@ public NotificationStateEventController(
this.notificationStateEventService = notificationStateEventService;
}

@Authorized(permission = AuthPermissions.READ, entity = AuthEntities.PROJECT)
@Authorized(permission = AuthPermissions.Constants.READ, entity = AuthEntities.Constants.PROJECT)
@GetMapping(
value =
"/"
Expand All @@ -64,8 +64,8 @@ public ResponseEntity<List<NotificationStateEventDto>> getNotificationStateEvent
}

@Authorized(
permission = AuthPermissions.READ,
entity = AuthEntities.SUBJECT,
permission = AuthPermissions.Constants.READ,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@GetMapping(
value =
Expand Down Expand Up @@ -93,8 +93,8 @@ public ResponseEntity<List<NotificationStateEventDto>> getNotificationStateEvent
}

@Authorized(
permission = AuthPermissions.UPDATE,
entity = AuthEntities.SUBJECT,
permission = AuthPermissions.Constants.UPDATE,
entity = AuthEntities.Constants.SUBJECT,
permissionOn = PermissionOn.SUBJECT)
@PostMapping(
value =
Expand Down
Loading

0 comments on commit 750b7f5

Please sign in to comment.