diff --git a/README.md b/README.md index 5434a06..52f12f1 100644 --- a/README.md +++ b/README.md @@ -1 +1,99 @@ -# webank-OnlineBanking \ No newline at end of file +# Webank Online Banking System +### An Online banking system middleware service +## Table of Contents +- [Project Overview](#project-overview) +- [Features](#features) +- [Technologies Used](#technologies-used) +- [Prerequisites](#prerequisites) +- [Installation Instructions](#installation-instructions) +- [Usage](#usage) +- [Project Documentation](#project-documentation) +- [Development and Contribution](#development-and-contribution) +- [License](#license) +- [Contact Information](#contact-information) +- [Acknowledgements](#acknowledgements) + +--- + +## Project Overview + +The **Webank Online Banking System** is a middleware service designed to connect the frontend applications with a core banking system, providing a seamless online banking experience for users. The system consists of various modules to manage key functionalities such as user registration, account management, OTP verification, and access control. + +### Key Modules +- **OBS (Online Banking Service)**: Orchestrates requests for registration and OTP verification, forwarding them to the appropriate backend modules. +- **PRS (Personal Registration Service)**: Manages user registration and OTP verification. +- **DAS (Deposit Account Service)**: Handles account creation and balance management. +- **AAS (Account Access Service)**: Manages account access and authorization. +- **SMS Gateway**: Sends OTPs to users for verification purposes. + +## Features +- **User Registration**: Users can register by providing their phone numbers and public keys. +- **OTP Verification**: Secure one-time passwords are sent to users’ phones to verify identity. +- **Account Management**: Once registration is complete, users can create bank accounts, check balances, and view transaction histories. +- **Scalable Microservices Architecture**: Each service is designed as an independent microservice, allowing for modularity and scalability. + +## Technologies Used +- **Backend**: Spring Boot for the OBS, PRS, DAS, and AAS modules. +- **Database**: PostgreSQL (or any preferred database system) for secure data storage. +- **API Documentation**: OpenAPI for standardized API documentation. +- **Messaging and SMS**: Integrated SMS gateway for OTPs. + +## Prerequisites +- **Java 11+**: Required to run the Spring Boot applications. +- **Maven**: Used for project dependency management. +- **Docker** (optional): For containerization and easier deployment. +- **PostgreSQL**: As the primary database for storing user and account data. + +## Installation Instructions +1. **Clone the Repository**: + ```bash + git clone https://github.com/yourusername/webank-online-banking-system.git + cd webank-online-banking-system + ``` +2. **Run Database Migration**: + - Ensure PostgreSQL is running and create necessary databases and tables (migration scripts are included in the `db/migrations` folder). + +3. **Build and Run Services**: + ```bash + mvn clean install + mvn spring-boot:run + ``` + +5. **Access API Documentation**: + - The OpenAPI documentation will be available at `http://localhost:8080/swagger-ui.html` (or the port specified for each module). + +## Usage +- **User Registration**: + - Make a `POST` request to `/register` with `phoneNumber` and `publicKey`. + - Receive an OTP on the provided phone number. +- **OTP Verification**: + - Verify OTP by making a `POST` request to `/verify-otp` with the OTP and public key. +- **Account Management**: + - Access endpoints for balance inquiries, transfers, and account details. + +For a detailed guide on using each endpoint, refer to the [API Documentation](#project-documentation) section. + +## Project Documentation +The architecture documentation and API specifications are available in the `docs` folder. The documentation includes: +- **Architecture Overview**: Detailed information on how OBS interacts with PRS, DAS, and AAS. +- **API Reference**: List of available endpoints, request payloads, and response formats. +- **Security Considerations**: Overview of authentication and data encryption practices. + +## Development and Contribution +We welcome contributions! Please follow these steps: +1. Fork the repository and create a new branch for your feature or bug fix. +2. Follow our [contribution guidelines](CONTRIBUTING.md) for best practices. +3. Submit a pull request detailing your changes. + +## License +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. + +## Contact Information +For questions or support, please reach out to: +- **Email**: [Adorsys](fpo@adorsys.de) +- **GitHub Issues**: [Submit an issue](https://github.com/ADORSYS-GIS/webank/issues) + +## Acknowledgements +- Thanks to the adorsys development team for their contributions. +- Special thanks to the contributors and libraries that supported this project. +- Special thanks to the development team and contributors for their support and dedication in building this project. diff --git a/obs/obs-rest-api/pom.xml b/obs/obs-rest-api/pom.xml index ea20038..3c3397e 100644 --- a/obs/obs-rest-api/pom.xml +++ b/obs/obs-rest-api/pom.xml @@ -30,18 +30,12 @@ - - io.swagger.core.v3 - swagger-annotations-jakarta - 2.2.22 - compile - + org.springframework.boot spring-boot-starter-web - 3.1.4 compile @@ -49,9 +43,12 @@ org.springframework.boot spring-boot-starter-test - 3.1.4 test + + org.springdoc + springdoc-openapi-starter-webmvc-ui + diff --git a/obs/obs-rest-api/src/main/java/com/adorsys/webank/obs/OBSRestApi.java b/obs/obs-rest-api/src/main/java/com/adorsys/webank/obs/OBSRestApi.java deleted file mode 100644 index 05c44a7..0000000 --- a/obs/obs-rest-api/src/main/java/com/adorsys/webank/obs/OBSRestApi.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.adorsys.webank.obs; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@RequestMapping("/api/obs") -public interface OBSRestApi { - - @GetMapping("/message") - @ResponseBody - String getMessage(); -} - diff --git a/obs/obs-rest-api/src/main/java/com/adorsys/webank/obs/resource/RegistrationResourceApi.java b/obs/obs-rest-api/src/main/java/com/adorsys/webank/obs/resource/RegistrationResourceApi.java new file mode 100644 index 0000000..e42c985 --- /dev/null +++ b/obs/obs-rest-api/src/main/java/com/adorsys/webank/obs/resource/RegistrationResourceApi.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018-2024 adorsys GmbH and Co. KG + * All rights are reserved. + */ + +package com.adorsys.webank.obs.resource; + +import com.adorsys.webank.obs.dto.RegistrationRequest; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + + + +@RestController +@RequestMapping("/api/registration") +public interface RegistrationResourceApi { + + @Operation(summary = "Register a new bank account", description = "Accepts a phone number and public key for registration") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Registration successful"), + @ApiResponse(responseCode = "400", description = "Invalid input") + }) + @PostMapping + ResponseEntity registerAccount( + @RequestBody RegistrationRequest registrationRequest + ); +} diff --git a/obs/obs-rest-server/pom.xml b/obs/obs-rest-server/pom.xml index 7d37d47..9673ba4 100644 --- a/obs/obs-rest-server/pom.xml +++ b/obs/obs-rest-server/pom.xml @@ -32,6 +32,11 @@ org.springframework.boot spring-boot-starter + + org.projectlombok + lombok + provided + com.adorsys.webank obs-service-api @@ -43,7 +48,14 @@ ${project.version} + + + org.springframework.boot + spring-boot-starter-test + test + + - \ No newline at end of file + diff --git a/obs/obs-rest-server/src/main/java/com/adorsys/webank/obs/OBSRestServer.java b/obs/obs-rest-server/src/main/java/com/adorsys/webank/obs/OBSRestServer.java deleted file mode 100644 index 959a2c0..0000000 --- a/obs/obs-rest-server/src/main/java/com/adorsys/webank/obs/OBSRestServer.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.adorsys.webank.obs; - -import org.springframework.web.bind.annotation.RestController; -import org.springframework.beans.factory.annotation.Autowired; - -@RestController -public class OBSRestServer implements OBSRestApi { - - private final OBSServiceApi obsService; - - @Autowired - public OBSRestServer(OBSServiceApi obsService) { - this.obsService = obsService; - } - - @Override - public String getMessage() { - return obsService.getMessage(); - } -} - diff --git a/obs/obs-rest-server/src/main/java/com/adorsys/webank/obs/resource/RegistrationResource.java b/obs/obs-rest-server/src/main/java/com/adorsys/webank/obs/resource/RegistrationResource.java new file mode 100644 index 0000000..fcfff07 --- /dev/null +++ b/obs/obs-rest-server/src/main/java/com/adorsys/webank/obs/resource/RegistrationResource.java @@ -0,0 +1,22 @@ +package com.adorsys.webank.obs.resource; + +import com.adorsys.webank.obs.dto.RegistrationRequest; +import com.adorsys.webank.obs.service.RegistrationServiceApi; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/registration") +public class RegistrationResource implements RegistrationResourceApi { + + @Autowired + private RegistrationServiceApi registrationService; + + @Override + @PostMapping + public ResponseEntity registerAccount(@RequestBody RegistrationRequest registrationRequest) { + String result = registrationService.registerAccount(registrationRequest); + return ResponseEntity.ok(result); + } +} diff --git a/obs/obs-rest-server/src/test/java/com/adorsys/webank/obs/resource/RegistrationResourceTest.java b/obs/obs-rest-server/src/test/java/com/adorsys/webank/obs/resource/RegistrationResourceTest.java new file mode 100644 index 0000000..0c58595 --- /dev/null +++ b/obs/obs-rest-server/src/test/java/com/adorsys/webank/obs/resource/RegistrationResourceTest.java @@ -0,0 +1,46 @@ +package com.adorsys.webank.obs.resource; + +import com.adorsys.webank.obs.dto.RegistrationRequest; +import com.adorsys.webank.obs.service.RegistrationServiceApi; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; + +public class RegistrationResourceTest { + + @InjectMocks + private RegistrationResource registrationResource; // Class under test + + @Mock + private RegistrationServiceApi registrationService; // Mocked dependency + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void registerAccount_ShouldReturnSuccessfulResponse() { + // Arrange + RegistrationRequest registrationRequest = new RegistrationRequest(); + registrationRequest.setPhoneNumber(1234567890); + registrationRequest.setPublicKey("testPublicKey"); + + String expectedResponse = "Registration successful"; + when(registrationService.registerAccount(registrationRequest)).thenReturn(expectedResponse); + + // Act + ResponseEntity responseEntity = registrationResource.registerAccount(registrationRequest); + + // Assert + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertEquals(expectedResponse, responseEntity.getBody()); + } +} diff --git a/obs/obs-service-api/pom.xml b/obs/obs-service-api/pom.xml index 8293b67..4fdabe0 100644 --- a/obs/obs-service-api/pom.xml +++ b/obs/obs-service-api/pom.xml @@ -36,6 +36,7 @@ spring-cloud-starter-openfeign + diff --git a/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/OBSServiceApi.java b/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/OBSServiceApi.java deleted file mode 100644 index 06998b6..0000000 --- a/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/OBSServiceApi.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.adorsys.webank.obs; - -public interface OBSServiceApi { - String getMessage(); -} - diff --git a/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/dto/RegistrationRequest.java b/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/dto/RegistrationRequest.java new file mode 100644 index 0000000..31b56c5 --- /dev/null +++ b/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/dto/RegistrationRequest.java @@ -0,0 +1,25 @@ +package com.adorsys.webank.obs.dto; + +public class RegistrationRequest { + + private int phoneNumber; + private String publicKey; + + // Getters and Setters + + public int getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(int phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getPublicKey() { + return publicKey; + } + + public void setPublicKey(String publicKey) { + this.publicKey = publicKey; + } +} diff --git a/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/service/RegistrationServiceApi.java b/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/service/RegistrationServiceApi.java new file mode 100644 index 0000000..2a8302b --- /dev/null +++ b/obs/obs-service-api/src/main/java/com/adorsys/webank/obs/service/RegistrationServiceApi.java @@ -0,0 +1,7 @@ +package com.adorsys.webank.obs.service; + +import com.adorsys.webank.obs.dto.RegistrationRequest; + +public interface RegistrationServiceApi { + String registerAccount(RegistrationRequest registrationRequest); +} diff --git a/obs/obs-service-impl/pom.xml b/obs/obs-service-impl/pom.xml index c5b2995..770d2ed 100644 --- a/obs/obs-service-impl/pom.xml +++ b/obs/obs-service-impl/pom.xml @@ -52,6 +52,7 @@ test + diff --git a/obs/obs-service-impl/src/main/java/com/adorsys/webank/obs/OBSServiceImpl.java b/obs/obs-service-impl/src/main/java/com/adorsys/webank/obs/OBSServiceImpl.java deleted file mode 100644 index 25db33f..0000000 --- a/obs/obs-service-impl/src/main/java/com/adorsys/webank/obs/OBSServiceImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.adorsys.webank.obs; - -import org.springframework.stereotype.Service; - -@Service -public class OBSServiceImpl implements OBSServiceApi { - - @Override - public String getMessage() { - return "Hello from the OBS Service!"; - } -} diff --git a/obs/obs-service-impl/src/main/java/com/adorsys/webank/obs/serviceimpl/RegistrationServiceImpl.java b/obs/obs-service-impl/src/main/java/com/adorsys/webank/obs/serviceimpl/RegistrationServiceImpl.java new file mode 100644 index 0000000..ebcc90c --- /dev/null +++ b/obs/obs-service-impl/src/main/java/com/adorsys/webank/obs/serviceimpl/RegistrationServiceImpl.java @@ -0,0 +1,19 @@ +package com.adorsys.webank.obs.serviceimpl; + +import com.adorsys.webank.obs.dto.RegistrationRequest; +import com.adorsys.webank.obs.service.RegistrationServiceApi; +import org.springframework.stereotype.Service; + +@Service +public class RegistrationServiceImpl implements RegistrationServiceApi { + + @Override + public String registerAccount(RegistrationRequest registrationRequest) { + int phoneNumber = registrationRequest.getPhoneNumber(); + String publicKey = registrationRequest.getPublicKey(); + + // Add logic for registering the account with phoneNumber and publicKey + + return "Registration successful for phone number: " + phoneNumber; // Return message including the phone number + } +} diff --git a/obs/obs-service-impl/src/test/java/com/adorsys/webank/obs/serviceimpl/RegistrationServiceImplTest.java b/obs/obs-service-impl/src/test/java/com/adorsys/webank/obs/serviceimpl/RegistrationServiceImplTest.java new file mode 100644 index 0000000..dbac4da --- /dev/null +++ b/obs/obs-service-impl/src/test/java/com/adorsys/webank/obs/serviceimpl/RegistrationServiceImplTest.java @@ -0,0 +1,33 @@ +package com.adorsys.webank.obs.serviceimpl; + +import com.adorsys.webank.obs.dto.RegistrationRequest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class RegistrationServiceImplTest { + + private RegistrationServiceImpl registrationService; + + @BeforeEach + void setUp() { + registrationService = new RegistrationServiceImpl(); + } + + @Test + void registerAccount_ShouldReturnSuccessMessageWithPhoneNumber_WhenGivenValidInput() { + // Arrange + RegistrationRequest request = new RegistrationRequest(); + int testPhoneNumber = 123456789; // Set a valid phone number + request.setPhoneNumber(testPhoneNumber); + request.setPublicKey("validPublicKey"); // Set a valid public key + + // Act + String result = registrationService.registerAccount(request); + + // Assert + assertEquals("Registration successful for phone number: " + testPhoneNumber, result); + } + + // You can add more tests here for edge cases, invalid input, etc. +} diff --git a/online-banking-app/pom.xml b/online-banking-app/pom.xml index 40ce7d8..8b5c286 100644 --- a/online-banking-app/pom.xml +++ b/online-banking-app/pom.xml @@ -3,12 +3,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.3.4 - + com.adorsys.webank + webank-OnlineBanking + 0.1-SNAPSHOT - com.adorsys.webank + online-banking-app 0.1-SNAPSHOT online-banking-app @@ -61,6 +60,19 @@ spring-boot-starter-web + + org.springdoc + springdoc-openapi-starter-webmvc-ui + + + + com.h2database + h2 + runtime + + + + org.projectlombok lombok diff --git a/online-banking-app/src/main/java/com/adorsys/webank/OnlineBankingApplication.java b/online-banking-app/src/main/java/com/adorsys/webank/OnlineBankingApplication.java index 9fb7318..caca0f0 100644 --- a/online-banking-app/src/main/java/com/adorsys/webank/OnlineBankingApplication.java +++ b/online-banking-app/src/main/java/com/adorsys/webank/OnlineBankingApplication.java @@ -2,12 +2,11 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication(exclude = {org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration.class, - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class}) + +@SpringBootApplication public class OnlineBankingApplication { public static void main(String[] args) { SpringApplication.run(OnlineBankingApplication.class, args); } - } diff --git a/online-banking-app/src/main/resources/application.properties b/online-banking-app/src/main/resources/application.properties new file mode 100644 index 0000000..ba24bfd --- /dev/null +++ b/online-banking-app/src/main/resources/application.properties @@ -0,0 +1,10 @@ +# Swagger UI URL +springdoc.api-docs.path=/v3/api-docs +springdoc.swagger-ui.path=/swagger-ui.html +springdoc.swagger-ui.enabled=true + +#h2 database +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driver-class-name=org.h2.Driver +spring.h2.console.enabled=true # Optional: Enables H2 console for easier testing +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration