2017-06-12 17 views
1

私は春のセキュリティ4を認証に使用しています。 私はログインページにリダイレクトできますが、その後は私はさらに移動できませんこのlocalhostのページはここ春のセキュリティを使用して認証できません。資格情報を入力した後

は私のweb.xmlのである。ここ

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
id="WebApp_ID" version="3.1"> 
     <display-name>self-thin-client</display-name> 
     <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
     <welcome-file>index.htm</welcome-file> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
     <welcome-file>default.htm</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
     </welcome-file-list> 

     <listener> 
      <listener-class> 
       org.springframework.web.context.ContextLoaderListener 
      </listener-class> 
     </listener> 
     <context-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/security.xml</param-value> 
     </context-param> 
     <filter> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
     </filter> 
     <filter-mapping> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <url-pattern>/rs/self/*</url-pattern> 
     </filter-mapping> 

     <servlet> 
      <servlet-name>dspature</servlet-name> 
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
      <load-on-startup>1</load-on-startup> 
     </servlet> 
     <servlet-mapping> 
      <servlet-name>dspature</servlet-name> 
      <url-pattern>/rs/*</url-pattern> 
     </servlet-mapping> 

     <servlet> 
      <servlet-name>Initializer</servlet-name> 
      <servlet-class>com.store.Initializer</servlet-class> 
      <load-on-startup>1</load-on-startup> 
     </servlet> 
    </web-app> 

は私のsecurity.xmlが

<beans:beans xmlns="http://www.springframework.org/schema/security" 
       xmlns:beans="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-4.0.xsd"> 


     <!-- Spring MVC based authentication, login page etc. --> 
     <http> 
      <intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')"/> 
      <form-login login-page="/rs/login" login-processing-url="/j_spring_security_check" 
         authentication-failure-url="/login" /> 
      <logout logout-success-url="/login"/> 
     </http> 

     <!-- Declared authentication manager --> 
     <authentication-manager alias="authenticationManager"> 
      <authentication-provider ref="AuthenticationManager" /> 
     </authentication-manager> 

     <!-- Bean implementing AuthenticationProvider of Spring Security --> 
     <beans:bean id="AuthenticationManager" class="com.radix.server.login.AuthenticationManager"> 
     </beans:bean> 

    </beans:beans> 
で見つけることができませんここでは0

が私のHTMLフォーム、

<form method="post" action="/j_spring_security_check" > 
    <p> 
     <span>Username:</span> 
     <input type="text" name= "j_username" > 
    </p> 
    <p> 
     <span>Password:</span> 
     <input type="password" name= "j_password" > 
    </p> 
    <p> 
     <input type="submit" value="submit"> 
    </p> 
    </form> 

である私は、問題がURLマッピングであるかもしれないと思いますが、私はそれと間違って何をしたか、それを把握することはできないんだけど、それ

答えて

1

変更で私を助けてくださいweb.xmlでこのマッピングをこのように:彼らは正常に実行されませんので

<filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
</filter-mapping> 

そうでない場合は、お使いのlogin-processing-urlなどがFilterChainProxy URLパターンと一致しません。

EDIT:CSRFを防ぐために、あなたの<security:http>要素内にこれを試してみてください。私は、このような特定のパス/rs/self/*ためspringSecurityFilterChainのベースパスを設定し、前に言ったように、

<security:csrf disabled="true"/>

しかし、私は考えていませんいい考えだね。具体的には、全く意味がありません。 <security:http>要素によれば、すべてのURLをアプリ(<intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')"/>)で保護したいと思われますが、springSecurityFilterChainはURLの一致する `/ rs/self/* 'に対してのみ起動されます。

<http pattern="/rs/login" security="none"/> 
<http> 
    <intercept-url pattern="/**" access="hasRole('ROLE_ADMIN')"/> 
    <form-login login-page="/rs/login" login-processing-url="/j_spring_security_check" 
       authentication-failure-url="/login" /> 
    <logout logout-success-url="/login"/> 
    <csrf disabled="true"/> 
</http> 

ログアウト成功URLは、ログインフォームのURLと一致していないが、それはそうです:

のWeb.xml:

<filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
</filter-mapping> 

のsecurity.xmlを

このようにしてみてくださいあなたは同じになりたいこのようにしたい場合は、<logout logout-success-url="/rs/login" />

EDIT2: 最後のコメントは、最後の問題はJSPフォームアクションです。このように行動を変えてみてください:

<form method="post" action="/your_app_context/j_spring_security_check" > 
+0

私には意味がありません。質問を投稿した最初の問題がログインが正しく機能していなかった場合、ログインはどのように機能しなくなりましたか?実際には、あなたの設定を読んでも、 '/ rs/self'や'/rs'は実際にあなたのコンテキスト名であったとは言いません...もし本当にアプリケーションのコンテキスト名であれば、 'security:http'要素を構成しており、内部の' intercept-url'要素です。最後に 'rs'や' rs/self'があなたのアプリケーションコンテキスト/ war名であれば 'web.xml'や' security.xml'や他のコントローラで使うマッピングURLに含めないでください。 – jlumietu

+0

jsp形式のログイン/ rs/self/j_spring_security_checkでハードコーディングしています。もし私が

+0

の代わりにcontext.xml}/j_spring_security_check ">フィルタをsecurity.xmlにリダイレクトすることはできません –

関連する問題