Skip to content

Commit

Permalink
Merge pull request #26 from pavelfomin/feature/spring-boot-3.1
Browse files Browse the repository at this point in the history
Migrate to springBoot version 3.1.2
  • Loading branch information
pavelfomin committed Aug 18, 2023
2 parents a0a40d9 + 1e30e19 commit 1a42476
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 78 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gradle-nebula.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
# 0 indicates all history for all branches and tags
fetch-depth: "0"

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'temurin'
settings-path: ${{ github.workspace }} # location for the settings.xml file

Expand All @@ -41,7 +41,7 @@ jobs:
git remote -v
- name: Build for PR
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
uses: gradle/gradle-build-action@v2
if: github.event_name == 'pull_request'
with:
arguments: build -Prelease.stage=final
Expand All @@ -65,7 +65,7 @@ jobs:
min-coverage-changed-files: 99

- name: Build, publish and tag release
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
uses: gradle/gradle-build-action@v2
if: github.event_name == 'push'
with:
arguments: build publish final -Prelease.stage=final
Expand Down
21 changes: 10 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ plugins {
id 'maven-publish'
}

allprojects {
group 'com.droidablebee'
sourceCompatibility = 11
targetCompatibility = 11
}

java {
sourceCompatibility = '17'
withJavadocJar()
withSourcesJar()
}
Expand All @@ -29,27 +24,31 @@ dependencies {
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-validation"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation "org.springframework.boot:spring-boot-starter-oauth2-resource-server"

implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.0'
implementation "com.h2database:h2:2.1.210"

testImplementation ("org.springframework.boot:spring-boot-starter-test") {
// exclude group: 'org.mockito'
// exclude group: 'org.junit.jupiter'
}
testImplementation "org.springframework.security:spring-security-test"
testImplementation "org.spockframework:spock-spring:2.3-groovy-3.0"
// testImplementation "org.objenesis:objenesis:3.3"
testImplementation platform("org.spockframework:spock-bom:${spockVersion}-groovy-${groovyVersion}")
testImplementation "org.spockframework:spock-spring"
testImplementation "org.apache.groovy:groovy-json"
}

repositories {
mavenLocal()
mavenCentral()
}

