【问题标题】:PicketLink / Deltaspike security does not work in SOAP (JAX-WS) layer (CDI vs EJB?)PicketLink / Deltaspike 安全性在 SOAP (JAX-WS) 层(CDI 与 EJB?)中不起作用
【发布时间】:2015-11-30 07:06:28
【问题描述】:

我是 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 and @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 上 - 结果相同)

【问题讨论】:

  • 您的 SOAP 端点上似乎没有托管容器注释。你在注释它@Stateless 吗?这将是我要尝试的第一件事。 WebService 端点不会自动成为无状态会话 Bean。
  • @JohnAment 这会导致部署异常:JBAS017312: KlasseImpl 的组件类型错误,它不能用作 Web 组件,并且在 JEE 世界中似乎不正确。无论如何,我怀疑这与 CXF 在内部使用 Spring 进行配置有关,因此 JEE bean 对于 CXF WebServices 是可见的,但是 JEE beans(和 DeltaSpike 拦截器)看不到 WebServices。 developer.jboss.org/wiki/Jbossws-stackcxfUserGuide
  • 该文档非常陈旧并且已经过时(与您正在使用的文档相比)。您需要提供完整的例外情况并更新问题以反映您实际尝试过的内容。

标签: soap ejb cdi deltaspike picketlink


【解决方案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 业务服务中。

【讨论】:

    猜你喜欢
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    相关资源
    最近更新 更多