Skip to content
Open
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
27 changes: 27 additions & 0 deletions .github/workflows/java11-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Java 11 Build

on:
push:
branches: [ DevOps, main, master ]
pull_request:
branches: [ DevOps, main, master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup JDK 11
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '11'
cache: maven

- name: Build with Maven
run: mvn -B -e -DskipTests clean verify

- name: Run Tests
run: mvn -B test
70 changes: 70 additions & 0 deletions MIGRATION_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Java 8 to Java 11 Migration Notes

This document summarizes the changes made to migrate the Springboot-BankApp from Java 8 to Java 11.

## Summary of Changes

### Build Configuration (pom.xml)

The following changes were made to support Java 11:

**Spring Boot Version**: Downgraded from 3.3.3 to 2.7.18 (LTS) because Spring Boot 3.x requires Java 17+, while Spring Boot 2.7.x supports Java 8-17.

**Java Version**: Updated from Java 8 to Java 11 using the `<release>11</release>` configuration in maven-compiler-plugin.

**Maven Plugins Updated**:
- maven-compiler-plugin: 3.11.0 (with `<release>11</release>`)
- maven-surefire-plugin: 3.2.5
- maven-failsafe-plugin: 3.2.5
- maven-enforcer-plugin: 3.5.0 (enforces Java 11+ requirement)

**Dependencies Changed**:
- thymeleaf-extras-springsecurity6 -> thymeleaf-extras-springsecurity5 (Spring Security 5 for Spring Boot 2.7.x)
- Added H2 database for testing (test scope)

### Source Code Changes

**Model Classes (Account.java, Transaction.java)**:
- Changed `jakarta.persistence.*` imports to `javax.persistence.*` (Jakarta EE namespace is used in Spring Boot 3.x, Java EE namespace in Spring Boot 2.7.x)
- Added UserDetails interface methods to Account.java: `isAccountNonExpired()`, `isAccountNonLocked()`, `isCredentialsNonExpired()`, `isEnabled()`

**SecurityConfig.java**:
- Updated from Spring Security 6 lambda DSL to Spring Security 5 method chaining style
- Changed `requestMatchers()` to `antMatchers()`
- Changed `authorizeHttpRequests()` to `authorizeRequests()`
- Updated logout, formLogin, and headers configuration to use `.and()` chaining

### Configuration Changes

**application.properties**:
- Changed Hibernate dialect from `MySQL8Dialect` to `MySQL57Dialect` for Hibernate 5 compatibility

**Test Configuration**:
- Added `src/test/resources/application.properties` with H2 in-memory database configuration for testing

### CI/CD

**GitHub Actions**:
- Added `.github/workflows/java11-build.yml` workflow for JDK 11 builds
- Uses Temurin JDK 11 distribution
- Includes Maven caching for faster builds

## Validation

- Build compiles successfully with Java 11
- All tests pass with H2 in-memory database
- Maven enforcer plugin ensures Java 11+ is required

## Known Considerations

1. **Database Compatibility**: The application uses MySQL in production. The test configuration uses H2 for CI/CD compatibility.

2. **Spring Security**: Using Spring Security 5 method chaining style. Some methods are deprecated but functional.

3. **Hibernate Dialect**: Using MySQL57Dialect which is compatible with MySQL 5.7+ and MySQL 8.x.

## Future Considerations

- Consider upgrading to Spring Boot 3.x with Java 17+ for long-term support
- Consider migrating to Jakarta EE namespace when upgrading to Spring Boot 3.x
- Consider using Spring Security 6 lambda DSL when upgrading to Spring Boot 3.x
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## End-to-End Bank Application Deployment using DevSecOps on AWS EKS
- This is a multi-tier bank an application written in Java (Springboot).

## Requirements
- **Java 11** (JDK 11 or higher) - This application requires Java 11 to build and run
- **Maven 3.6+** - For building the application
- **MySQL 5.7+** - For the database

See [MIGRATION_NOTES.md](MIGRATION_NOTES.md) for details on the Java 8 to Java 11 migration.

![Login diagram](images/login.png)
![Transactions diagram](images/transactions.png)

Expand Down
61 changes: 53 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<version>2.7.18</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand All @@ -27,7 +27,9 @@
<url/>
</scm>
<properties>
<java.version>17</java.version>
<java.version>11</java.version>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
Expand All @@ -48,7 +50,7 @@
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>

<dependency>
Expand All @@ -67,9 +69,53 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<goals><goal>enforce</goal></goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[11,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -78,11 +124,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
</plugins>
</build>
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/com/example/bankapp/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,26 @@ public static PasswordEncoder passwordEncoder() {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(authz -> authz
.requestMatchers("/register").permitAll()
.csrf().disable()
.authorizeRequests()
.antMatchers("/register").permitAll()
.anyRequest().authenticated()
)
.formLogin(form -> form
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/dashboard", true)
.permitAll()
)
.logout(logout -> logout
.and()
.logout()
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login?logout")
.permitAll()
)
.headers(headers -> headers
.frameOptions(frameOptions -> frameOptions.sameOrigin())
);
.and()
.headers()
.frameOptions().sameOrigin();

return http.build();
}
Expand All @@ -57,4 +56,4 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception
auth.userDetailsService(accountService).passwordEncoder(passwordEncoder());

}
}
}
22 changes: 21 additions & 1 deletion src/main/java/com/example/bankapp/model/Account.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.bankapp.model;

import jakarta.persistence.*;
import javax.persistence.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

Expand Down Expand Up @@ -84,4 +84,24 @@ public List<Transaction> getTransactions() {
public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}

@Override
public boolean isAccountNonExpired() {
return true;
}

@Override
public boolean isAccountNonLocked() {
return true;
}

@Override
public boolean isCredentialsNonExpired() {
return true;
}

@Override
public boolean isEnabled() {
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/bankapp/model/Transaction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.bankapp.model;

import jakarta.persistence.*;
import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# JPA & Hibernate configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.jpa.show-sql=true
12 changes: 12 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring.application.name=bankapp

# H2 Database configuration for testing
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

# JPA & Hibernate configuration for testing
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true