Connexion BDD v1
This commit is contained in:
@@ -23,7 +23,6 @@ public class AccueilController {
|
||||
@GetMapping({"/", "/accueil"})
|
||||
public String viewAccueil(Model model) {
|
||||
|
||||
logger.info("Liste des articles : {}", articleService.findAllArticle().getLast());
|
||||
model.addAttribute("articles", articleService.findAllArticle());
|
||||
|
||||
return "accueil";
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.List;
|
||||
@Repository
|
||||
@Primary
|
||||
public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ArticleRepositoryImpl.class);
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||
@@ -37,17 +38,16 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
return article;
|
||||
}
|
||||
}
|
||||
|
||||
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.namedJdbcTemplate = namedJdbcTemplate;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Article> findAllArticle() {
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS";
|
||||
List<Article> articles = jdbcTemplate.query(sql, new ArticleRowMapper());
|
||||
|
||||
return articles;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
@@ -12,10 +13,12 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@Primary
|
||||
public class UserRepositoryImpl implements UserRepository {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public UserRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
|
||||
41
src/main/java/fr/eni/enchere/security/WebSecurityConfig.java
Normal file
41
src/main/java/fr/eni/enchere/security/WebSecurityConfig.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package fr.eni.enchere.security;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests((requests) -> requests.requestMatchers("/", "/films", "/filmotheque", "/film").permitAll()
|
||||
.requestMatchers("/filmLogout", "/login").permitAll()
|
||||
.requestMatchers("/css/**", "/images/**").permitAll()
|
||||
.requestMatchers("/genres").hasRole("ADMIN")
|
||||
.requestMatchers("/ajoutFilm")
|
||||
.hasAnyRole("MEMBRE", "ADMIN")
|
||||
.anyRequest().authenticated())
|
||||
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
||||
.logout((logout) -> logout.clearAuthentication(true).invalidateHttpSession(true)
|
||||
.deleteCookies("JSESSIONID").logoutSuccessUrl("/filmLogout")
|
||||
.logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll());
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder encoder() {
|
||||
// Production :
|
||||
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
// Dev/test
|
||||
//return NoOpPasswordEncoder.getInstance();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user