Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Java CI
on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '23'
distribution: 'temurin'
- name: Build with Maven
run: mvn --batch-mode --update-snapshots package
90 changes: 90 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*
replay_pid*

##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

##############################
## Gradle
##############################
bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar

##############################
## IntelliJ
##############################
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws

##############################
## Eclipse
##############################
.settings/
bin/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath

##############################
## NetBeans
##############################
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

##############################
## Visual Studio Code
##############################
.vscode/
.code-workspace

##############################
## OS X
##############################
.DS_Store

##############################
## Miscellaneous
##############################
*.log
72 changes: 72 additions & 0 deletions API-Gateway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.bank</groupId>
<artifactId>bank-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>API-Gateway</artifactId>

<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.12.6</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.12.6</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.19.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.19.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.19.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.4.4</version>
</dependency>
<dependency>
<groupId>org.bank</groupId>
<artifactId>bank-infrastructure</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.gateway.application.filters;

import org.gateway.application.services.JwtServices;
import org.gateway.application.services.UserDetailsServiceImpl;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.lang.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

@Component
@RequiredArgsConstructor
public class JwtAuthFilter extends OncePerRequestFilter {

private final JwtServices jwtService;
private final UserDetailsServiceImpl userDetailsService;

@Override
protected void doFilterInternal(@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull FilterChain chain)
throws IOException, ServletException {
final String authHeader = extractToken(request);
final String jwt;
final String login;

if (authHeader == null || !authHeader.startsWith("Bearer ")) {
chain.doFilter(request, response);
return;
}

jwt = authHeader.substring(7);
login = jwtService.extractLogin(jwt);

if (login != null && SecurityContextHolder.getContext().getAuthentication() == null) {
UserDetails userDetails = userDetailsService.loadUserByUsername(login);

if (jwtService.isTokenValid(jwt, userDetails)) {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
userDetails, jwt,
userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));

SecurityContextHolder.getContext().setAuthentication(authentication);
}
}

chain.doFilter(request, response);
}

private String extractToken(HttpServletRequest request) {
String header = request.getHeader("Authorization");
return header != null && header.startsWith("Bearer ") ? header : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.gateway.application.interfaces;

import org.gateway.infrastructure.DTO.GatewayAccountDTO;
import org.gateway.infrastructure.DTO.GatewayUserDTO;
import org.gateway.infrastructure.requestEntities.CreateUserRequest;
import org.springframework.security.core.Authentication;

import java.util.List;

public interface AdminApi {

void createClient(CreateUserRequest clientRequest, String password, Authentication auth);

List<GatewayUserDTO> getAllUsers(Authentication auth);

List<GatewayUserDTO> getAllUsersGenderFilter(String gender, Authentication auth);

List<GatewayUserDTO> getAllUsersHairColorFilter(String hairColor, Authentication auth);

GatewayUserDTO getUserById(long id, Authentication auth);

List<GatewayAccountDTO> getAllAccounts(Authentication auth);

List<GatewayAccountDTO> getAllUserAccounts(long id, Authentication auth);

GatewayAccountDTO getAccountById(long id, Authentication auth);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.gateway.application.interfaces;

import org.gateway.infrastructure.DTO.GatewayAccountDTO;
import org.gateway.infrastructure.DTO.GatewayFriendsAccountsDTO;
import org.gateway.infrastructure.DTO.GatewayUserDTO;
import org.gateway.infrastructure.requestEntities.TransferRequest;
import org.springframework.security.core.Authentication;

import java.util.List;

public interface ClientApi {
GatewayUserDTO getSelf(Authentication auth);

List<GatewayAccountDTO> getMyAccounts(Authentication auth);

GatewayAccountDTO getAccountById(Long id, Authentication auth);

List<GatewayFriendsAccountsDTO> getFriendsAccounts(Authentication auth);

void transfer(TransferRequest transferRequest, Authentication auth);

void addFriend(Long friendId, Authentication auth);

void removeFriend(Long friendId, Authentication auth);

void deposit(Long id, double amount, Authentication auth);

void withdraw(Long id, double amount, Authentication auth);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.gateway.application.services;

import org.gateway.application.interfaces.AdminApi;
import org.gateway.infrastructure.entities.GatewayUser;
import org.gateway.infrastructure.entities.enums.Role;
import org.gateway.infrastructure.repos.GatewayUserRepository;
import org.gateway.infrastructure.requestEntities.CreateAdminRequest;
import org.gateway.infrastructure.requestEntities.CreateUserRequest;
import org.gateway.infrastructure.DTO.GatewayAccountDTO;
import org.gateway.infrastructure.DTO.GatewayUserDTO;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@RequiredArgsConstructor
public class AdminServices {
private final GatewayUserRepository gatewayUserRepository;
private final PasswordEncoder passwordEncoder;

private final AdminApi adminApi;

@Transactional
public void createAdmin(CreateAdminRequest admin) {
GatewayUser gatewayUser = new GatewayUser(admin.getLogin(),
passwordEncoder.encode(admin.getPassword()), List.of(Role.ADMIN));
gatewayUserRepository.save(gatewayUser);
}

@Transactional
public void createClient(CreateUserRequest clientRequest, String password, Authentication auth) {
GatewayUser entity = new GatewayUser(clientRequest.getLogin(),
passwordEncoder.encode(password), List.of(Role.CLIENT));
gatewayUserRepository.save(entity);
adminApi.createClient(clientRequest, password, auth);
}

public List<GatewayUserDTO> getAllUsers(Authentication auth) {
return adminApi.getAllUsers(auth);
}

public List<GatewayUserDTO> getAllUsersGenderFilter(String gender, Authentication auth) {
return adminApi.getAllUsersGenderFilter(gender, auth);
}

public List<GatewayUserDTO> getAllUsersHairColorFilter(String haircolor, Authentication auth) {
return adminApi.getAllUsersHairColorFilter(haircolor, auth);
}

public GatewayUserDTO getUserById(long id, Authentication auth) {
return adminApi.getUserById(id, auth);
}

public List<GatewayAccountDTO> getAllAccounts(Authentication auth) {
return adminApi.getAllAccounts(auth);
}

public List<GatewayAccountDTO> getAllUserAccounts(long user_id, Authentication auth) {
return adminApi.getAllUserAccounts(user_id, auth);
}

public GatewayAccountDTO getAccountById(long accountId, Authentication auth) {
return adminApi.getAccountById(accountId, auth);
}
}
Loading
Loading