-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: created and tested auditor access entity
- Loading branch information
1 parent
4736e14
commit e0e6964
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ount-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/AuditorAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.adorsys.ledgers.baam.db.domain; | ||
|
||
import jakarta.persistence.*; | ||
import java.util.logging.Logger; | ||
|
||
@Entity | ||
@Table(name = "auditor_access") | ||
public class AuditorAccess extends BankAccountAccess { | ||
private static final Logger logger = Logger.getLogger(AuditorAccess.class.getName()); | ||
|
||
// Constructor sets default values | ||
public AuditorAccess() { | ||
this.setStatus(AccessStatus.ACTIVE); // By default, AuditorAccess is active | ||
this.setWeight(1.0); // Weight is always 1 for AuditorAccess | ||
logger.info("AuditorAccess created with default active status and weight of 1"); | ||
} | ||
|
||
public boolean allowsAction(String action) { | ||
// Only allow read actions such as viewing transactions and balances | ||
return switch (action) { | ||
case "VIEW_ACCOUNT_BALANCES", "VIEW_TRANSACTION_HISTORY", "VIEW_ACCESS_LOGS" -> true; | ||
default -> false; // No modifications are allowed | ||
}; | ||
} | ||
|
||
// Overriding status management to ensure that AuditorAccess can be restricted or suspended | ||
public void suspendAccess() { | ||
this.setStatus(AccessStatus.SUSPENDED); | ||
logger.info("AuditorAccess has been suspended."); | ||
} | ||
|
||
public void activateAccess() { | ||
this.setStatus(AccessStatus.ACTIVE); | ||
logger.info("AuditorAccess has been reactivated."); | ||
} | ||
|
||
public void restrictAccess() { | ||
this.setStatus(AccessStatus.RESTRICTED); | ||
logger.info("AuditorAccess has been restricted."); | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
...pository/src/main/java/de/adorsys/ledgers/baam/db/repository/AuditorAccessRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.adorsys.ledgers.baam.db.repository; | ||
|
||
import de.adorsys.ledgers.baam.db.domain.AuditorAccess; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface AuditorAccessRepository extends JpaRepository<AuditorAccess, String> { | ||
// Additional query methods can be added here if necessary | ||
} |
51 changes: 51 additions & 0 deletions
51
...sitory/src/test/java/de/adorsys/ledgers/baam/db/repository/AuditorAccessRepositoryIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package de.adorsys.ledgers.baam.db.repository; | ||
|
||
import com.github.springtestdbunit.DbUnitTestExecutionListener; | ||
import de.adorsys.ledgers.baam.db.domain.AccessStatus; | ||
import de.adorsys.ledgers.baam.db.domain.AuditorAccess; | ||
import de.adorsys.ledgers.baam.db.test.BaamRepositoryApplication; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.TestExecutionListeners; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; | ||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@SpringBootTest(classes = BaamRepositoryApplication.class) | ||
@ExtendWith(SpringExtension.class) | ||
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, | ||
TransactionalTestExecutionListener.class, | ||
DbUnitTestExecutionListener.class}) | ||
public class AuditorAccessRepositoryIT { | ||
|
||
@Autowired | ||
private AuditorAccessRepository auditorAccessRepository; | ||
|
||
@Test | ||
void test_createAuditorAccess_ok() { | ||
// Given | ||
auditorAccessRepository.deleteAll(); // Clean up any existing records | ||
|
||
AuditorAccess auditorAccess = new AuditorAccess(); | ||
auditorAccess.setId("1"); | ||
auditorAccess.setAccountId("100L"); | ||
auditorAccess.setEntityId("200L"); | ||
auditorAccess.setStatus(AccessStatus.ACTIVE); // Setting status explicitly | ||
|
||
// When | ||
AuditorAccess savedAccess = auditorAccessRepository.save(auditorAccess); | ||
|
||
// Retrieve the saved object | ||
AuditorAccess result = auditorAccessRepository.findById(savedAccess.getId()).orElse(null); | ||
|
||
// Then | ||
assertNotNull(result); | ||
assertEquals("100L", result.getAccountId()); | ||
assertEquals(AccessStatus.ACTIVE, result.getStatus()); | ||
} | ||
} |