test {
tasks.named('test') {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
afterSuite { desc, result ->
if (!desc.parent)
println("${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)")
Expand Down
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version=2.6.3.0
group=com.droidablebee

springBootVersion=2.6.3
springBootDependencyManagement=1.0.11.RELEASE
springBootVersion=3.1.2
springBootDependencyManagement=1.1.2
spockVersion=2.4-M1
groovyVersion=4.0
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebConfiguration implements WebMvcConfigurer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
package com.droidablebee.springboot.rest.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}")
private String issuerUri;
public class WebSecurityConfig {

@Value("${app.security.ignore:/swagger/**, /swagger-resources/**, /swagger-ui/**, /swagger-ui.html, /webjars/**, /v3/api-docs/**, /actuator/info}")
private String[] ignorePatterns;

@Override
protected void configure(HttpSecurity http) throws Exception {

http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

http.csrf().disable(); // do not require SCRF for POST and PUT

//make sure principal is created for the health endpoint to verify the role
http.authorizeRequests().antMatchers("/actuator/health").permitAll();
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http
.csrf(AbstractHttpConfigurer::disable)
.authorizeRequests()
// .mvcMatchers("/messages/**").hasAuthority("SCOPE_message:read")
.anyRequest().authenticated()
//make sure principal is created for the health endpoint to verify the role
.requestMatchers(new AntPathRequestMatcher("/actuator/health"))
.permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
.oauth2ResourceServer((configurer) -> configurer.jwt(Customizer.withDefaults()))
.sessionManagement((s) -> s.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

return http.build();
}

@Override
public void configure(WebSecurity web) {
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {

web.ignoring().antMatchers(ignorePatterns);
return (web) -> web.ignoring().requestMatchers(ignorePatterns);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.droidablebee.springboot.rest.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotNull;

@Entity
public class Address {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/droidablebee/springboot/rest/domain/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;

@Entity
public class Person {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
Expand Down Expand Up @@ -32,7 +32,7 @@ protected ResponseEntity<?> handleBindException(BindException exception) {
}

/**
* Exception handler for validation errors caused by method parameters @RequesParam, @PathVariable, @RequestHeader annotated with javax.validation constraints.
* Exception handler for validation errors caused by method parameters @RequesParam, @PathVariable, @RequestHeader annotated with jakarta.validation constraints.
*/
@ExceptionHandler
protected ResponseEntity<?> handleConstraintViolationException(ConstraintViolationException exception) {
Expand Down Expand Up @@ -76,12 +76,12 @@ protected ResponseEntity<?> handleHttpMessageNotReadableException(HttpMessageNot

@ExceptionHandler
protected ResponseEntity<?> handleAccessDeniedException(AccessDeniedException exception) {
return new ResponseEntity<Error>(new Error(null, null, exception.getMessage()), HttpStatus.FORBIDDEN);
return new ResponseEntity<>(new Error(null, null, exception.getMessage()), HttpStatus.FORBIDDEN);
}

@ExceptionHandler
protected ResponseEntity<?> handleException(Exception exception) {
return new ResponseEntity<Error>(new Error(null, null, exception.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(new Error(null, null, exception.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
}

protected List<Error> convert(List<ObjectError> objectErrors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.Size;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;

@RestController
@RequestMapping(produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.transaction.annotation.Transactional

import javax.persistence.EntityManager
import jakarta.persistence.EntityManager

import static com.droidablebee.springboot.rest.endpoint.PersonEndpoint.PERSON_READ_PERMISSION
import static com.droidablebee.springboot.rest.endpoint.PersonEndpoint.PERSON_WRITE_PERMISSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabas
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import spock.lang.Specification

import javax.persistence.EntityManager
import javax.persistence.EntityNotFoundException
import javax.persistence.PersistenceContext
import jakarta.persistence.EntityManager
import jakarta.persistence.EntityNotFoundException
import jakarta.persistence.PersistenceContext

@DataJpaTest
/*
Expand All @@ -35,7 +35,7 @@ class PersonRepositorySpec extends Specification {
and: "accessing id won't throw an exception"
person.getId()

when: "accessing the Entity's reference state should cause javax.persistence.EntityNotFoundException"
when: "accessing the Entity's reference state should cause jakarta.persistence.EntityNotFoundException"
person.getFirstName()

then:
Expand All @@ -53,7 +53,7 @@ class PersonRepositorySpec extends Specification {
and: "accessing id won't throw an exception"
person.getId()

when: "accessing the Entity's reference state should cause javax.persistence.EntityNotFoundException"
when: "accessing the Entity's reference state should cause jakarta.persistence.EntityNotFoundException"
person.getFirstName()

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import java.util.Date;
import java.util.List;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -34,19 +34,19 @@ public void getOne() {

Person person = personRepository.getOne(Long.MAX_VALUE);
assertNotNull(person);
//access to the Entity's reference state should cause javax.persistence.EntityNotFoundException
//access to the Entity's reference state should cause jakarta.persistence.EntityNotFoundException
assertNotNull(person.getId()); // accessing id won't throw an exception
assertThrows(javax.persistence.EntityNotFoundException.class, () -> person.getFirstName());
assertThrows(jakarta.persistence.EntityNotFoundException.class, () -> person.getFirstName());
}

@Test
public void getReferenceUsingEntityManager() {

Person person = entityManager.getReference(Person.class, Long.MAX_VALUE);
assertNotNull(person);
//access to the Entity's reference state should cause javax.persistence.EntityNotFoundException
//access to the Entity's reference state should cause jakarta.persistence.EntityNotFoundException
assertNotNull(person.getId()); // accessing id won't throw an exception
assertThrows(javax.persistence.EntityNotFoundException.class, () -> person.getFirstName());
assertThrows(jakarta.persistence.EntityNotFoundException.class, () -> person.getFirstName());
}

@Test
Expand Down

0 comments on commit 1a42476

Please sign in to comment.