3

我是 Spring 的老用户,现在只需要切换到 Java EE。有很多事情没有按预期工作......

我有一个 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);
    }
}

还有一个无状态 EJB 的 KlasseService:

@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 看起来如下:

<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>

在处理 SOAP 请求时,永远不会调用CutomAuthorizer 代码(在接口、实现甚至服务 - EJB 上放置注释)。但是,当从ie 调用的方法使用相同的注解时。JSF - 一切都按预期工作

我发现了一些相关的问题:Deltaspike 和@Stateless Bean 然而阅读这篇文章:Where to use EJB 3.1 and CDI? 让我认为 EJB 容器应该知道 CDI 拦截器等。此外,其他自定义拦截器 (@AroundInvoke) 对我有用,并且 JSF 请求得到保护,正如预期的那样。

我是否遗漏了一些明显的东西,这将使 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 上 - 结果相同)

4

1 回答 1

1

我整理了一下。带有 DeltaSpike SecurityInterceptor 的 beans.xml 必须存在于使用注释的同一模块中。在我的设置中,它仅在提供安全代码的模块中。此外,它仅适用于任何 EJB 或 CDI bean,除了 @WebService(这里是 WF8/9 上的 CXF) - 正如@JohnAment 所建议的那样,我假设 SOAP 端点不会在 EJB/CDI 上下文中自动注册,因此不能直接通过这个注解。

将@Stateless 添加到已经存在的@WebService 会阻止应用程序被部署:

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

无论如何,我相信业务逻辑应该与 SOAP(或任何其他)端点分开,因此我成功地使用注解注入到 SOAP 业务服务中。

于 2015-09-07T20:23:58.587 回答