【发布时间】: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