2012-07-05 132 views
1

我創建了一個簡單的spring用戶應用程序。我正在使用Tomcat進行部署。這是我的web.xmlSpring Security AOP錯誤

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 
    <display-name>ContactSync</display-name> 
    <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>/user/*</url-pattern> 
    </filter-mapping> 
    <servlet> 
     <servlet-name>spring</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
     /WEB-INF/spring-security.xml 
     </param-value> 
    </context-param> 

    <servlet-mapping> 
     <servlet-name>spring</servlet-name> 
     <url-pattern>*.do</url-pattern> 
    </servlet-mapping> 
    <welcome-file-list> 
     <welcome-file>redirect.jsp</welcome-file> 
    </welcome-file-list> 

    <!-- <servlet-mapping> 
     <servlet-name>default</servlet-name> 
     <url-pattern>/static/*</url-pattern> 
    </servlet-mapping> --> 
</web-app> 

我的彈簧security.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: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/security 
    http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 

<!-- This is where we configure Spring-Security --> 
<security:http auto-config="true" use-expressions="true" access-denied-page="/user/denied.do" > 
     <security:intercept-url pattern="/" access="permitAll"/> 
     <security:intercept-url pattern="/user/login.do" access="permitAll"/> 
     <!-- Not using admin role right now --> 
     <!-- <security:intercept-url pattern="/user/admin" access="hasRole('ROLE_ADMIN')"/> --> 
     <security:intercept-url pattern="/user/common.do" access="hasRole('ROLE_USER')"/> 

     <security:form-login 
       login-page="/user/login.do" 
       authentication-failure-url="/user/login.do?error=true" 
       default-target-url="/user/common.do"/> 

     <security:logout 
       invalidate-session="true" 
       logout-success-url="/user/login.do" 
       logout-url="/user/logout.do"/> 


</security:http> 

<security:authentication-manager> 
    <security:authentication-provider> 
    <security:user-service> 
     <security:user name="abcd" password="abcd" authorities="ROLE_USER" /> 
    </security:user-service> 
    </security:authentication-provider> 
</security:authentication-manager> 

</beans> 

我的庫是:

antlr-2.7.6.jar 
antlr-runtime-3.0.1.jar 
commons-collections-3.1.jar 
commons-dbcp-1.4.jar 
commons-logging-1.1.1.jar 
commons-pool-1.5.6.jar 
dom4j-1.6.1.jar 
gson-2.2.1.jar 
hibernate3.jar 
hibernate-annotations-3.5.1-Final.jar 
hibernate-commons-annotations-3.2.0.Final.jar 
j2ee.jar 
javassist-3.4.GA.jar 
javax.persistence-2.0.2.jar 
jstl-1.2.jar 
jta-1.1.jar 
mysql-connector-java-5.1.5.jar 
org.springframework.asm-3.0.1.RELEASE-A.jar 
org.springframework.beans-3.0.1.RELEASE-A.jar 
org.springframework.context.support-3.0.1.RELEASE-A.jar 
org.springframework.context-3.0.1.RELEASE-A.jar 
org.springframework.core-3.0.1.RELEASE-A.jar 
org.springframework.expression-3.0.1.RELEASE-A.jar 
org.springframework.jdbc-3.0.1.RELEASE-A.jar 
org.springframework.orm-3.0.1.RELEASE-A.jar 
org.springframework.transaction-3.0.1.RELEASE-A.jar 
org.springframework.web.servlet-3.0.1.RELEASE-A.jar 
org.springframework.web-3.0.1.RELEASE-A.jar 
slf4j-api-1.5.6.jar 
slf4j-simple-1.5.6.jar 
spring-aop-3.0.1.RELEASE-sources.jar 
spring-security-acl-3.0.1.RELEASE.jar 
spring-security-acl-3.0.1.RELEASE-sources.jar 
spring-security-cas-client-3.0.1.RELEASE.jar 
spring-security-cas-client-3.0.1.RELEASE-sources.jar 
spring-security-config-3.0.1.RELEASE.jar 
spring-security-config-3.0.1.RELEASE-sources.jar 
spring-security-core-3.0.1.RELEASE.jar 
spring-security-core-3.0.1.RELEASE-sources.jar 
spring-security-ldap-3.0.1.RELEASE.jar 
spring-security-ldap-3.0.1.RELEASE-sources.jar 
spring-security-openid-3.0.1.RELEASE.jar 
spring-security-openid-3.0.1.RELEASE-sources.jar 
spring-security-samples-tutorial-3.0.1.RELEASE.war 
spring-security-samples-tutorial-3.0.1.RELEASE-sources.jar 
spring-security-taglibs-3.0.1.RELEASE.jar 
spring-security-taglibs-3.0.1.RELEASE-sources.jar 
spring-security-web-3.0.1.RELEASE.jar 
spring-security-web-3.0.1.RELEASE-sources.jar 
standard-1.1.2.jar 
yuicompressor-2.4.8pre.jar 

試圖訪問登錄文件時,我得到404錯誤。但是我能夠訪問歡迎文件。任何人都可以幫助我解決這個問題。

Error: 

HTTP Status 404 - /Learning/WEB-INF/jsp/loginpage.jsp 

type Status report 

message /Learning/WEB-INF/jsp/loginpage.jsp 

description The requested resource (/Learning/WEB-INF/jsp/loginpage.jsp) is not available. 

我的入口註銷控制器:

package com.contact.test.web; 


import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RequestParam; 

@RequestMapping("/user") 
@Controller 
public class LoginLogoutController{ 

    @RequestMapping(value = "/login.do", method = RequestMethod.GET) 
    public String getLoginPage(@RequestParam(value="error", required=false) boolean error, 
     ModelMap model) { 

     // Add an error message to the model if login is unsuccessful 
     // The 'error' parameter is set to true based on the when the authentication has failed. 
     // We declared this under the authentication-failure-url attribute inside the spring-security.xml 
     /* See below: 
     <form-login 
     login-page="/user/login" 
     authentication-failure-url="/user/login?error=true" 
     default-target-url="/user/common"/>*/ 

     if (error == true) { 
     // Assign an error message 
     model.put("error", "You have entered an invalid username or password!"); 
     } else { 
     model.put("error", ""); 
     } 
     // This will resolve to /WEB-INF/jsp/loginpage.jsp 
     return "loginpage"; 
    } 

    /** 
     * Handles and retrieves the denied JSP page. This is shown whenever a regular user 
     * tries to access an admin only page. 
     * 
     * @return the name of the JSP page 
     */ 
    @RequestMapping(value = "/denied.do", method = RequestMethod.GET) 
     public String getDeniedPage() { 

     // This will resolve to /WEB-INF/jsp/deniedpage.jsp 
     return "deniedpage"; 
    } 
} 

