refactor: 백엔드 리펙토링 진행 중

This commit is contained in:
DongHyeonka
2026-09-25 17:57:07 +09:00
parent fe80bb3ff3
commit fcddab7e2a
7518 changed files with 3217541 additions and 21259 deletions
@@ -34,13 +34,32 @@ public final class AdminAuthorizationGuard {
* Require that the actor may act on a tenant.
*
* <p>An actor with no tenant is a global operator; one bound to a tenant may only act inside it.
*
* @param authority the authority being exercised, which the refusal names; it used to name {@code
* SUPPRESS} whatever the operation was
*/
public void requireTenant(AdminActor actor, TenantId tenantId) {
public void requireTenant(
AdminActor actor, TenantId tenantId, NotificationAdminAuthority authority) {
Objects.requireNonNull(actor, "actor");
Objects.requireNonNull(tenantId, "tenantId");
Objects.requireNonNull(authority, "authority");
Optional<TenantId> scope = actor.tenantId();
if (scope.isPresent() && !scope.get().equals(tenantId)) {
throw new AdminAccessDeniedException(NotificationAdminAuthority.SUPPRESS);
throw new AdminAccessDeniedException(authority);
}
}
/**
* Require a global operator.
*
* <p>For state every tenant shares — a provider runtime serves all of them — a tenant-bound actor
* holding the authority would still be acting outside its tenant.
*/
public void requireGlobal(AdminActor actor, NotificationAdminAuthority authority) {
Objects.requireNonNull(actor, "actor");
Objects.requireNonNull(authority, "authority");
if (actor.tenantId().isPresent()) {
throw new AdminAccessDeniedException(authority);
}
}
}
@@ -102,7 +102,7 @@ public final class NotificationAdminApplicationService implements NotificationAd
attempts
.snapshot(command.attemptId())
.orElseThrow(() -> new IllegalStateException("delivery attempt is not available"));
authorization.requireTenant(actor, original.tenantId());
authorization.requireTenant(actor, original.tenantId(), NotificationAdminAuthority.REDRIVE);
duplicateRiskGuard.verify(original, command.approveDuplicateRisk());
if (command.dryRun()) {
@@ -156,6 +156,16 @@ public final class NotificationAdminApplicationService implements NotificationAd
public AdminOperationResult reconcile(ReconcileCommand command, AdminActor actor) {
Objects.requireNonNull(command, "command");
authorization.require(actor, NotificationAdminAuthority.RECONCILE);
// Every attempt is checked before any is touched, so a batch with one foreign id changes none.
// An id with no attempt behind it is left to reconciliation, which does nothing with it.
for (DeliveryAttemptId attemptId : command.attemptIds()) {
attempts
.snapshot(attemptId)
.ifPresent(
attempt ->
authorization.requireTenant(
actor, attempt.tenantId(), NotificationAdminAuthority.RECONCILE));
}
if (command.dryRun()) {
return new AdminOperationResult(
@@ -207,7 +217,7 @@ public final class NotificationAdminApplicationService implements NotificationAd
public AdminOperationResult suppress(SuppressCommand command, AdminActor actor) {
Objects.requireNonNull(command, "command");
authorization.require(actor, NotificationAdminAuthority.SUPPRESS);
authorization.requireTenant(actor, command.tenantId());
authorization.requireTenant(actor, command.tenantId(), NotificationAdminAuthority.SUPPRESS);
if (command.dryRun()) {
return new AdminOperationResult(
@@ -287,6 +297,7 @@ public final class NotificationAdminApplicationService implements NotificationAd
public AdminOperationResult setProviderState(SetProviderStateCommand command, AdminActor actor) {
Objects.requireNonNull(command, "command");
authorization.require(actor, NotificationAdminAuthority.PROVIDER_CONTROL);
authorization.requireGlobal(actor, NotificationAdminAuthority.PROVIDER_CONTROL);
if (command.dryRun()) {
return new AdminOperationResult(
@@ -12,7 +12,6 @@ public enum SecretPurpose {
CONTACT_LOOKUP_HMAC,
CALLBACK_SIGNING,
PROVIDER_CREDENTIAL,
VAPID_SIGNING,
PAYLOAD_ENCRYPTION,
/**
@@ -31,9 +31,15 @@ class AdminAuthorizationGuardTest {
Set.of(NotificationAdminAuthority.SUPPRESS),
Optional.of(new TenantId("tenant-a")));
assertThatCode(() -> guard.requireTenant(actor, new TenantId("tenant-a")))
assertThatCode(
() ->
guard.requireTenant(
actor, new TenantId("tenant-a"), NotificationAdminAuthority.SUPPRESS))
.doesNotThrowAnyException();
assertThatThrownBy(() -> guard.requireTenant(actor, new TenantId("tenant-b")))
assertThatThrownBy(
() ->
guard.requireTenant(
actor, new TenantId("tenant-b"), NotificationAdminAuthority.SUPPRESS))
.isInstanceOf(AdminAccessDeniedException.class);
}
@@ -43,7 +49,10 @@ class AdminAuthorizationGuardTest {
new AdminActor(
"global-operator", Set.of(NotificationAdminAuthority.SUPPRESS), Optional.empty());
assertThatCode(() -> guard.requireTenant(global, new TenantId("tenant-b")))
assertThatCode(
() ->
guard.requireTenant(
global, new TenantId("tenant-b"), NotificationAdminAuthority.SUPPRESS))
.doesNotThrowAnyException();
}
}
@@ -1,8 +1,21 @@
package dev.caskeleton.application.notification.platform.admin;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import dev.caskeleton.application.notification.platform.api.ContactPointId;
import dev.caskeleton.application.notification.platform.api.DeliveryAttemptId;
import dev.caskeleton.application.notification.platform.api.NotificationId;
import dev.caskeleton.application.notification.platform.api.ProviderId;
import dev.caskeleton.application.notification.platform.api.ProviderProfileId;
import dev.caskeleton.application.notification.platform.api.RecipientDeliveryId;
import dev.caskeleton.application.notification.platform.api.TenantId;
import dev.caskeleton.application.notification.platform.api.delivery.AttemptConfirmation;
import dev.caskeleton.application.notification.platform.api.delivery.DeliveryOutcome;
import dev.caskeleton.application.notification.platform.api.delivery.EvidenceLevel;
import dev.caskeleton.application.notification.platform.api.delivery.SubmissionOutcome;
import dev.caskeleton.application.notification.platform.api.routing.Channel;
import dev.caskeleton.application.notification.platform.callback.DeliveryAttemptSnapshot;
import dev.caskeleton.application.notification.platform.dispatch.NotificationPlatformNoops;
import dev.caskeleton.application.notification.platform.dispatch.PlatformFakes;
import dev.caskeleton.application.notification.platform.observation.NotificationAuditEvent;
@@ -18,6 +31,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class NotificationAdminApplicationServiceTest {
@@ -71,6 +86,85 @@ class NotificationAdminApplicationServiceTest {
assertThat(fixture.runtime.calls).isZero();
}
@Test
@DisplayName("tenant 범위 운영자는 다른 tenant의 attempt를 reconcile할 수 없다")
void aTenantScopedOperatorCannotReconcileAnotherTenantsAttempt() {
// given
Fixture fixture = new Fixture();
DeliveryAttemptSnapshot foreign = attemptOf(new TenantId("tenant-a"));
fixture.attempts.snapshots.put(foreign.attemptId(), foreign);
AdminActor tenantB =
new AdminActor(
"operator-b",
Set.of(NotificationAdminAuthority.RECONCILE),
Optional.of(new TenantId("tenant-b")));
ReconcileCommand command =
new ReconcileCommand("op-r", List.of(foreign.attemptId()), "stuck attempt", false);
// when
Throwable failure = catchThrowable(() -> fixture.service.reconcile(command, tenantB));
// then
assertThat(failure)
.isInstanceOfSatisfying(
AdminAccessDeniedException.class,
denied ->
assertThat(denied.required()).isEqualTo(NotificationAdminAuthority.RECONCILE));
}
@Test
@DisplayName("tenant 범위 운영자는 모든 tenant가 공유하는 provider 상태를 바꿀 수 없다")
void aTenantScopedOperatorCannotChangeAGlobalProviderState() {
// given
Fixture fixture = new Fixture();
AdminActor tenantB =
new AdminActor(
"operator-b",
Set.of(NotificationAdminAuthority.PROVIDER_CONTROL),
Optional.of(new TenantId("tenant-b")));
SetProviderStateCommand command =
new SetProviderStateCommand(
"op-p",
new ProviderProfileId("ses-primary"),
ProviderRuntimeState.DISABLED,
"tenant wants it off",
false);
// when
Throwable failure = catchThrowable(() -> fixture.service.setProviderState(command, tenantB));
// then
assertThat(failure)
.isInstanceOfSatisfying(
AdminAccessDeniedException.class,
denied ->
assertThat(denied.required())
.isEqualTo(NotificationAdminAuthority.PROVIDER_CONTROL));
}
private static DeliveryAttemptSnapshot attemptOf(TenantId tenantId) {
return new DeliveryAttemptSnapshot(
new DeliveryAttemptId(UUID.fromString("00000000-0000-7000-8000-000000000011")),
new RecipientDeliveryId(UUID.fromString("00000000-0000-7000-8000-000000000012")),
new NotificationId(UUID.fromString("00000000-0000-7000-8000-000000000013")),
tenantId,
1,
Channel.EMAIL,
new ProviderId("ses"),
new ProviderProfileId("ses-primary"),
Optional.empty(),
new ContactPointId(UUID.fromString("00000000-0000-7000-8000-000000000014")),
AttemptConfirmation.AMBIGUOUS,
SubmissionOutcome.AMBIGUOUS,
DeliveryOutcome.UNKNOWN,
EvidenceLevel.PLATFORM_QUEUED,
1L,
"a".repeat(64),
CLOCK.instant(),
Optional.empty(),
Optional.empty());
}
private static final class Fixture {
private final PlatformFakes.AttemptStore attempts = new PlatformFakes.AttemptStore();
private final PlatformFakes.RequestStore requests = new PlatformFakes.RequestStore();