Skip to content

Commit

Permalink
fix():compiling errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibaut-Mouton committed Apr 16, 2024
1 parent 59c4719 commit 80b92a8
Show file tree
Hide file tree
Showing 89 changed files with 2,169 additions and 2,979 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: maven
name: build-back

on: push

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: npm
name: build-front

on: push

Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
![maven build status](https://github.com/Thibaut-Mouton/react-spring-messenger-project/workflows/maven/badge.svg?branch=master)
![npm build status](https://github.com/Thibaut-Mouton/react-spring-messenger-project/workflows/npm/badge.svg?branch=master)

<p align="center">
<img src="/assets/react.png" alt="React logo"/>
<img src="/assets/springboot.png" alt="Spring boot logo"/>
</p>

# FastLiteMessage ![build status](https://github.com/Thibaut-Mouton/react-spring-messenger-project/workflows/maven/badge.svg?branch=master)
# FastLiteMessage

Real time chat application group oriented built with React and Spring Boot. Talk with your friends, create and add users to conversation, send messages or images, set groups administrators and start video calls ! (coming soon)

# Project Requirements

* [JDK](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) 17
* [NodeJS](https://nodejs.org/en/download/) v16.14.2
* [ReactJS](https://reactjs.org/) v17
* [NodeJS](https://nodejs.org/en/download/) v20.12.1
* [ReactJS](https://reactjs.org/) v18
* [Material UI](https://mui.com/) v5.7.0
* [MySQL Server](https://www.mysql.com/)

Expand All @@ -24,7 +27,7 @@ This will start 3 containers : MySQL, backend and frontend together. Liquibase
* Luke
* Steve
```
Be sure that no other app is running on port 3000, 9090 or 3306
Warning : Be sure that no other app is running on port 3000, 9090 or 3306
```

# Project development set up
Expand All @@ -33,7 +36,7 @@ Be sure that no other app is running on port 3000, 9090 or 3306
* You can disable Liquibase by setting ```spring.liquibase.enabled=false``` in ```application.properties```.
* To try the project on localhost, check that nothing runs on ports 9090 (Spring Boot) and 3000 (React app)
* You can edit ````spring.datasource```` in ```backend/src/main/resources/application.properties``` and ```username``` and ```password``` in ```backend/src/main/resources/liquibase.properties``` with your own MySQL login / password
* Create a database named "fastlitemessage" or you can also modify the name in the properties files mentioned just above.
* Create a database named "fastlitemessage_dev" or you can also modify the name in the properties files mentioned just above.

## Start backend
* Go inside backend folder then type ```mvn spring-boot:run``` to launch backend.
Expand Down
41 changes: 28 additions & 13 deletions backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/>
<version>3.2.4</version>
</parent>

<groupId>com.mercure</groupId>
<artifactId>messenger</artifactId>
<version>1.3.0</version>
Expand Down Expand Up @@ -40,50 +41,62 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.6.7</version>
<version>3.2.4</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.2.4</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.0.0-jre</version>
<version>33.1.0-jre</version>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0-M2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
<version>6.2.3</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.2.4</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.3.0</version>
</dependency>

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.27.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>3.2.4</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<version>2.10.1</version>
</dependency>

<dependency>
Expand All @@ -95,24 +108,26 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
<version>3.2.4</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<version>3.2.4</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.10.0</version>
<version>4.27.0</version>
</dependency>
</dependencies>

Expand All @@ -122,7 +137,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>3.13.0</version>
<configuration>
<release>17</release>
</configuration>
Expand All @@ -137,7 +152,7 @@
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.0.0</version>
<version>4.10.0</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mercure.config;

import com.mercure.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -14,7 +15,6 @@
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.server.HandshakeInterceptor;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.mercure.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

Expand Down
12 changes: 6 additions & 6 deletions backend/src/main/java/com/mercure/config/JwtWebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.mercure.service.CustomUserDetailsService;
import com.mercure.utils.JwtUtil;
import com.mercure.utils.StaticVariable;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -11,11 +16,6 @@
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.WebUtils;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
Expand All @@ -28,7 +28,7 @@ public class JwtWebConfig extends OncePerRequestFilter {
private JwtUtil jwtUtil;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException, ServletException {
String jwtToken = null;
String username;
Cookie cookie = WebUtils.getCookie(request, StaticVariable.SECURE_COOKIE);
Expand Down
106 changes: 41 additions & 65 deletions backend/src/main/java/com/mercure/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,87 +1,63 @@
package com.mercure.config;

import com.mercure.service.CustomUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.Customizer;
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.config.http.SessionCreationPolicy;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;
import java.util.List;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;

@Autowired
private JwtWebConfig jwtWebConfig;

@Autowired
private CustomUserDetailsService customUserDetailsService;
public class SecurityConfig {

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(passwordEncoder());
}
// @Bean
// public CorsConfigurationSource corsConfigurationSource() {
// CorsConfiguration configuration = new CorsConfiguration();
// configuration.setAllowedOrigins(List.of("http://localhost:3000"));
// configuration.setAllowedMethods(Arrays.asList("GET", "POST", "OPTIONS"));
// configuration.setAllowedMethods(List.of("*"));
// configuration.setAllowedHeaders(List.of("*"));
// configuration.setAllowCredentials(Boolean.TRUE);
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// source.registerCorsConfiguration("/**", configuration);
// return source;
// }

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of("http://localhost:3000"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST"));
configuration.setAllowedHeaders(List.of("*"));
configuration.addAllowedOriginPattern("*");
configuration.setAllowCredentials(Boolean.TRUE);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors(Customizer.withDefaults())
.authorizeHttpRequests((auth) -> auth.anyRequest().permitAll());
return http.build();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
.authorizeRequests()
.antMatchers("/api/auth").permitAll()
.antMatchers("/api/user/register").permitAll()
.antMatchers("/ws").permitAll()
.antMatchers("/static/**").permitAll()
.antMatchers("/images/**").permitAll()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(jwtWebConfig, UsernamePasswordAuthenticationFilter.class);
}
// protected void configure(HttpSecurity http) throws Exception {
// http.cors().and()
// .csrf()
// .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
// .and()
// .authorizeRequests()
// .antMatchers("/api/auth").permitAll()
// .antMatchers("/api/user/register").permitAll()
// .antMatchers("/ws").permitAll()
// .antMatchers("/static/**").permitAll()
// .antMatchers("/images/**").permitAll()
// .antMatchers("/").permitAll()
// .anyRequest().authenticated()
// .and()
// .exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
// .and()
// .sessionManagement()
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// http.addFilterBefore(jwtWebConfig, UsernamePasswordAuthenticationFilter.class);
// }
}
Loading

0 comments on commit 80b92a8

Please sign in to comment.