Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f90f34b
updated test to @WebMvcTest
PierreSQS Dec 11, 2022
5af64ff
upgraded SB to 2.7.6 and MapStruct to 1.5.3 and added annotation on U…
PierreSQS Dec 12, 2022
94bcab3
fixed the issue of the previous commit(5af64ff3) and extended test
PierreSQS Dec 12, 2022
a0ed4d4
upgraded java 11 to 17
PierreSQS Dec 12, 2022
c4aeb8a
upgraded SB maven to 3.8.6
PierreSQS Dec 12, 2022
c5cbeaa
upgraded circle CI Config
PierreSQS Dec 12, 2022
465f09b
last POM cleaning and adaption
PierreSQS Dec 12, 2022
6bd8b65
added failsafe plugin since IT tests not executed in CircleCI
PierreSQS Dec 12, 2022
217b0e6
adapted CI-Config to run the integration tests
PierreSQS Dec 12, 2022
8e7f69d
upgraded to SB2.7.8 and Maven FailSafe,optimized POM as per Initializr
PierreSQS Jan 21, 2023
e0f22a1
adapted Branch Badge accordingly
PierreSQS Jan 21, 2023
bf84adc
Sec8_Chap66-Spring Boot Test-NOK: upgraded SB from 2.7.8 to 3.0.1
PierreSQS Jan 22, 2023
afafdee
Sec8_Chap56-Spring Boot Test-NOK: fixed the failing test issue
PierreSQS Jan 22, 2023
47c86e8
Sec8_Chap56-Spring Boot Test: final solution fixed the previous issues
PierreSQS Jan 22, 2023
8d491f5
Sec8_Chap56-Spring Boot Test: adapted Branch Badge
PierreSQS Jan 22, 2023
be213e8
Sec8_Chap56-Spring Boot Test: fixed the Thymeleaf deprecation issues
PierreSQS Jan 22, 2023
cffdfb3
Sec8_Chap56-Spring Boot Test-NOK: fixed the H2-Console access issue a…
PierreSQS Jan 22, 2023
2bc0d2d
Sec8_Chap56-Spring Boot Test: final solution and fixes the previous i…
PierreSQS Jan 22, 2023
abeef09
Sec8_Chap56-Spring Boot Test: formatted Security Config and cleaned code
PierreSQS Mar 31, 2023
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
62 changes: 31 additions & 31 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build:
# Below is the definition of your job to build and test your app, you can rename and customize it as you want.
build-and-test:
# These next lines define a Docker executor: https://circleci.com/docs/2.0/executor-types/
# You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# Be sure to update the Docker image tag below to openjdk version of your application.
# A list of available CircleCI Docker Convenience Images are available here: https://circleci.com/developer/images/image/cimg/openjdk
docker:
# specify the version you desire here
- image: circleci/openjdk:11.0.7-buster

working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m

- image: cimg/openjdk:17.0.5
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
# Checkout the code as the first step.
- checkout
# Use mvn clean and package as the standard maven build phase
- run:
name: Build
command: mvn -V -B -DskipTests clean package
# Then run your unit tests and also the integrations tests!
- run:
name: Test
command: mvn -V verify

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: mvn install dependency:go-offline -Dmaven.test.skip=true

- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}

