Authentification par la methode datasource de la base de donnée
Bonjour, je travail sur un petit projet avec spring version 2.3.1 et lorsque j'essai de faire une authentification avec les utilisateurs et les rôles depuis la base de donnée. il me renvoie une erreur de ce genre:
Citation:
There is no PasswordEncoder mapped for the id "null"
Voici ma classe pour la configuration de la sécurité
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| package org.univ;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
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;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void globalConfig(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception {
/*auth.inMemoryAuthentication().withUser("admin").password("{noop}admin").roles("ADMIN","PROF");
auth.inMemoryAuthentication().withUser("professeur").password("{noop}prof").roles("PROF");
auth.inMemoryAuthentication().withUser("etudiant").password("{noop}etud1").roles("ETUDIANT");
auth.inMemoryAuthentication().withUser("scolarite").password("{noop}scolarite").roles("SCOLARITE");*/
auth.jdbcAuthentication()
.dataSource(dataSource).usersByUsernameQuery("select user_name, password, actived from users where user_name = ?")
.authoritiesByUsernameQuery("select user_user_name, roles_role from user_roles where user_user_name = ?")
.rolePrefix("ROLE_");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.defaultSuccessUrl("/index.html");
}
} |
SVP besoin d'une aide si quelqu'un y peut.