Skip to content

Commit

Permalink
chore: proper implementation for agent access
Browse files Browse the repository at this point in the history
  • Loading branch information
Koufan-De-King committed Oct 4, 2024
1 parent e515622 commit 10143c3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,4 @@ public enum AccessScope {
EXECUTE,
DELETE;

public boolean allowsAction(String action) {
try {
AccessScope requestedAction = AccessScope.valueOf(action);
return this == requestedAction;
} catch (IllegalArgumentException e) {
// Action not allowed
return false;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,6 @@
public class AgentAccess extends BankAccountAccess {

public AgentAccess() {
this.setStatus(AccessStatus.ACTIVE);
}

// Impersonate the account holder to perform an action within the authorized scope
public void impersonate(String action) {
if (this.getStatus() != AccessStatus.ACTIVE) {
throw new IllegalStateException("Access is not active, impersonation is not allowed.");
}
if (this.getScope().allowsAction(action)) {
return;
// Perform the payment logic
} else {
throw new IllegalArgumentException("Action not permitted within the current scope.");
}
}

// Revoke the agent's access
public void revokeAccess() {
this.setStatus(AccessStatus.SUSPENDED);
}

// Activate agent access if it has been suspended
public void activateAccess() {
this.setStatus(AccessStatus.ACTIVE);
}

// Restrict access temporarily without full revocation
public void restrictAccess() {
this.setStatus(AccessStatus.RESTRICTED);
}

// Example usage scenario: Execute a payment on behalf of the account holder
public void executePayment(double amount) {
if (this.getStatus() == AccessStatus.ACTIVE && this.getScope().allowsAction("EXECUTE_PAYMENT")) {
return;
// Perform the payment logic
} else {
throw new IllegalStateException("Payment execution not allowed under the current access status or scope.");
}
super();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package de.adorsys.ledgers.baam.db.repository;

import de.adorsys.ledgers.baam.db.domain.AgentAccess;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import de.adorsys.ledgers.baam.db.domain.AgentAccess;

@Repository
public interface AgentAccessRepository extends JpaRepository<AgentAccess, String> {

Expand Down

0 comments on commit 10143c3

Please sign in to comment.