diff --git a/.github/workflows/java11-build.yml b/.github/workflows/java11-build.yml new file mode 100644 index 00000000..0ac9e871 --- /dev/null +++ b/.github/workflows/java11-build.yml @@ -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 diff --git a/MIGRATION_NOTES.md b/MIGRATION_NOTES.md new file mode 100644 index 00000000..5a9d95a7 --- /dev/null +++ b/MIGRATION_NOTES.md @@ -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 `11` configuration in maven-compiler-plugin. + +**Maven Plugins Updated**: +- maven-compiler-plugin: 3.11.0 (with `11`) +- 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 diff --git a/README.md b/README.md index 2f49958e..b9099a63 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/pom.xml b/pom.xml index fc5bfeac..32fa46b5 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.3.3 + 2.7.18 com.example @@ -27,7 +27,9 @@ - 17 + 11 + 11 + UTF-8 @@ -48,7 +50,7 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity6 + thymeleaf-extras-springsecurity5 @@ -67,9 +69,53 @@ spring-security-test test + + com.h2database + h2 + test + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 11 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.5 + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.5.0 + + + enforce + + + + [11,) + + + + + + + + org.springframework.boot @@ -78,11 +124,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - + + + org.apache.maven.plugins + maven-enforcer-plugin diff --git a/src/main/java/com/example/bankapp/config/SecurityConfig.java b/src/main/java/com/example/bankapp/config/SecurityConfig.java index 4dbd1572..c3e929cc 100644 --- a/src/main/java/com/example/bankapp/config/SecurityConfig.java +++ b/src/main/java/com/example/bankapp/config/SecurityConfig.java @@ -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(); } @@ -57,4 +56,4 @@ public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception auth.userDetailsService(accountService).passwordEncoder(passwordEncoder()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/example/bankapp/model/Account.java b/src/main/java/com/example/bankapp/model/Account.java index b5e3f17d..1185cb66 100644 --- a/src/main/java/com/example/bankapp/model/Account.java +++ b/src/main/java/com/example/bankapp/model/Account.java @@ -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; @@ -84,4 +84,24 @@ public List getTransactions() { public void setTransactions(List 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; + } } diff --git a/src/main/java/com/example/bankapp/model/Transaction.java b/src/main/java/com/example/bankapp/model/Transaction.java index b3f371f9..f9bdcb1e 100644 --- a/src/main/java/com/example/bankapp/model/Transaction.java +++ b/src/main/java/com/example/bankapp/model/Transaction.java @@ -1,6 +1,6 @@ package com.example.bankapp.model; -import jakarta.persistence.*; +import javax.persistence.*; import java.math.BigDecimal; import java.time.LocalDateTime; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 08663a63..5dfad87b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 00000000..3c7cd18a --- /dev/null +++ b/src/test/resources/application.properties @@ -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