2010-03-10 39 views
0

朋友,錯誤使用Spring Security 3.0.2 X春3.0.1 - 代理無法創建

我已經失去了幾天搜索互聯網的答案關於我的問題,並沒有發現任何可能實際解決它。我嘗試了幾種不同的配置,但仍然無濟於事。

這裏是我的問題:

我有工作正常,直到我決定增加春季安全的應用程序。在我介紹這個組件後,我一直在啓動tomcat 6.0.24時收到這些消息:


INFO: Bean 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
Mar 10, 2010 3:46:47 PM org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization 
INFO: Bean 'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
Mar 10, 2010 3:46:47 PM org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization 
INFO: Bean 'org.springframework.security.methodSecurityMetadataSourceAdvisor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
Mar 10, 2010 3:46:48 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 

我沒有收到。因此,現在所有類都不會獲取業務類的代理,而是獲得不提交事務的POJO。我正在使用@PersistenceContext註解並注入EntityManager,但在Spring Security出現後,我一直在獲取NPE(EntityManager不再被注入)。所以,我想延長的JpaDaoSupport和獲得EntityManager的以不同的方式,像這樣:


getJpaTemplate() 
    .execute(new JpaCallback() { 
          public Object doInJpa(final EntityManager em) 
          throws PersistenceException { 
            // Here, I get an EntityManager... 
          } 
         }); 

它的工作原理,因爲現在我沒有得到任何NPE了。但它仍然不是代理。

如果我註釋掉app-security.xml文件並且不加載它的bean,那麼應用程序可以正常工作。如果我這樣做,則不會創建代理,並且應用程序不會提交任何事務。

我的應用程序,security.xml文件是:


[?xml version="1.0" encoding="UTF-8"?] 
[beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:security="http://www.springframework.org/schema/security" 
     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.0.xsd" 
] 

[bean id="interfaceDecisionManagerBean" class="com.mot.br.jag.security.InterfaceDecisionManager" /] 

[security:global-method-security 
     access-decision-manager-ref="interfaceDecisionManagerBean"  
/] 

