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

웹 페이지의 현재 컨텍스트 경로를 기반으로하여 유효성 검사를 시도하고 있습니다. 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"> 

이것은 당신이 항상 곁에 < your_application_context>/j_spring_security_check에 게시 보장합니다. JSTL에 대한

참조 : http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/url.html

관련 문제