2013-03-12 5 views
12

私は春のセキュリティの仕組みを学びたいので、いくつかのサンプルプロジェクトをダウンロードしてから、そのソリューションを自分のプロジェクトに実装しようとしました。しかし、私がログインしようとすると、私は404エラーを取得し、アドレスバーにはhttp://localhost:8080/fit/j_spring_security_checkがあります。私はここで同様の質問を見ようとしましたが、私は自分のプロジェクトにそれをどのように適用するかを認識できませんでした。もっと経験豊富な人が私を助けてくれたら本当に感謝しています。春3セキュリティj_spring_security_check

マイアプリの構造は次のようになります。

enter image description here

applicationContext.xmlを:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:security="http://www.springframework.org/schema/security" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

<context:annotation-config/> 

<context:component-scan base-package="cz.cvut.fit"/> 

<import resource="classpath:applicationContext-security.xml"/> 

</beans> 

のApplicationContext-web.xmlの:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:security="http://www.springframework.org/schema/security" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

<context:annotation-config/> 

<context:component-scan base-package="cz.cvut.fit" /> 

<mvc:annotation-driven /> 

<security:global-method-security jsr250-annotations="enabled" 
           proxy-target-class="true"/> 
</beans> 

のApplicationContext-のsecurity.xml:

<beans xmlns:security="http://www.springframework.org/schema/security" 
    xmlns="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-3.0.xsd 
      http://www.springframework.org/schema/security 
      http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

<security:http pattern="/css/**" security="none"/> 
<security:http pattern="/views/login.jsp*" security="none"/> 
<security:http pattern="/views/denied.jsp" security="none"/> 

<security:http auto-config="true" access-denied-page="/denied.jsp" servlet-api-provision="false"> 
    <security:intercept-url pattern="/views/login.jsp*" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 
    <security:intercept-url pattern="/views/edit/**" access="ROLE_EDIT"/> 
    <security:intercept-url pattern="/views/admin/**" access="ROLE_ADMIN"/> 
    <security:intercept-url pattern="/**" access="ROLE_USER"/> 
    <security:form-login login-page="/views/login.jsp" authentication-failure-url="/denied.jsp" 
         default-target-url="/home.jsp"/> 
    <security:logout/> 
</security:http> 

<security:authentication-manager> 
    <security:authentication-provider> 
     <security:user-service> 
      <security:user name="adam" password="adampassword" authorities="ROLE_USER"/> 
      <security:user name="jane" password="janepassword" authorities="ROLE_USER, ROLE_ADMIN"/> 
      <security:user name="sue" password="suepassword" authorities="ROLE_USER, ROLE_EDIT"/> 
     </security:user-service> 
    </security:authentication-provider> 
</security:authentication-manager> 

</beans> 
+7

'j_spring_security_check'は、実際の認証が行われ、あなたは、このサーブレットにログインフォームのアクションをマップする必要がありサーブレットです。あなたのログインページでこれをやっていますか? '

...
'? – Lion

+1

web.xmlを表示してください。/j_spring_security_check URLはspringSecurityFilterChainフィルタで処理する必要があります。 –

+0

はい、私は...しかし、私はそれがうまくさせるために、次に何をするか、手がかりがありません。 : -/ – Dworza

答えて

9

Webページの現在のコンテキストパスに基づいて、URIを検証しようとしています。 JSTLタグlibを使用すると、アプリケーションのコンテキストに基づいて正しいURLを簡単に生成できるようになります。これを迅速に実装するには、タグライブラリを使用します。これを行うには、JSPの先頭にJSTLタグライブラリを追加することができます。

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

が次にログイン・サーブレットに投稿するには、以下のことができます。

<form action="<c:url value="/j_spring_security_check"></c:url>" method="post" role="form"> 

これはなかれ>/j_spring_security_check < your_application_contextに投稿保証します。 JSTLのための

参照: http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/url.html

関連する問題