Skip to content

Commit

Permalink
Merge pull request #37 from amitrp/aph-15360_java21_sb_3.4
Browse files Browse the repository at this point in the history
aph-15360 java 21 and SB 3.4
  • Loading branch information
amitrp authored Dec 17, 2024
2 parents 637c1e6 + 3e21b31 commit 53a1272
Show file tree
Hide file tree
Showing 154 changed files with 964 additions and 925 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'adopt'
cache: 'maven'
- name: Build with Maven
Expand Down
36 changes: 34 additions & 2 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>2.7.5</version>
<version>3.4.0</version>
</parent>

<groupId>com.amitph.spring</groupId>
Expand All @@ -32,7 +32,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<java.version>21</java.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -116,6 +116,38 @@
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<java>
<includes>
<include>src/main/java/**/*.java</include> <!-- Check application code -->
<include>src/test/java/**/*.java</include> <!-- Check application tests code -->
</includes>
<googleJavaFormat>
<version>1.17.0</version>
<style>AOSP</style>
</googleJavaFormat>
<importOrder />
<removeUnusedImports />
</java>
</configuration>

<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.amitph.spring.songs.actuator;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

@Component
@RestControllerEndpoint(id = "custom-rest-endpoint")
public class CustomRestActuator {
Expand All @@ -24,7 +23,7 @@ public Map<String, String> get() {
}

@PostMapping
public String post(@RequestBody String request) {
public String post(@RequestBody String request) {
return "We have received your request: " + request;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.amitph.spring.songs.actuator;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

@Component
@Endpoint(id = "custom-endpoint")
public class ServerTimeActuator {
Expand All @@ -34,4 +33,4 @@ public String deleteOperation() {
// Implementation skipped
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

@Component
public class ServiceAHealthIndicator implements HealthIndicator {
private final String message_key = "Service A";
private final String message_key = "Service A";

@Override
public Health health() {
if (!isRunningServiceA()) {
Expand All @@ -21,4 +22,4 @@ private Boolean isRunningServiceA() {

return isRunning;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.amitph.spring.songs.data;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

@Entity
public class Song {
@Id
@GeneratedValue
private Long songId;
@Id @GeneratedValue private Long songId;

private String title;
private String album;
Expand Down Expand Up @@ -54,4 +52,4 @@ public Integer getYear() {
public void setYear(Integer year) {
this.year = year;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.amitph.spring.songs.data;

import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SongRepository extends CrudRepository<Song, Long> {
List<Song> findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.amitph.spring.songs.data.SongRepository;
import com.amitph.spring.songs.web.SongDto;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
Expand All @@ -16,10 +14,12 @@ public class SongService {
private final SongTransformer transformer;

public List<SongDto> getAllSongs() {
return repository.findAll().stream().map(transformer::transform).collect(Collectors.toList());
return repository.findAll().stream()
.map(transformer::transform)
.collect(Collectors.toList());
}

public SongDto addNewSong(SongDto dto) {
return transformer.transform(repository.save(transformer.transform(dto)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public Song transform(SongDto dto) {
song.setYear(dto.getYear());
return song;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.amitph.spring.songs.web;

import com.amitph.spring.songs.service.SongService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/songs")
@RequiredArgsConstructor
Expand All @@ -26,4 +24,4 @@ public List<SongDto> getAll() {
public SongDto addSong(@RequestBody SongDto dto) {
return songService.addNewSong(dto);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public Integer getYear() {
public void setYear(Integer year) {
this.year = year;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
package com.amitph.spring.adminserver;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
public class SecurityConfiguration {
private final String adminContextPath;

public SecurityConfiguration(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
@Bean
protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler =
new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");

http
.authorizeRequests().antMatchers(adminContextPath + "/assets/**").permitAll()
.antMatchers(adminContextPath + "/login").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler)
.and().logout().logoutUrl(adminContextPath + "/logout")
.and().httpBasic()
.and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringAntMatchers(adminContextPath + "/instances", adminContextPath + "/actuator/**");
http.authorizeHttpRequests(
req ->
req.requestMatchers(adminContextPath + "/assets/**")
.permitAll()
.requestMatchers(adminContextPath + "/login")
.permitAll()
.anyRequest()
.authenticated())
.formLogin(
formLogin ->
formLogin
.loginPage(adminContextPath + "/login")
.successHandler(successHandler))
.logout(logout -> logout.logoutUrl(adminContextPath + "/logout"))
.httpBasic(Customizer.withDefaults())
.csrf(
csrf ->
csrf.csrfTokenRepository(
CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(
adminContextPath + "/instances",
adminContextPath + "/actuator/**"));
return http.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}


@Override
public void run(String... args) throws Exception {
service.printMessage(args);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.amitph.spring.nonweb.service;

import org.springframework.stereotype.Service;

import java.util.Arrays;
import org.springframework.stereotype.Service;

@Service
public class NonWebService {
public void printMessage(String[] arguments) {
System.out.println("Inside NonWebService Class. Received below arguments");
Arrays.stream(arguments).forEach(System.out::println);
}
}
}
2 changes: 1 addition & 1 deletion spring-boot-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<java.version>21</java.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
}
Loading

0 comments on commit 53a1272

Please sign in to comment.