2012-12-28 294 views
0

使用彈簧安全保護我休息的WebService春季安全mysuccessHandler

我有一個usue這是

該類org.rest.security.MySavedRequestAwareAuthenticationSuccessHandler

<?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:tx="http://www.springframework.org/schema/tx" 
    xmlns:c="http://www.springframework.org/schema/c" 
    xmlns:security="http://www.springframework.org/schema/security" 
    xsi:schemaLocation="http://www.springframework.org/schema/oxm  http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd 
     http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
     http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 
    <security:http entry-point-ref="restAuthenticationEntryPoint"> 
     <security:intercept-url pattern="/api/admin/**" access="ROLE_ADMIN"/> 

     <security:custom-filter ref="myFilter" position="FORM_LOGIN_FILTER"/> 


    </security:http> 
    <bean id="mydataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" 
      value="jdbc:mysql://127.0.0.1:3306/VconfGwDb?autoReconnect=true" /> 
     <property name="username" value="***" /> 
     <property name="password" value="****" /> 
     <property name="validationQuery" value="Select 1"></property> 
    </bean> 

    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="mydataSource" /> 
     <property name="annotatedClasses"> 
      <list> 
       <value>com.alpha.vconf.model.Participation</value> 
       <value>com.alpha.vconf.model.ParticipationId</value> 
       <value>com.**.**.model.***</value> 
       <value>com.**.*.model.**</value> 
       <value>com.***.**.model.**</value> 
       <value>com.**.**.model.***</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop> 
      </props> 
     </property> 
    </bean> 
    <bean id="transactionManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 
    <bean id="myFilter" class= 
    "org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
     <property name="authenticationManager" ref="authenticationManager"/> 
     <property name="authenticationSuccessHandler" ref="mySuccessHandler"/> 
    </bean> 
    <bean id="mySuccessHandler" 
    class="org.rest.security.MySavedRequestAwareAuthenticationSuccessHandler"/> 

    <security:authentication-manager alias="authenticationManager"> 
     <security:authentication-provider> 
     <security:user-service> 
      <security:user name="temporary" password="temporary" authorities="****"/> 
      <security:user name="***" password="***" authorities="***"/> 
     </security:user-service> 
     </security:authentication-provider> 
    </security:authentication-manager> 
    <tx:annotation-driven transaction-manager="transactionManager" /> 
    <context:annotation-config /> 
    <context:component-scan base-package="com.***.***"></context:component-scan> 
</beans> 

所以問題是: - ''org.rest.security.MySavedRequestAwareAuthenticationSuccessHandler'不是 找到了我該如何解決此問題

+0

該類的聲音不存在於類路徑中,你是該類的所有者還是應該放在jar中? – Dani

回答

1

org.rest.security.MySavedRequestAwareAuthenticationSuccessHandler必須在WEB-INF/classes或在一個JAR WEB-INF/lib但我想你知道這一點。你有什麼異常?請注意,NoClassDefFoundErrorClassNotFoundException之間有區別。

編輯

在任何情況下,你的成功處理程序必須是org.springframework.security.web.authentication.AuthenticationSuccessHandler的實現。你要麼提供自己的(改變晦澀com.rest.yadayada類名到類的名稱)或刪除此行

<property name="authenticationSuccessHandler" ref="mySuccessHandler"/> 

使用默認的成功處理程序。

+0

我還沒有得到一個異常,但在我的application-context.xml中,這行是紅色突出顯示的,錯誤是:在這一行找到了多個註釋: - 找不到類'org.rest.security.MySavedRequestAwareAuthenticationSuccessHandler' - 我的 – AhmedDrira

+0

lib文件夾中沒有包含此類的jar – AhmedDrira

+0

老兄,也許你應該告訴我們你正在關注在線教程?或者,當您搜索'org.rest.security.MySavedRequestAwareAuthenticationSuccessHandler'時,Google提出http://www.javacodegeeks.com/2011/11/securing-restful-web-service-with.html是巧合嗎?它有一個看起來就像你的Spring配置...我會編輯我的答案,你可能會接受它。 –