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