Bonjour tout le monde,
Je travaille sur une application Web avec le framework Spring et Acegi security.
Dans mon application je gère des utilisateurs et je voudrais que ceux ci puisse modifier leur profil (leur login, mot de passe, etc.).
En fait cette fonctionnalité marche correctement mais lorsque l'utilisateur valide le formulaire qui lui permet de changer ces données, il est déconnecté.
Les données de mes utilisateurs sont stockées dans une base de données modifiée au moment de la validation de ce formulaire.
Voici mon code :
web.xml
ma configuration Acegi :
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
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
Mon controller pour le formulaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Et pou finir ma page JSP :
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138package mova.web.controllers; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import mova.logging.domain.User; import mova.logging.service.InscriptionManager; import mova.logging.service.UserManager; import mova.utils.Toolkit; import mova.web.validators.UserValidator; import org.springframework.validation.BindException; import org.springframework.validation.ValidationUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; /** * * @author Mohicane */ public class CompteController extends SimpleFormController { private UserManager userManager; private InscriptionManager inscriptionManager; @Override protected Object formBackingObject(HttpServletRequest request) throws Exception { User user = userManager.getCurrentUser(request); if (user != null) { return user; } return super.formBackingObject(request); } @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { User currentUser = userManager.getCurrentUser(request); User modifiedUser = (User) command; if (!modifiedUser.equals(currentUser)) { throw new SecurityException("Sécurité : Modification d'un profil par un User non autorisé."); } boolean modified = false; modified |= validateLogin(currentUser, modifiedUser, errors); modified |= validateEmail(currentUser, modifiedUser, errors); String newPassword = request.getParameter("new_password"); String newPasswordConfirmation = request.getParameter("new_password_confirmation"); modified |= validatePassword(newPassword, newPasswordConfirmation, modifiedUser, errors); if (errors.hasErrors()) { return showForm(request, response, errors); } if (modified) { currentUser.setLogin(modifiedUser.getLogin()); if (!newPassword.equals("")) { currentUser.setPassword(Toolkit.stringToMD5Encoding(newPassword)); } currentUser.setEmail(modifiedUser.getEmail()); userManager.saveUser(currentUser); } return new ModelAndView(getSuccessView()); } private boolean validateLogin(User currentUser, User modifiedUser, BindException errors) { if (!modifiedUser.getLogin().equals(currentUser.getLogin())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "login", "field.required", new Object[]{"login"}, ""); modifiedUser.setLogin(modifiedUser.getLogin().trim()); String login = modifiedUser.getLogin(); if (userManager.isLoginExisting(login) || inscriptionManager.isLoginExisting(login)) { errors.rejectValue("login", "field.already_used", new Object[]{login, "login"}, ""); } return !errors.hasFieldErrors("login"); } return false; } private boolean validateEmail(User currentUser, User modifiedUser, BindException errors) { if (!modifiedUser.getEmail().equals(currentUser.getEmail())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required", new Object[]{"email"}, ""); modifiedUser.setEmail(modifiedUser.getEmail().trim()); String email = modifiedUser.getEmail(); if (!email.matches(UserValidator.EMAIL_REGEX)) { errors.rejectValue("email", "field.invalid", new Object[]{email, "email"}, ""); } if (userManager.isEmailExisting(email) || inscriptionManager.isEmailExisting(email)) { errors.rejectValue("email", "field.already_used", new Object[]{email, "email"}, ""); } return !errors.hasFieldErrors("email"); } return false; } private boolean validatePassword(String newPassword, String newPasswordConfirmation, User modifiedUser, BindException errors) { if (newPassword.trim().length() != 0) { if (newPasswordConfirmation.trim().length() == 0) { errors.rejectValue("password", "password.not_confirmed"); } if (!newPasswordConfirmation.equals(newPassword)) { errors.rejectValue("password", "password.wrong_confirmation"); } if (newPassword.equals(modifiedUser.getLogin())) { errors.rejectValue("password", "password.login_like"); } return !errors.hasFieldErrors("password"); } return false; } public UserManager getUserManager() { return userManager; } public void setUserManager(UserManager userManager) { this.userManager = userManager; } public InscriptionManager getInscriptionManager() { return inscriptionManager; } public void setInscriptionManager(InscriptionManager inscriptionManager) { this.inscriptionManager = inscriptionManager; } }
Bon avec tout ca devrait être bon.
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
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
En vous remerciant d'avance pour votre aide ...
Mohicane

 

 
		
		 
        

 
			
			

 
   



 Changement des données utilisateurs = Deconnexion
 Changement des données utilisateurs = Deconnexion
				 Répondre avec citation
  Répondre avec citation
Partager