皆様初めまして
私は現在、Spring3.2の既存のシステムの改修に関わっています。
そこで既存のログイン画面とは別にログイン画面を設け、新しいログイン画面(管理者用)からは別の認証方法でログインをさせるという処理を実装をしている部分でつまづいております。
以下、Spring security3.2のソースになります
java
1<?xml version="1.0" encoding="UTF-8"?> 2<beans:beans xmlns="http://www.springframework.org/schema/security" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:beans="http://www.springframework.org/schema/beans" 5 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 6 xsi:schemaLocation=" 7 http://www.springframework.org/schema/beans 8 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 9 http://www.springframework.org/schema/security 10 http://www.springframework.org/schema/security/spring-security-3.2.xsd 11 http://www.springframework.org/schema/context 12 http://www.springframework.org/schema/context/spring-context.xsd"> 13 14 <!-- 静的リソースは認証対象外 --> 15 <http pattern="/resources/**" security="none"/> 16 <!-- APIリソースは認証対象外 --> 17 <http pattern="/api/**" security="none"/> 18 <!-- Login画面は認証対象外 --> 19 <http pattern="/user/login*" security="none" /> 20 <http pattern="/user/login/error*" security="none" /> 21 22 <!-- 管理者用の設定 start --> 23 <http pattern="/admin**" auto-config="false" entry-point-ref="loginUrlAuthenticationEntryPoint" > 24 <custom-filter 25 position="FORM_LOGIN_FILTER" 26 ref="applicationUsernamePasswordAuthenticationFilter" /> 27 <logout logout-url="/user/logout" logout-success-url="/user/login?timeout=false" invalidate-session="true" /> 28 </http> 29 <!-- 管理者用の設定 end --> 30 31 <http auto-config="true" authentication-manager-ref="userAuthenticationManager"> 32 <intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER" /> 33 <!-- ユーザの設定 --> 34 <form-login 35 login-page="/user/login?timeout=false" 36 default-target-url="/user/index" 37 authentication-failure-url="/user/login/error?errorType=typeMiss" 38 login-processing-url="/j_spring_security_check" 39 always-use-default-target="true" /> 40 <logout logout-url="/user/logout" 41 logout-success-url="/user/login?timeout=false" 42 invalidate-session="true" /> 43 <anonymous granted-authority="ROLE_ANONYMOUS" /> 44 <access-denied-handler error-page="/user/login/error?errorType=noAuthority" /> 45 </http> 46 47 <context:property-placeholder location="classpath:jdbc.properties"/> 48 49 <!-- データソースの設定 --> 50 <beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 51 <beans:property name="driverClassName" value="${jdbc.driverClassName}" /> 52 <beans:property name="url" value="${jdbc.url}" /> 53 <beans:property name="username" value="${jdbc.username}" /> 54 <beans:property name="password" value="${jdbc.password}" /> 55 </beans:bean> 56 57 <authentication-manager id="userAuthenticationManager"> 58 <authentication-provider> 59 <password-encoder hash="sha-256" > 60 <salt-source user-property="username" /> 61 </password-encoder> 62 63 <jdbc-user-service data-source-ref="dataSource" 64 users-by-username-query=" 65 select 66 login_id as username 67 , login_password as password 68 , true as enabled 69 from 70 m_login 71 where 72 login_id=? 73 and delete_flg = 0" 74 authorities-by-username-query=" 75 select 76 login_id as username 77 , login_authority as authority 78 from 79 m_login 80 where 81 login_id=?" /> 82 </authentication-provider> 83 </authentication-manager> 84 85 <beans:bean id="userDetailsService" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl"> 86 <beans:property name="dataSource" ref="dataSource"/> 87 </beans:bean> 88 89 90 <beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> 91 <beans:constructor-arg value="/admin/test" /> 92 </beans:bean> 93 94 <beans:bean id="applicationUsernamePasswordAuthenticationFilter" class="com.capitarise.xxxx.admin.filter.ApplicationUsernamePasswordAuthenticationFilter"> 95 <beans:property name="authenticationManager" ref="adminAuthenticationManager" /> 96 <beans:property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" /> 97 <beans:property name="authenticationFailureHandler" ref="authenticationFailureHandler" /> 98 <beans:property name="filterProcessesUrl" value="/authentication" /> 99 </beans:bean> 100 101 <beans:bean id="authenticationSuccessHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler"> 102 <beans:property name="defaultTargetUrl" value="/admin/check"/> 103 </beans:bean> 104 105 <!-- 気になる箇所① --> 106 <beans:bean id="authenticationFailureHandler" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler"> 107 <beans:property name="defaultFailureUrl" value="/admin/test"/> 108 </beans:bean> 109 110 <authentication-manager alias="adminAuthenticationManager"> 111 <authentication-provider ref="applicationUsernamePasswordAuthenticationProvider" /> 112 </authentication-manager> 113 114 <beans:bean id="applicationUsernamePasswordAuthenticationProvider" class="com.capitarise.xxxx.admin.provider.ApplicationUsernamePasswordAuthenticationProvider"> 115 </beans:bean> 116 117</beans:beans>
上記のように修正し「/admin/test」のURLを叩いてみたところ、上記の「ユーザの設定」に記載されている「/user/login?timeout=false」に飛んでしまいました。
私の認識としては、「/admin」の場合は「気になる箇所①」で設定した「/admin/test」に、
それ以外は「/user/login?timeout=false」が最初に開かれる想定であったのですが、私の認識が間違っているようでした・・
どの部分を直せば想定通り「/admin/test」からログインページを開き別の処理を行えるのか、ご存知の方がいらっしゃいましたら、ご教授願えますでしょうか?
宜しくお願い致します。
Springのバージョン:3.2.2
Spring Security:3.2.10
参考サイト
あなたの回答
tips
プレビュー