[security:http auto-config="false" access-decision-manager-ref="interfaceDecisionManagerBean"] 
     [security:form-login login-page="/login.html" 
          login-processing-url="/loginProcess" 
          default-target-url="/index.jsp" 
          authentication-failure-url="/login.html?login_error=1" /] 

     [security:anonymous /] 
     [security:logout logout-url="/logout" logout-success-url="/logoutSuccess.html" /] 

    [security:port-mappings] 
     [security:port-mapping http="8080" https="8443"/] 
    [/security:port-mappings]   
    [/security:http] 

    [security:ldap-server 
     id="motoLDAP" 
     url="[private... ]" 
    /] 

    [security:authentication-manager] 
     [security:ldap-authentication-provider 
      server-ref="motoLDAP" 
      user-search-filter="(uid={0})" 
       user-search-base="ou=intranet" 
     /] 

    [/security:authentication-manager] 

    [bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"] 
    [constructor-arg value="[... private ...]"/] 
[/bean] 

[bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"] 
    [constructor-arg index="0" value="ou=intranet"/] 
    [constructor-arg index="1" value="(uid={0})"/] 
    [constructor-arg index="2" ref="contextSource" /] 
[/bean] 

[bean id="ldapAuthentication" class="com.mot.br.jag.security.authentication.LDAPAuthentication"] 
     [constructor-arg index="0"] 
     [bean id="ldapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"] 
     [constructor-arg] 
      [bean class="org.springframework.security.ldap.authentication.BindAuthenticator"] 
       [constructor-arg ref="contextSource" /] 
        [property name="userSearch" ref="userSearch" /] 
       [/bean] 
      [/constructor-arg] 
     [/bean] 
     [/constructor-arg] 

     [constructor-arg index="1" ref="userSearch" /] 
[/bean] 

[/beans] 

我的應用程序,是的persistence.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:aop="http://www.springframework.org/schema/aop" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:jee="http://www.springframework.org/schema/jee" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"] 

    [bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /] 
    [bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /] 
    [bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" /] 

[!-- ENTITY MANAGERS --] 

    [bean id="interfaceEMF" 
     class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"] 
     [property name="persistenceUnitName" value="interfaceDS" /] 
    [/bean] 

    [!-- TRANSACTION MANAGERS --] 

    [bean id="interfaceTM" class="org.springframework.orm.jpa.JpaTransactionManager"] 
     [property name="entityManagerFactory" ref="interfaceEMF" /] 
    [/bean] 

    [!-- TX ADVICES --] 

    [tx:advice id="txAdvice" transaction-manager="interfaceTM"] 
     [tx:attributes] 
      [tx:method name="*" propagation="REQUIRED" rollback-for="Throwable" /] 
     [/tx:attributes] 
    [/tx:advice] 

    [!-- AOP CONFIG --] 

    [aop:aspectj-autoproxy /] 
    [aop:config] 
     [aop:pointcut id="businessMethods" expression="execution(* com.mot.br.jag.business.Business+.*(..))" /] 

     [aop:advisor advice-ref="txAdvice" pointcut-ref="businessMethods" /] 
    [/aop:config] 

[/beans] 

我跑出來的想法......我讀過,這是一個錯誤,因爲bean的預處理順序發生了,但是我也讀過這個bug已經修復了。如果我沒有清楚地表達自己,我很抱歉,英語不是我的第一語言。如果能引導我朝着正確的方向發展,我會很樂意回答任何問題。 :)

非常感謝你提前, 羅德里戈

+0

你的意思是說它曾用於春季安全2.x? –

+0

你沒有清楚地說明問題所在。你說你正在得到一個NPE - 你能發佈這個NPE的堆棧跟蹤嗎?你還會說「如果我註釋掉app-security.xml文件並且不加載它的bean,那麼應用程序工作正常」,你需要在這裏更具體一點 - 如果你刪除整個文件,這是_really_ true,或者只是''聲明?註釋處理器可以在哪裏找到註釋?你在相同的bean上混合了@Transactional和@Secured註解嗎?請提供更多信息! –

回答

0

我猜想,有

<aop:aspectj-autoproxy/> 

<security:global-method-security ... /> 

既是之間的衝突,涉及建立某種代理您的豆。

+0

我嘗試過,沒有這個標籤,無濟於事。我記得只是添加這個標籤是因爲我想用「secure-annotations = disabled」屬性來嘗試它,但它不起作用。我剛剛刪除了這個標籤,但它仍然不起作用。 –

1

這可能是由JDK dynamic proxies引起的,嘗試

<aop:aspectj-autoproxy proxy-target-class = "true" /> 

<security:global-method-security proxy-target-class = "true" ... /> 
+0

我試過..但它沒有奏效。如果我不加載'app-security.xml'文件,它沒有proxy-target-class屬性就可以正常工作...... –

2

我不知道這裏發生了什麼,但我有一個袋鼠應用了類似的問題:它的工作直到我配置了安全性。

我的問題是我有一個自定義AuthenticationManager,它使用Roo實體來查找用戶及其角色,即執行身份驗證和授權。

我在啓動時遇到了@PersistenceContext類似的問題,它沒有被注入。

我發現這個問題和解決辦法,也許它可以幫助你......

的FilterSecurityInterceptor嘗試當其屬性validateConfigAttributes設置爲true(這是在默認情況下它的值來獲取所有的ConfigAttribute在他們的afterPropertiesSet方法)

在我的情況下,它意味着使用需要@PersistenceContext的Roo實體的數據庫選擇,它們沒有。

爲什麼?

由於小豆已經以這種方式配置所述的contextConfigLocation在web.xml:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value> 
</context-param> 

正因爲如此,所述的applicationContext-security.xml文件是第一選擇的配置文件,它包含applicationContext.xml中之前持久性上下文的配置。

我認爲順序並不重要,如果你不必在啓動過程中訪問持久性上下文。

但是,如果發生這種情況,試試這個:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     classpath*:META-INF/spring/applicationContext.xml 
     classpath*:META-INF/spring/applicationContext-security.xml 
    </param-value> 
</context-param> 
0

這是一個老問題,但我只是碰到了同樣的問題,幸運的是我設法解決它。我使用的是Spring 3.2.3和spring security 3.1.4

豆的排序是罪魁禍首。

我改變了我的配置文件的順序(全部在相同的上下文中),以便我所有的安全配置都是第一位的。一旦我做到了,所有事情都會神奇地運作我不確定潛在的原因是什麼,但我認爲它與代理創建的方式有關。

我有一個註解驅動緩存類似的問題。我結束了最後一個。

相關問題