gpt4 book ai didi

soap - PicketLink/Deltaspike 安全性在 SOAP (JAX-WS) 层中不起作用(CDI vs EJB?)

转载 作者:行者123 更新时间:2023-12-02 03:22:23 24 4
gpt4 key购买 nike

我是 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 代码永远不会被调用(在接口(interface)、实现甚至服务 - 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但这听起来很麻烦....

附言。我正在使用 WildFly 8.2(在 WF9 上 - 结果相同)

最佳答案

我整理好了。带有 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(或任何其他)端点分离,因此我成功地使用了注入(inject)到 SOAP 业务服务中的注解。

关于soap - PicketLink/Deltaspike 安全性在 SOAP (JAX-WS) 层中不起作用(CDI vs EJB?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32392702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com