質問編集履歴
7
実装の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -180,7 +180,7 @@
|
|
180
180
|
|
181
181
|
.successHandler(new AppAuthenticationSuccessHandler())
|
182
182
|
|
183
|
-
.usernameParameter("
|
183
|
+
.usernameParameter("name")
|
184
184
|
|
185
185
|
.passwordParameter("password")
|
186
186
|
|
6
実装の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -202,7 +202,7 @@
|
|
202
202
|
|
203
203
|
|
204
204
|
|
205
|
-
// private static final Logger logger = LoggerFactory.getLogger("
|
205
|
+
// private static final Logger logger = LoggerFactory.getLogger("test_log");
|
206
206
|
|
207
207
|
private SessionRegistry sessionRegistry;
|
208
208
|
|
5
実装の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -316,6 +316,48 @@
|
|
316
316
|
|
317
317
|
|
318
318
|
|
319
|
+
AppAuthenticationProvider.java
|
320
|
+
|
321
|
+
```Java
|
322
|
+
|
323
|
+
public class AppAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
|
324
|
+
|
325
|
+
@Override
|
326
|
+
|
327
|
+
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
|
328
|
+
|
329
|
+
throws AuthenticationException {
|
330
|
+
|
331
|
+
System.out.println("ユーザー名:" + username);
|
332
|
+
|
333
|
+
System.out.println("パスワード:" + authentication.getCredentials().toString());
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
// 動作確認のため一旦、例外をスローする
|
338
|
+
|
339
|
+
throw new AuthenticationException("ログインに失敗") {
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
/**
|
344
|
+
|
345
|
+
*
|
346
|
+
|
347
|
+
*/
|
348
|
+
|
349
|
+
private static final long serialVersionUID = 1L;
|
350
|
+
|
351
|
+
};
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
```
|
358
|
+
|
359
|
+
|
360
|
+
|
319
361
|
pom.xml
|
320
362
|
|
321
363
|
```xml
|
4
実装の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -224,8 +224,6 @@
|
|
224
224
|
|
225
225
|
public FirewalledRequest getFirewalledRequest(HttpServletRequest request) throws RequestRejectedException {
|
226
226
|
|
227
|
-
// logger.debug("Portal Firewall Check [IN]");
|
228
|
-
|
229
227
|
System.out.println("検知したリクエストURL:" + request.getRequestURL());
|
230
228
|
|
231
229
|
|
3
実装の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -194,6 +194,130 @@
|
|
194
194
|
|
195
195
|
|
196
196
|
|
197
|
+
AppHttpFirewall.java
|
198
|
+
|
199
|
+
```java
|
200
|
+
|
201
|
+
public class AppHttpFirewall extends StrictHttpFirewall {
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
// private static final Logger logger = LoggerFactory.getLogger("dm_log");
|
206
|
+
|
207
|
+
private SessionRegistry sessionRegistry;
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
public AppHttpFirewall(SessionRegistry sessionRegistry) {
|
212
|
+
|
213
|
+
super();
|
214
|
+
|
215
|
+
this.sessionRegistry = sessionRegistry;
|
216
|
+
|
217
|
+
return;
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
@Override
|
224
|
+
|
225
|
+
public FirewalledRequest getFirewalledRequest(HttpServletRequest request) throws RequestRejectedException {
|
226
|
+
|
227
|
+
// logger.debug("Portal Firewall Check [IN]");
|
228
|
+
|
229
|
+
System.out.println("検知したリクエストURL:" + request.getRequestURL());
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
String userId = "";
|
234
|
+
|
235
|
+
String cookieCerfToken = null;
|
236
|
+
|
237
|
+
String userAgent = request.getHeader("user-agent");
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
Cookie csrfToken = WebUtils.getCookie(request, "_csrf");
|
242
|
+
|
243
|
+
if(Objects.nonNull(csrfToken)) {
|
244
|
+
|
245
|
+
cookieCerfToken = csrfToken.getValue();
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
// セッションレジストリーからユーザー情報を取得しユーザIDを取得する
|
252
|
+
|
253
|
+
SessionInformation sessionInfo = sessionRegistry.getSessionInformation(request.getSession().getId());
|
254
|
+
|
255
|
+
if(Objects.nonNull(sessionInfo)) {
|
256
|
+
|
257
|
+
Object principal = sessionInfo.getPrincipal();
|
258
|
+
|
259
|
+
if(principal instanceof UserDetails) {
|
260
|
+
|
261
|
+
DMUser user = (DMUser) principal;
|
262
|
+
|
263
|
+
userId = user.getUser().getUserId();
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
try {
|
272
|
+
|
273
|
+
return super.getFirewalledRequest(request);
|
274
|
+
|
275
|
+
} catch (RequestRejectedException e) {
|
276
|
+
|
277
|
+
// 認証情報をクリアする
|
278
|
+
|
279
|
+
SecurityContextHolder.clearContext();
|
280
|
+
|
281
|
+
request.getSession().invalidate();
|
282
|
+
|
283
|
+
// logger.error("リクエストURL不正")
|
284
|
+
|
285
|
+
return new FirewalledRequest(request) {
|
286
|
+
|
287
|
+
@Override
|
288
|
+
|
289
|
+
public void reset() {
|
290
|
+
|
291
|
+
return;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
};
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
@Override
|
304
|
+
|
305
|
+
public HttpServletResponse getFirewalledResponse(HttpServletResponse response) {
|
306
|
+
|
307
|
+
// TODO 自動生成されたメソッド・スタブ
|
308
|
+
|
309
|
+
return super.getFirewalledResponse(response);
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
```
|
318
|
+
|
319
|
+
|
320
|
+
|
197
321
|
pom.xml
|
198
322
|
|
199
323
|
```xml
|
2
プログラム実装内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -178,7 +178,7 @@
|
|
178
178
|
|
179
179
|
.failureHandler(new AppAuthenticationFailureHandler()) //認証失敗時
|
180
180
|
|
181
|
-
.successHandler(new AppAuthenticationSuccessHandler(
|
181
|
+
.successHandler(new AppAuthenticationSuccessHandler())
|
182
182
|
|
183
183
|
.usernameParameter("user")
|
184
184
|
|
1
クラスを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -122,6 +122,78 @@
|
|
122
122
|
|
123
123
|
|
124
124
|
|
125
|
+
AppSecurityConfig.java
|
126
|
+
|
127
|
+
```Java
|
128
|
+
|
129
|
+
@Configuration
|
130
|
+
|
131
|
+
@EnableWebSecurity
|
132
|
+
|
133
|
+
public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
|
134
|
+
|
135
|
+
@Override
|
136
|
+
|
137
|
+
public void configure(WebSecurity web) throws Exception {
|
138
|
+
|
139
|
+
web.ignoring().antMatchers("/css/**", "/js/**");
|
140
|
+
|
141
|
+
web.httpFirewall(new AppHttpFirewall(sessionRegistry));
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
@Override
|
148
|
+
|
149
|
+
protected void configure(HttpSecurity http) throws Exception {
|
150
|
+
|
151
|
+
http.sessionManagement()
|
152
|
+
|
153
|
+
.maximumSessions(1)
|
154
|
+
|
155
|
+
.maxSessionsPreventsLogin(true)
|
156
|
+
|
157
|
+
.sessionRegistry(sessionRegistry())
|
158
|
+
|
159
|
+
.and()
|
160
|
+
|
161
|
+
.sessionFixation().newSession();
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
http.authorizeRequests()
|
166
|
+
|
167
|
+
.mvcMatchers(HttpMethod.GET, "/").permitAll()
|
168
|
+
|
169
|
+
.mvcMatchers(HttpMethod.POST, "/register", "/authenticate").permitAll()
|
170
|
+
|
171
|
+
.anyRequest().authenticated();
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
http.formLogin()
|
176
|
+
|
177
|
+
.loginProcessingUrl("/authenticate") // ログイン処理URL
|
178
|
+
|
179
|
+
.failureHandler(new AppAuthenticationFailureHandler()) //認証失敗時
|
180
|
+
|
181
|
+
.successHandler(new AppAuthenticationSuccessHandler(dmCryptoConfigurtion))
|
182
|
+
|
183
|
+
.usernameParameter("user")
|
184
|
+
|
185
|
+
.passwordParameter("password")
|
186
|
+
|
187
|
+
.permitAll();
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
|
196
|
+
|
125
197
|
pom.xml
|
126
198
|
|
127
199
|
```xml
|