18
18
19
19
import org .springframework .context .ApplicationContext ;
20
20
import org .springframework .context .ApplicationContextAware ;
21
- import org .springframework .security .authentication .password .ChangeExistingPasswordAdvisor ;
22
21
import org .springframework .security .authentication .password .ChangePasswordAdvice ;
22
+ import org .springframework .security .authentication .password .ChangePasswordAdvisor ;
23
23
import org .springframework .security .authentication .password .ChangePasswordServiceAdvisor ;
24
- import org .springframework .security .authentication .password .ChangeUpdatingPasswordAdvisor ;
25
24
import org .springframework .security .authentication .password .DelegatingChangePasswordAdvisor ;
26
25
import org .springframework .security .authentication .password .UserDetailsPasswordManager ;
27
26
import org .springframework .security .config .annotation .web .HttpSecurityBuilder ;
28
27
import org .springframework .security .core .userdetails .UserDetails ;
29
- import org .springframework .security .crypto .factory .PasswordEncoderFactories ;
30
- import org .springframework .security .crypto .password .PasswordEncoder ;
31
28
import org .springframework .security .web .RequestMatcherRedirectFilter ;
32
29
import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
33
30
import org .springframework .security .web .authentication .password .ChangeCompromisedPasswordAdvisor ;
34
31
import org .springframework .security .web .authentication .password .ChangePasswordAdviceHandler ;
35
32
import org .springframework .security .web .authentication .password .ChangePasswordAdviceRepository ;
36
33
import org .springframework .security .web .authentication .password .ChangePasswordAdvisingFilter ;
37
- import org .springframework .security .web .authentication .password .ChangePasswordProcessingFilter ;
38
- import org .springframework .security .web .authentication .password .DefaultChangePasswordPageGeneratingFilter ;
39
34
import org .springframework .security .web .authentication .password .HttpSessionChangePasswordAdviceRepository ;
40
35
import org .springframework .security .web .authentication .password .SimpleChangePasswordAdviceHandler ;
41
36
import org .springframework .security .web .savedrequest .RequestCacheAwareFilter ;
42
- import org .springframework .security .web .servlet .util .matcher .PathPatternRequestMatcher ;
43
37
import org .springframework .util .Assert ;
44
38
45
39
/**
@@ -53,21 +47,17 @@ public final class PasswordManagementConfigurer<B extends HttpSecurityBuilder<B>
53
47
54
48
private static final String WELL_KNOWN_CHANGE_PASSWORD_PATTERN = "/.well-known/change-password" ;
55
49
56
- private static final String DEFAULT_CHANGE_PASSWORD_PAGE = DefaultChangePasswordPageGeneratingFilter . DEFAULT_CHANGE_PASSWORD_URL ;
50
+ private static final String DEFAULT_CHANGE_PASSWORD_PAGE = "/change-password" ;
57
51
58
52
private ApplicationContext context ;
59
53
60
54
private boolean customChangePasswordPage = false ;
61
55
62
56
private String changePasswordPage = DEFAULT_CHANGE_PASSWORD_PAGE ;
63
57
64
- private String changePasswordProcessingUrl = ChangePasswordProcessingFilter .DEFAULT_PASSWORD_CHANGE_PROCESSING_URL ;
65
-
66
58
private ChangePasswordAdviceRepository changePasswordAdviceRepository ;
67
59
68
- private ChangeExistingPasswordAdvisor changeExistingPasswordAdvisor ;
69
-
70
- private ChangeUpdatingPasswordAdvisor changeUpdatingPasswordAdvisor ;
60
+ private ChangePasswordAdvisor changePasswordAdvisor ;
71
61
72
62
private ChangePasswordAdviceHandler changePasswordAdviceHandler ;
73
63
@@ -86,26 +76,15 @@ public PasswordManagementConfigurer<B> changePasswordPage(String changePasswordP
86
76
return this ;
87
77
}
88
78
89
- public PasswordManagementConfigurer <B > changePasswordProcessingUrl (String changePasswordProcessingUrl ) {
90
- this .changePasswordProcessingUrl = changePasswordProcessingUrl ;
91
- return this ;
92
- }
93
-
94
79
public PasswordManagementConfigurer <B > changePasswordAdviceRepository (
95
80
ChangePasswordAdviceRepository changePasswordAdviceRepository ) {
96
81
this .changePasswordAdviceRepository = changePasswordAdviceRepository ;
97
82
return this ;
98
83
}
99
84
100
- public PasswordManagementConfigurer <B > changeExistingPasswordAdvisor (
101
- ChangeExistingPasswordAdvisor changePasswordAdvisor ) {
102
- this .changeExistingPasswordAdvisor = changePasswordAdvisor ;
103
- return this ;
104
- }
105
-
106
- public PasswordManagementConfigurer <B > changeUpdatingPasswordAdvisor (
107
- ChangeUpdatingPasswordAdvisor changePasswordAdvisor ) {
108
- this .changeUpdatingPasswordAdvisor = changePasswordAdvisor ;
85
+ public PasswordManagementConfigurer <B > changePasswordAdvisor (
86
+ ChangePasswordAdvisor changePasswordAdvisor ) {
87
+ this .changePasswordAdvisor = changePasswordAdvisor ;
109
88
return this ;
110
89
}
111
90
@@ -136,26 +115,22 @@ public void init(B http) throws Exception {
136
115
: this .context .getBeanProvider (ChangePasswordAdviceRepository .class )
137
116
.getIfUnique (HttpSessionChangePasswordAdviceRepository ::new );
138
117
139
- ChangeExistingPasswordAdvisor changeExistingPasswordAdvisor = (this .changeExistingPasswordAdvisor != null )
140
- ? this .changeExistingPasswordAdvisor
141
- : this .context .getBeanProvider (ChangeExistingPasswordAdvisor .class )
142
- .getIfUnique (() -> DelegatingChangePasswordAdvisor .forExisting (
118
+ ChangePasswordAdvisor changePasswordAdvisor = (this .changePasswordAdvisor != null )
119
+ ? this .changePasswordAdvisor
120
+ : this .context .getBeanProvider (ChangePasswordAdvisor .class )
121
+ .getIfUnique (() -> DelegatingChangePasswordAdvisor .of (
143
122
new ChangePasswordServiceAdvisor (passwordManager ), new ChangeCompromisedPasswordAdvisor ()));
144
- ChangeUpdatingPasswordAdvisor changeUpdatingPasswordAdvisor = (this .changeExistingPasswordAdvisor != null )
145
- ? this .changeUpdatingPasswordAdvisor : this .context .getBeanProvider (ChangeUpdatingPasswordAdvisor .class )
146
- .getIfUnique (ChangeCompromisedPasswordAdvisor ::new );
147
123
148
124
http .setSharedObject (ChangePasswordAdviceRepository .class , changePasswordAdviceRepository );
149
125
http .setSharedObject (UserDetailsPasswordManager .class , passwordManager );
150
- http .setSharedObject (ChangeUpdatingPasswordAdvisor .class , changeUpdatingPasswordAdvisor );
151
126
152
127
FormLoginConfigurer form = http .getConfigurer (FormLoginConfigurer .class );
153
128
String passwordParameter = (form != null ) ? form .getPasswordParameter () : "password" ;
154
129
http .getConfigurer (SessionManagementConfigurer .class )
155
130
.addSessionAuthenticationStrategy ((authentication , request , response ) -> {
156
131
UserDetails user = (UserDetails ) authentication .getPrincipal ();
157
132
String password = request .getParameter (passwordParameter );
158
- ChangePasswordAdvice advice = changeExistingPasswordAdvisor .advise (user , password );
133
+ ChangePasswordAdvice advice = changePasswordAdvisor .advise (user , password );
159
134
changePasswordAdviceRepository .savePasswordAdvice (request , response , advice );
160
135
});
161
136
}
@@ -173,28 +148,10 @@ public void configure(B http) throws Exception {
173
148
return ;
174
149
}
175
150
176
- PasswordEncoder passwordEncoder = this .context .getBeanProvider (PasswordEncoder .class )
177
- .getIfUnique (PasswordEncoderFactories ::createDelegatingPasswordEncoder );
178
-
179
151
ChangePasswordAdviceHandler changePasswordAdviceHandler = (this .changePasswordAdviceHandler != null )
180
152
? this .changePasswordAdviceHandler : this .context .getBeanProvider (ChangePasswordAdviceHandler .class )
181
153
.getIfUnique (() -> new SimpleChangePasswordAdviceHandler (this .changePasswordPage ));
182
154
183
- if (!this .customChangePasswordPage ) {
184
- DefaultChangePasswordPageGeneratingFilter page = new DefaultChangePasswordPageGeneratingFilter ();
185
- http .addFilterBefore (page , RequestCacheAwareFilter .class );
186
- }
187
-
188
- ChangePasswordProcessingFilter processing = new ChangePasswordProcessingFilter (
189
- http .getSharedObject (UserDetailsPasswordManager .class ));
190
- processing
191
- .setRequestMatcher (PathPatternRequestMatcher .withDefaults ().matcher (this .changePasswordProcessingUrl ));
192
- processing .setChangePasswordAdvisor (http .getSharedObject (ChangeUpdatingPasswordAdvisor .class ));
193
- processing .setChangePasswordAdviceRepository (http .getSharedObject (ChangePasswordAdviceRepository .class ));
194
- processing .setPasswordEncoder (passwordEncoder );
195
- processing .setSecurityContextHolderStrategy (getSecurityContextHolderStrategy ());
196
- http .addFilterBefore (processing , RequestCacheAwareFilter .class );
197
-
198
155
ChangePasswordAdvisingFilter advising = new ChangePasswordAdvisingFilter ();
199
156
advising .setChangePasswordAdviceRepository (http .getSharedObject (ChangePasswordAdviceRepository .class ));
200
157
advising .setChangePasswordAdviceHandler (changePasswordAdviceHandler );
0 commit comments