Bonjour ,
j'ai une class JWT AuthentificationFilter, je tente de récupérer le username et le password,mais je tombe sur cette erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "password" (class ohkod.tdlist.entities.Membre), not marked as ignorable (4 known properties: "id", "passsword", "roles", "username"]) at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1, column: 33] (through reference chain: ohkod.tdlist.entities.Membre["password"])
Voici ma class Membre:
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 import java.util.ArrayList; import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonSetter; @Entity public class Membre{ @Id @GeneratedValue private Long id; @Column(unique=true) private String username; private String passsword; @ManyToMany(fetch=FetchType.EAGER) private Collection<AppRole> roles = new ArrayList<>(); public Membre( Long id, String username, String passsword, Collection<AppRole> roles) { super(); this.id = id; this.username = username; this.passsword = passsword; this.roles = roles; } public Membre() { super(); } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public String getUsername() { return this.username; } public void setUsername(String username) { this.username = username; } @JsonIgnore public String getPasssword() { return this.passsword; } @JsonSetter public void setPasssword(String passsword) { this.passsword = passsword; } public Collection<AppRole> getRoles() { return this.roles; } public void setRoles(Collection<AppRole> roles) { this.roles = roles; } }
voici le code jwtAuthentication:
voici la configuration de la sécurité:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45 import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.sql.rowset.serial.SerialException; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import ohkod.tdlist.entities.Membre; public class JWTAuthentificationFilter extends UsernamePasswordAuthenticationFilter{ private AuthenticationManager authenticationManager; public JWTAuthentificationFilter(AuthenticationManager authenticationManager){ super(); this.authenticationManager = authenticationManager; } @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse reponse) throws AuthenticationException{ Membre membre = null; try { membre = new ObjectMapper().readValue(request.getInputStream(),Membre.class); } catch (Exception e) { System.out.println("**********Ligne 36**********"); throw new RuntimeException(e); } System.out.println("**********TEST JWT**********"); System.out.println(membre.getUsername()); System.out.println(membre.getPasssword()); return authenticationManager.authenticate( new UsernamePasswordAuthenticationToken(membre.getUsername(), membre.getPasssword()) ); }
comment je dois débugger cela pour que j'arrive juste à récupérer les informations post avant de continuer ?
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
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 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; 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.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsService userDetailsService; @Autowired private BCryptPasswordEncoder bCryptPasswordEncoder; @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder); } @Override protected void configure(HttpSecurity http) throws Exception{ http.csrf().disable(); http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);//desactiver la session //http.formLogin(); http.authorizeRequests().antMatchers("/login/**","/register/**").permitAll(); http.authorizeRequests().antMatchers(HttpMethod.POST, "/taches/**").hasAuthority("ADMIN"); http.authorizeRequests().anyRequest().authenticated(); System.out.println("**********TEST ligne 38**********"); http.addFilter(new JWTAuthentificationFilter(authenticationManager())); } }
merci de vos réponses
Partager