# run tests!
- run: mvn integration-test
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
sample: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
jobs:
- build-and-test
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![CircleCI](https://circleci.com/gh/PierreSQS/ssc-brewery/tree/db-test-context-revisit-sb3.0.1-INT.svg?style=shield)](https://circleci.com/gh/PierreSQS/ssc-brewery/tree/db-test-context-revisit-sb3.0.1-INT)
# Brewery Spring MVC Monolith

This repository contains source code examples used to support my on-line courses about the Spring Framework.
This repository contains source code examples used to support my on-line course [Spring Security Core: Beginner to Guru](https://www.udemy.com/course/spring-security-core-beginner-to-guru/).

You can learn more about the courses here:
* [Spring Security Core: Beginner to Guru](https://www.udemy.com/course/spring-security-core-beginner-to-guru/?referralCode=306F288EB78688C0F3BC)
Expand Down
45 changes: 34 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<version>3.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -57,14 +57,11 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<jaxb.version>2.3.0</jaxb.version>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<org.mapstruct.version>1.3.1.Final</org.mapstruct.version>
<org.projectlombok.version>1.18.12</org.projectlombok.version>
<!--Surefire plugin argLine value to suppress UnresolvedMavenProperty -->
<argLine>--illegal-access=permit</argLine>
<mapstruct.version>1.5.3.Final</mapstruct.version>

<!-- Web dependencies -->
<webjars-bootstrap.version>3.3.6</webjars-bootstrap.version>
<webjars-jquery-ui.version>1.12.1</webjars-jquery-ui.version>
Expand Down Expand Up @@ -114,7 +111,7 @@
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
<version>${mapstruct.version}</version>
</dependency>
<!-- webjars -->
<dependency>
Expand Down Expand Up @@ -154,6 +151,14 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
Expand Down Expand Up @@ -191,18 +196,23 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
<version>${lombok.version}</version>
</path>
<!-- additional annotation processor required as of Lombok 1.18.16 -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
Expand All @@ -212,6 +222,19 @@
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M8</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void loadSecurityData() {
}

@Override
public void run(String... args) throws Exception {
public void run(String... args) {
if (authorityRepository.count() == 0) {
loadSecurityData();
}
Expand Down
84 changes: 19 additions & 65 deletions src/main/java/guru/sfg/brewery/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,95 +1,49 @@
package guru.sfg.brewery.config;

import guru.sfg.brewery.security.SfgPasswordEncoderFactories;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

/**
* Created by jt on 6/13/20.
* Formatted by Pierrot on 2023-03-31.
*/
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
public class SecurityConfig {

@Override
protected void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {

http
.authorizeRequests(authorize -> {
authorize
.antMatchers("/h2-console/**").permitAll() //do not use in production!
.antMatchers("/", "/webjars/**", "/login", "/resources/**").permitAll()
.antMatchers("/beers/find", "/beers*").permitAll()
.antMatchers(HttpMethod.GET, "/api/v1/beer/**").permitAll()
.mvcMatchers(HttpMethod.GET, "/api/v1/beerUpc/{upc}").permitAll();
} )
.authorizeRequests()
.anyRequest().authenticated()
.authorizeHttpRequests(authorize -> authorize
.requestMatchers(PathRequest.toH2Console()).permitAll() //do not use in production!
.requestMatchers("/", "/webjars/**", "/login", "/resources/**").permitAll()
.requestMatchers("/beers/find", "/beers*").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/beer/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/beerUpc/{upc}").permitAll())
.authorizeHttpRequests().anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic()
.and()
.formLogin().and()
.httpBasic()
.and().csrf().disable();
.csrf().disable();

//h2 console config
http.headers().frameOptions().sameOrigin();
return http.build();
}

@Bean
PasswordEncoder passwordEncoder(){
return SfgPasswordEncoderFactories.createDelegatingPasswordEncoder();
}

// @Override
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.userDetailsService(this.jpaUserDetailsService).passwordEncoder(passwordEncoder());

// auth.inMemoryAuthentication()
// .withUser("spring")
// .password("{bcrypt}$2a$10$7tYAvVL2/KwcQTcQywHIleKueg4ZK7y7d44hKyngjTwHCDlesxdla")
// .roles("ADMIN")
// .and()
// .withUser("user")
// .password("{sha256}1296cefceb47413d3fb91ac7586a4625c33937b4d3109f5a4dd96c79c46193a029db713b96006ded")
// .roles("USER");
//
// auth.inMemoryAuthentication().withUser("scott").password("{bcrypt15}$2a$15$baOmQtw8UqWZRDQhMFPFj.xhkkWveCTQHe4OBdr8yw8QshejiSbI6").roles("CUSTOMER");
// }

// @Override
// @Bean
// protected UserDetailsService userDetailsService() {
// UserDetails admin = User.withDefaultPasswordEncoder()
// .username("spring")
// .password("guru")
// .roles("ADMIN")
// .build();
//
// UserDetails user = User.withDefaultPasswordEncoder()
// .username("user")
// .password("password")
// .roles("USER")
// .build();
//
// return new InMemoryUserDetailsManager(admin, user);
// }















}
7 changes: 2 additions & 5 deletions src/main/java/guru/sfg/brewery/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@
*/
package guru.sfg.brewery.domain;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.UUID;

/**
* Created by jt on 2019-01-26.
* Modified by Pierrot on 2023-01-22.
*/

@Setter
@Getter
@NoArgsConstructor
Expand All @@ -51,7 +49,6 @@ public BaseEntity(UUID id, Long version, Timestamp createdDate, Timestamp lastMo
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Type(type="org.hibernate.type.UUIDCharType")
@Column(length = 36, columnDefinition = "varchar", updatable = false, nullable = false )
private UUID id;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/guru/sfg/brewery/domain/Beer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

/**
* Created by jt on 2019-01-26.
* Modified by Pierrot on 2023-01-22.
*/
@Getter
@Setter
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/guru/sfg/brewery/domain/BeerInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import java.sql.Timestamp;
import java.util.UUID;

/**
* Created by jt on 2019-01-26.
* Modified by Pierrot on 2023-01-22.
*/
@Getter
@Setter
Expand Down
Loading