2011-09-09 7 views
1

ユーザーにログインし、パスワードを確認し、いくつかのリソースや方法を保護するためにLoginControllerを実装する必要があります。春のセキュリティでログインしたユーザーのパスワードを問い合わせる

シナリオ1) システムにログインしていないとします。彼はlogin.jspにリダイレクトする必要があるときにメソッドにアクセスしようとします。ログインプロセスの後、元の場所から来た適切なURLにリダイレクトする必要があります。

シナリオ2) ユーザーには既にログインし、保護された方法にアクセスしようとします。パスワードを再度確認するためにverifyPassword.jspにリダイレクトする必要があります。

シナリオ1はうまく動作します。

私はログインを依頼する方法のために注釈を使用し、私のsecurity.xmlに

<security:global-method-security 
     secured-annotations="enabled" 
     jsr250-annotations="disabled" 
     access-decision-manager-ref="accessDecisionManager" 
    /> 




<security:http entry-point-ref="authEntryPoint" access-denied-page="/accessdenied.action" access-decision-manager-ref="accessDecisionManager" > 
     <security:intercept-url pattern="/js/**" filters="none" /> 

     <security:anonymous/> 

     <security:http-basic /> 
     <security:port-mappings > 
      <security:port-mapping http="8080" https="443"/> 
     </security:port-mappings> 
     <security:logout invalidate-session="true" /> 
     <security:custom-filter position="FORM_LOGIN_FILTER" ref="customizedFormLoginFilter"/> 
    </security:http> 


<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"> 
     <constructor-arg index="0" value="256" /> 
    </bean> 



<bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl"> 
     <property name="hierarchy"> 
      <value> 
       ROLE_PORTAL_RESTRICTED_USER > ROLE_USER 
      </value> 
     </property> 
    </bean> 

<bean id="userDetailsService" class="org.springframework.security.access.hierarchicalroles.UserDetailsServiceWrapper"> 
     <property name="userDetailsService"> 
      <bean class="com.java.CustomeUserDetails" /> 
     </property> 
     <property name="roleHierarchy" ref="roleHierarchy" /> 
    </bean> 

<bean id="authEntryPoint" class="org.springframework.security.web.authentication.AuthenticationProcessingFilterEntryPoint"> 
     <property name="forceHttps" value="false" /> 
     <property name="loginFormUrl" value="/login.action" /> 

     <property name="portMapper"> 
      <bean class="org.springframework.security.web.PortMapperImpl"> 
       <property name="portMappings"> 
        <map> 
         <entry key="8080" value="443"/> 
        </map> 
       </property> 
      </bean> 
     </property> 
    </bean> 


<bean id="customizedFormLoginFilter" 

     class ="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" > 
     <property name="allowSessionCreation" value="true" /> 
     <property name="filterProcessesUrl" value="/j_spring_security_check" /> 
     <property name="authenticationManager" ref="authenticationManager" /> 
     <property name="authenticationFailureHandler" ref="failureHandler" /> 
     <property name="authenticationSuccessHandler" ref="successHandler" /> 
    </bean> 

    <bean id="successHandler" 
     class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> 
      <property name="alwaysUseDefaultTargetUrl" value="false"/> 
     <property name="defaultTargetUrl" value="/loginsuccess.action" /> 
    </bean> 

    <bean id="failureHandler" 
     class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
     <property name="defaultFailureUrl" value="/loginfailed.action" /> 
    </bean> 



    <security:authentication-manager alias="authenticationManager"> 
     <security:authentication-provider user-service-ref="userDetailsService"> 
      <security:password-encoder ref="passwordEncoder"> 
       <security:salt-source user-property="username" /> 
      </security:password-encoder> 

     </security:authentication-provider> 

    </security:authentication-manager> 

を使用しています。

@Secured("ROLE_USER") 
    public ModelAndView protectedMethod() 

私はすべての情報を私に与えました。ログインしたユーザーのためにverifypin.jspにリダイレクトする方法。

私に提案してください。

答えて

0

このシナリオでは、春のセキュリティのためのソリューションはありませんので、自分で実装する必要があります。解決策のアイデアは、新しいロール "ROLE_VERIFIEDPIN"を定義することです。このロールをメソッドの保護されたアノテーションに追加します。セキュリティで保護されたメソッドを呼び出すWebコントローラメソッドに、このロールの手書き(if文)チェックを追加します。用途にピンの役割が確認されている場合は、保護されたメソッドを呼び出し、確認ページにリダイレクトしないでください。検証が成功した場合は、彼に役割を与え、 "傍受された"制御メソッドを呼び出す。

+0

Ralph、ありがとうございました。まだ私はこの答えについてはっきりしていません。理解するためにいくつかのサンプルコードまたは擬似コードを与えてください。ありがとうございました – Steve

関連する問題