Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
David committed Sep 10, 2021
2 parents 3e6aada + 5f2eae8 commit 2cc0a84
Show file tree
Hide file tree
Showing 55 changed files with 2,892 additions and 173 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HELP.md
target/
logs/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
Expand Down
Binary file modified docs/data-model/2-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 73 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand All @@ -32,8 +46,31 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand Down Expand Up @@ -70,7 +107,41 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<!-- Excludes Front Coverage (Thymeleaf) -->
<exclude>**/*LoginController.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MoneyTransferSystemApplication {
public class Application {

public static void main(String[] args) {
SpringApplication.run(MoneyTransferSystemApplication.class, args);
}

SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.openclassrooms.moneytransfersystem.configuration;

import com.openclassrooms.moneytransfersystem.model.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class CustomUserDetails implements UserDetails {

private User user;

public CustomUserDetails(User user) {

this.user = user;
}

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {

return null;
}

@Override
public String getPassword() {

return user.getPassword();
}

@Override
public String getUsername() {

return user.getEmail();
}

@Override
public boolean isAccountNonExpired() {

return true;
}

@Override
public boolean isCredentialsNonExpired() {

return true;
}

@Override
public boolean isAccountNonLocked() {
return true;
}

@Override
public boolean isEnabled() {

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.openclassrooms.moneytransfersystem.configuration;

import com.openclassrooms.moneytransfersystem.dao.UserRepository;
import com.openclassrooms.moneytransfersystem.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class CustomUserDetailsService implements UserDetailsService {

@Autowired
private UserRepository userRepository;

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

User user = userRepository.findByEmail(username);
if (user == null) {
throw new UsernameNotFoundException("[loadUserByUsername] user not found: " + username);
}

return new CustomUserDetails(user);
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,70 @@
package com.openclassrooms.moneytransfersystem.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import javax.sql.DataSource;

@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
@Autowired
private DataSource dataSource;

auth.inMemoryAuthentication()
.withUser("[email protected]")
.password(passwordEncoder().encode("jamesbond"))
.roles("CLIENT");
@Bean
public UserDetailsService userDetailsService() {

return new CustomUserDetailsService();
}

@Override
public void configure(HttpSecurity http) throws Exception {
@Bean
public BCryptPasswordEncoder passwordEncoder() {

http.authorizeRequests()
.antMatchers("/compte").hasRole("CLIENT")
.anyRequest().authenticated()
.and()
.formLogin();
return new BCryptPasswordEncoder();
}

@Bean
public PasswordEncoder passwordEncoder() {
public DaoAuthenticationProvider authenticationProvider() {

return new BCryptPasswordEncoder();
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService());
authProvider.setPasswordEncoder(passwordEncoder());

return authProvider;
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {

auth.authenticationProvider(authenticationProvider());
}

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

http.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/app")
.authenticated()
.and()
.formLogin()
.defaultSuccessUrl("/app")
.usernameParameter("email")
.permitAll()
.and()
.logout().logoutSuccessUrl("/").permitAll()
.and()
.csrf().disable(); // Enabling Postman POST requests
}
}
Loading

0 comments on commit 2cc0a84

Please sign in to comment.