2015-09-04 19 views
3

我很久沒有用Spring了,現在只能切換到Java EE。有很多事情,只是不能按預期工作...PicketLink/Deltaspike安全在SOAP(JAX-WS)層中不起作用(CDI vs EJB?)

我有一個CXF/SOAP服務

@WebService(...) 
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) 
public interface KlassePortType { ... 

    @WebMethod(...) 
    @WebResult(...) 
    public ListOutputType list(@WebParam(...) 
      ListInputType request 
     ); 
    ... 
    } 

的實現:

@WebService(...) 
public class KlasseImpl implements KlassePortType { ... 

    @Inject 
    private KlasseService klasseService; 

    @DeclaresRole 
    @Override 
    public ListOutputType list(ListInputType request) { 
     return klasseService.list(request); 
    } 
} 

,也是一個KlasseService這是一個無狀態EJB:

@Stateless 
public class KlasseService { ... 

    @DeclaresRole 
    public ListOutputType list(ListInputType listInputType) { 
     METHOD LOGIC 
    } 
... 
} 

的DeclaresRole註釋被指定爲:

@Retention(value = RetentionPolicy.RUNTIME) 
@Target({ ElementType.TYPE, ElementType.METHOD }) 
@Documented 
@SecurityBindingType 
public @interface DeclaresRole { 
} 

而且有配套DeltaSpike授權:

@ApplicationScoped 
public class CustomAuthorizer {... 
    @Secures 
    @DeclaresRole 
    public boolean doSecuredCheck() throws Exception 
    { 
     SECURITY CHECK LOGIC 
    } 
... 
} 

我的beans.xml看起來folllowing:

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
          http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all"> 
    <interceptors> 
     <class>org.apache.deltaspike.security.impl.extension.SecurityInterceptor</class> 
    </interceptors> 
</beans> 

的CutomAuthorizer代碼從來沒有被稱爲,當SOAP請求被處理, (在接口,執行甚至服務上註釋 - EJB)。 然而,當從調用的方法使用相同的註釋時,即。 JSF - 一切按預期工作

我發現了一些相關的問題:Deltaspike and @Stateless Bean 但是閱讀本:Where to use EJB 3.1 and CDI? 讓我想到EJB容器應該知道CDI攔截器等 而且其他,自定義攔截器(@AroundInvoke)爲我工作的,而JSF reqests正如預期的那樣獲得擔保。

我是否錯過了明顯的東西,這將使PicketLink/Deltaspike在SOAP層中可用? 作爲替代我可以使用Spring Security + AspectJ切走了,一樣記載:http://forum.spring.io/forum/spring-projects/security/119811-method-security-java-ee-cdi 但只是聽起來像很多的麻煩....

PS。我正在使用WildFly 8.2(在WF9上 - 結果相同)

+0

您的SOAP端點似乎沒有託管容器註釋。你註釋了它嗎@ @ Stateless?這將是我會嘗試的第一件事。 WebService端點不會自動變爲無狀態會話Bean。 –

+0

@JohnAment這會導致部署異常:JBAS017312:KlasseImpl具有錯誤的組件類型,它不能用作Web組件,並且在JEE世界中似乎不正確。無論如何,我懷疑這與CXF內部使用Spring進行配置有關,因此JEE bean對於CXF WebServices是可見的,但是JEE bean(和DeltaSpike攔截器)沒有看到WebServices。 https://developer.jboss.org/wiki/Jbossws-stackcxfUserGuide – mszalinski

+0

該文檔非常陳舊,過時(與您的工作相比)。您需要提供完整的例外情況並更新問題以反映您實際嘗試的內容。 –

回答

1

我整理出來了。 帶有DeltaSpike SecurityInterceptor的beans.xml必須存在於使用註釋的相同模塊中。 在我的設置中,它只在模塊中提供安全代碼。 另外它只適用於任何EJB或CDI bean,除了@WebService(這裏是WF8/9上的CXF) - 正如@JohnAment所建議的那樣我假設SOAP端點不會自動在EJB/CDI上下文中註冊,因此不能直接進行安全保護通過這個註釋。

添加@Stateless到alredy本@WebService防止從應用程序被部署:

JBAS017312: KlasseImpl has the wrong component type, it cannot be used as a web component 

相信無論如何,該業務邏輯應該從SOAP(或任何其他)端點被分離,因此,我成功地使用注入到SOAP業務服務中的註釋。