項目的結構是:

/Learning/WebContent 
/Learning/WebContent/META-INF 
/Learning/WebContent/WEB-INF 
/Learning/WebContent/WEB-INF/jsp 
/Learning/WebContent/WEB-INF/jsp/adminpage.jsp 
/Learning/WebContent/WEB-INF/jsp/commonpage.jsp 
/Learning/WebContent/WEB-INF/jsp/deniedpage.jsp 
/Learning/WebContent/WEB-INF/jsp/loginpage.jsp 
/Learning/WebContent/WEB-INF/jsp/userForm.jsp 

回答

0

你有

spring-aop-3.0.1.RELEASE-sources.jar 

它不包含任何編譯的Java類。您需要包括:

spring-aop-3.0.1.RELEASE.jar 

無關這個問題:你還需要各方面的spring-aop-3.0.1.RELEASE.pom.xml

+0

感謝中提及的所需依賴的......現在我能夠訪問歡迎頁面,但無法訪問登錄頁面...請參閱上面的錯誤... – goblin2986 2012-07-07 10:14:52

+0

WEB-INF文件夾中包含的任何資源都不能直接從瀏覽器訪問。您應該將它們移至WebContent文件夾。 – Ravi 2012-07-07 20:17:45

0

據我瞭解,你也需要把這樣的庫,以您的構建路徑:

asm-3.3.1.jar 
aopalliance-1.0.jar 
aspectjrt-1.6.12.jar 
aspectjtools-1.6.12.jar 
aspectjweaver-1.6.12.jar 

版本可能不同,我只是從我的項目中複製了庫的名稱。