Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into 28-create-bank-acc…
Browse files Browse the repository at this point in the history
…ount-access-service-api-ledgers-bank-account-access-service-api
  • Loading branch information
nancymuyeh committed Oct 7, 2024
2 parents 8f1fae5 + b3bc4dd commit a6a3a9c
Show file tree
Hide file tree
Showing 30 changed files with 740 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
@RequiredArgsConstructor
public class SwaggerConfig implements WebMvcConfigurer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public enum AccessScope {
WRITE,
EXECUTE,
DELETE;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Entity
@Table(name = "agent_access")
public class AgentAccess extends BankAccountAccess {

public AgentAccess() {
super();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.Table;

@Entity
@Table(name = "auditor_access")
public class AuditorAccess extends BankAccountAccess {

public AuditorAccess() {
super();
this.setStatus(AccessStatus.ACTIVE); // By default, AuditorAccess is active
this.setWeight(1.0); // Weight is always 1 for Auditor Access
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public abstract class BankAccountAccess {

private String policies; // Policies associated with the access

public BankAccountAccess(@NotNull String accountId, @NotNull String entityId) {
this.accountId = accountId;
this.entityId = entityId;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.adorsys.ledgers.baam.db.domain;

/**
* Enum representing different types of consents in the context of open banking.
* These consents define the scope of access granted to third-party service providers.
*/
public enum ConsentType {

/*
* The need to implement Other Open Banking Services may call for the creation of more ConsentTypes
*/

/**
* Consent allowing the third party to access account information such as
* balances, transaction histories, and account details without modifying them.
* This is typically used by Account Information Service Providers (AISP).
*/
ACCOUNT_INFORMATION_CONSENT,

/**
* Consent allowing the third party to initiate payments from the account
* on behalf of the account holder. This is typically used by Payment
* Initiation Service Providers (PISP).
*/
PAYMENT_INITIATION_CONSENT,

/**
* Consent allowing the third party to verify whether the account has
* sufficient funds for a particular transaction. No additional account
* information is provided beyond the confirmation of funds.
*/
CONFIRMATION_OF_FUNDS_CONSENT

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class DelegatedAccess extends BankAccountAccess {

private DelegatedAccessType delegatedType;

public DelegatedAccess() {
super();
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.adorsys.ledgers.baam.db.domain;

/**
* Enum representing different types of Power of Attorney.
*/
public enum DelegatedAccessType {
GENERAL,
LIMITED,
DURABLE,
SPRINGING
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "holder_access")
@Data
@NoArgsConstructor(force = true)
public class HolderAccess extends BankAccountAccess {

// Constructor for creating HolderAccess with full access
public HolderAccess(String entityId, String accountId) {
super();
this.setEntityId(entityId);
this.setAccountId(accountId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;


import java.util.HashSet;
import java.util.Set;


@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ManagerAccess extends BankAccountAccess {


@ElementCollection
private Set<TypeOfManagedAccess> managedAccessTypes = new HashSet<>();

@ElementCollection
private Set<AccessScope> scopeOfAccess = new HashSet<>();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.adorsys.ledgers.baam.db.domain;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "third_party_access")
public class ThirdPartyAccess extends BankAccountAccess {

@Column(name = "consent_type")
@Enumerated(EnumType.STRING)
private ConsentType consentType;

@Column(name = "expiration_date")
private LocalDateTime expirationDate;

@Column(name = "max_transaction_amount")
private Double maxTransactionAmount;

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.adorsys.ledgers.baam.db.domain;

public enum TypeOfManagedAccess {
AGENT_ACCESS,
AUDITOR_ACCESS,
POA_ACCESS;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;

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

}

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> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.adorsys.ledgers.baam.db.repository;

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

import java.util.List;

@Repository
public interface DelegatedAccessRepository extends JpaRepository<DelegatedAccess, String> {

List<DelegatedAccess> findByAccountId(String accountId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2018-2023 adorsys GmbH and Co. KG
* All rights are reserved.
*/

package de.adorsys.ledgers.baam.db.repository;

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

@Repository
public interface HolderAccessRepository extends JpaRepository<HolderAccess, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.adorsys.ledgers.baam.db.repository;


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



@Repository
public interface ManagerAccessRepository extends JpaRepository<ManagerAccess, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.adorsys.ledgers.baam.db.repository;

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

@Repository
public interface ThirdPartyAccessRepository extends JpaRepository<ThirdPartyAccess, String> {

}

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.*;
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.assertNotNull;

@SpringBootTest(classes = BaamRepositoryApplication.class)
@ExtendWith(SpringExtension.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
TransactionalTestExecutionListener.class,
DbUnitTestExecutionListener.class})

public class AgentAccessRepositoryIT {

@Autowired
private AgentAccessRepository agentAccessRepository;

@Test
void test_create_ok() {
// Given
agentAccessRepository.deleteAll(); // Clean up any existing records
AgentAccess agentAccess = new AgentAccess();
agentAccess.setId("1");
agentAccess.setAccountId("1L");
agentAccess.setEntityId("2L");
agentAccess.setScope(AccessScope.EXECUTE); // Example action scope
agentAccess.setWeight(0.5); // Partial authority
agentAccess.setConditions(AccessCondition.AMOUNT_RESTRICTED); // Example condition
agentAccess.setStatus(AccessStatus.ACTIVE); // Agent is active
agentAccess.setPolicies("Payment-Only Policy"); // Example policy

// When
AgentAccess savedAccess = agentAccessRepository.save(agentAccess);

// Retrieve the saved object
AgentAccess result = agentAccessRepository.findById(savedAccess.getId()).orElse(null);

// Then
assertNotNull(result);
}
}
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());
}
}
Loading

0 comments on commit a6a3a9c

Please sign in to comment.