質問編集履歴
2
最後の質問部分を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -258,7 +258,7 @@
|
|
258
258
|
|
259
259
|
|
260
260
|
|
261
|
-
|
261
|
+
どの部分を直せば想定通り「/admin/test」からログインページを開き別の処理を行えるのか、ご存知の方がいらっしゃいましたら、ご教授願えますでしょうか?
|
262
262
|
|
263
263
|
宜しくお願い致します。
|
264
264
|
|
1
本文の内容に至らない部分が多々あったため修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Spring Securityの複数ログイン画面の実装方法
|
1
|
+
Spring Securityの複数ログイン画面の実装方法について
|
test
CHANGED
@@ -4,15 +4,11 @@
|
|
4
4
|
|
5
5
|
私は現在、Spring3.2の既存のシステムの改修に関わっています。
|
6
6
|
|
7
|
-
そこで既存のログイン画面とは別にログイン画面を設け、新しいログイン画面からは別の認証方法でログインをさせるという
|
7
|
+
そこで既存のログイン画面とは別にログイン画面を設け、新しいログイン画面(管理者用)からは別の認証方法でログインをさせるという処理を実装をしている部分でつまづいております。
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
|
10
|
+
|
15
|
-
以下、Spring security3.2の
|
11
|
+
以下、Spring security3.2のソースになります
|
16
12
|
|
17
13
|
```java
|
18
14
|
|
@@ -46,53 +42,63 @@
|
|
46
42
|
|
47
43
|
<http pattern="/resources/**" security="none"/>
|
48
44
|
|
49
|
-
|
45
|
+
<!-- APIリソースは認証対象外 -->
|
46
|
+
|
47
|
+
<http pattern="/api/**" security="none"/>
|
50
48
|
|
51
49
|
<!-- Login画面は認証対象外 -->
|
52
50
|
|
53
|
-
<http pattern="/
|
51
|
+
<http pattern="/user/login*" security="none" />
|
54
|
-
|
52
|
+
|
55
|
-
<http pattern="/
|
53
|
+
<http pattern="/user/login/error*" security="none" />
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
|
55
|
+
|
56
|
+
|
59
|
-
<
|
57
|
+
<!-- 管理者用の設定 start -->
|
58
|
+
|
60
|
-
|
59
|
+
<http pattern="/admin**" auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint" >
|
60
|
+
|
61
|
+
<custom-filter
|
62
|
+
|
63
|
+
position="FORM_LOGIN_FILTER"
|
64
|
+
|
65
|
+
ref="applicationUsernamePasswordAuthenticationFilter" />
|
66
|
+
|
67
|
+
<logout logout-url="/user/logout" logout-success-url="/user/login?timeout=false" invalidate-session="true" />
|
68
|
+
|
69
|
+
</http>
|
70
|
+
|
61
|
-
|
71
|
+
<!-- 管理者用の設定 end -->
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
<http auto-config="true" authentication-manager-ref="userAuthenticationManager">
|
62
76
|
|
63
77
|
<intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER" />
|
64
78
|
|
65
|
-
|
79
|
+
<!-- ユーザの設定 -->
|
66
80
|
|
67
81
|
<form-login
|
68
82
|
|
69
|
-
login-page="/
|
83
|
+
login-page="/user/login?timeout=false"
|
70
|
-
|
84
|
+
|
71
|
-
default-target-url="/
|
85
|
+
default-target-url="/user/index"
|
72
|
-
|
86
|
+
|
73
|
-
authentication-failure-url="/
|
87
|
+
authentication-failure-url="/user/login/error?errorType=typeMiss"
|
74
88
|
|
75
89
|
login-processing-url="/j_spring_security_check"
|
76
90
|
|
77
91
|
always-use-default-target="true" />
|
78
92
|
|
79
|
-
<!-- ログアウト時の画面制御 -->
|
80
|
-
|
81
|
-
<logout logout-url="/
|
93
|
+
<logout logout-url="/user/logout"
|
82
|
-
|
94
|
+
|
83
|
-
logout-success-url="/
|
95
|
+
logout-success-url="/user/login?timeout=false"
|
84
96
|
|
85
97
|
invalidate-session="true" />
|
86
98
|
|
87
|
-
<!-- anonymousユーザのROLE -->
|
88
|
-
|
89
99
|
<anonymous granted-authority="ROLE_ANONYMOUS" />
|
90
100
|
|
91
|
-
|
92
|
-
|
93
|
-
<access-denied-handler error-page="/
|
101
|
+
<access-denied-handler error-page="/user/login/error?errorType=noAuthority" />
|
94
|
-
|
95
|
-
|
96
102
|
|
97
103
|
</http>
|
98
104
|
|
@@ -118,7 +124,7 @@
|
|
118
124
|
|
119
125
|
|
120
126
|
|
121
|
-
<authentication-manager>
|
127
|
+
<authentication-manager id="userAuthenticationManager">
|
122
128
|
|
123
129
|
<authentication-provider>
|
124
130
|
|
@@ -168,94 +174,98 @@
|
|
168
174
|
|
169
175
|
login_id=?" />
|
170
176
|
|
171
|
-
|
172
|
-
|
173
177
|
</authentication-provider>
|
174
178
|
|
175
179
|
</authentication-manager>
|
176
180
|
|
181
|
+
|
182
|
+
|
183
|
+
<beans:bean id="userDetailsService" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
|
184
|
+
|
185
|
+
<beans:property name="dataSource" ref="dataSource"/>
|
186
|
+
|
187
|
+
</beans:bean>
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
<beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
|
194
|
+
|
195
|
+
<beans:constructor-arg value="/admin/test" />
|
196
|
+
|
197
|
+
</beans:bean>
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<beans:bean id="applicationUsernamePasswordAuthenticationFilter" class="com.capitarise.xxxx.admin.filter.ApplicationUsernamePasswordAuthenticationFilter">
|
202
|
+
|
203
|
+
<beans:property name="authenticationManager" ref="adminAuthenticationManager" />
|
204
|
+
|
205
|
+
<beans:property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" />
|
206
|
+
|
207
|
+
<beans:property name="authenticationFailureHandler" ref="authenticationFailureHandler" />
|
208
|
+
|
209
|
+
<beans:property name="filterProcessesUrl" value="/authentication" />
|
210
|
+
|
211
|
+
</beans:bean>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<beans:bean id="authenticationSuccessHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
|
216
|
+
|
217
|
+
<beans:property name="defaultTargetUrl" value="/admin/check"/>
|
218
|
+
|
219
|
+
</beans:bean>
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
<!-- 気になる箇所① -->
|
224
|
+
|
225
|
+
<beans:bean id="authenticationFailureHandler" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
|
226
|
+
|
227
|
+
<beans:property name="defaultFailureUrl" value="/admin/test"/>
|
228
|
+
|
229
|
+
</beans:bean>
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
<authentication-manager alias="adminAuthenticationManager">
|
234
|
+
|
235
|
+
<authentication-provider ref="applicationUsernamePasswordAuthenticationProvider" />
|
236
|
+
|
237
|
+
</authentication-manager>
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
<beans:bean id="applicationUsernamePasswordAuthenticationProvider" class="com.capitarise.xxxx.admin.provider.ApplicationUsernamePasswordAuthenticationProvider">
|
242
|
+
|
243
|
+
</beans:bean>
|
244
|
+
|
245
|
+
|
246
|
+
|
177
247
|
</beans:beans>
|
178
248
|
|
179
249
|
```
|
180
250
|
|
181
251
|
|
182
252
|
|
183
|
-
上記のソースに参考サイトを基に以下のようなコードを加えてみたりとあがいてみたのですが、ステータスが400で返ってきたり、
|
184
|
-
|
185
|
-
「No mapping found for HTTP request with URI [/pms/j_spring_security_check] in DispatcherServlet with name 'appServlet'」というエラーがコンソールに表示などされて、なかなか前に進めません。
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
```java
|
190
|
-
|
191
|
-
|
253
|
+
上記のように修正し「/admin/test」のURLを叩いてみたところ、上記の「ユーザの設定」に記載されている「/user/login?timeout=false」に飛んでしまいました。
|
192
|
-
|
193
|
-
|
254
|
+
|
194
|
-
|
195
|
-
position="FORM_LOGIN_FILTER"
|
196
|
-
|
197
|
-
ref="applicationUsernamePasswordAuthenticationFilter" />
|
198
|
-
|
199
|
-
</http>
|
200
|
-
|
201
|
-
<beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
|
202
|
-
|
203
|
-
|
255
|
+
私の認識としては、「/admin」の場合は「気になる箇所①」で設定した「/admin/test」に、
|
204
|
-
|
205
|
-
|
256
|
+
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
<beans:bean id="applicationUsernamePasswordAuthenticationFilter" class="com.capitarise.xxxx.admin.filter.ApplicationUsernamePasswordAuthenticationFilter">
|
210
|
-
|
211
|
-
<beans:property name="authenticationManager" ref="adminAuthenticationManager" />
|
212
|
-
|
213
|
-
<beans:property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" />
|
214
|
-
|
215
|
-
<beans:property name="authenticationFailureHandler" ref="authenticationFailureHandler" />
|
216
|
-
|
217
|
-
<beans:property name="filterProcessesUrl" value="/authentication" />
|
218
|
-
|
219
|
-
</beans:bean>
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
<beans:bean id="authenticationSuccessHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
|
224
|
-
|
225
|
-
<beans:property name="defaultTargetUrl" value="/admin/check"/>
|
226
|
-
|
227
|
-
</beans:bean>
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
<beans:bean id="authenticationFailureHandler" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
|
232
|
-
|
233
|
-
<beans:property name="defaultFailureUrl" value="/admin/login"/>
|
234
|
-
|
235
|
-
</beans:bean>
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
257
|
+
それ以外は「/user/login?timeout=false」が最初に開かれる想定であったのですが、私の認識が間違っているようでした・・
|
240
|
-
|
241
|
-
|
258
|
+
|
242
|
-
|
259
|
+
|
260
|
+
|
243
|
-
|
261
|
+
間違っている部分などご存知の方がいらっしゃいましたら、ご教授願えますでしょうか?
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
262
|
+
|
248
|
-
|
249
|
-
|
263
|
+
宜しくお願い致します。
|
250
|
-
|
251
|
-
|
264
|
+
|
265
|
+
|
252
266
|
|
253
267
|
Springのバージョン:3.2.2
|
254
268
|
|
255
269
|
Spring Security:3.2.10
|
256
270
|
|
257
|
-
|
258
|
-
|
259
|
-
|
271
|
+
[参考サイト](http://namihira.hatenablog.com/entry/20160817/1471396975)
|
260
|
-
|
261
|
-
宜しくお願い致します。
|