我很久以来都是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
}
...
}
my 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上 - 相同的结果)
答案 0 :(得分:1)
我整理出来了。 带有DeltaSpike SecurityInterceptor的beans.xml必须存在于使用注释的同一模块中。 在我的设置中,它只在模块中提供安全代码。 它也只适用于任何EJB或CDI bean,除了@WebService(这里是WF8 / 9上的CXF) - 正如@JohnAment所建议的那样我假设SOAP端点不会自动在EJB / CDI上下文中注册,因此不能直接通过这个注释。
将@Stateless添加到alredy现在的@WebService会阻止部署应用程序:
JBAS017312: KlasseImpl has the wrong component type, it cannot be used as a web component
无论如何,我相信业务逻辑应该与SOAP(或任何其他)端点分离,因此我成功地将注释注入到SOAP业务服务中。