Connexion BDD v1

This commit is contained in:
jleroy
2024-04-23 08:12:45 +02:00
parent 2fcafc0ea1
commit b253aa55b0
4 changed files with 46 additions and 3 deletions

View File

@@ -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";

View File

@@ -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;
}

View File

@@ -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;

View 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();
}
}