我在设置JavaEE6CDI拦截器时遇到了问题。我使用的是嵌入式glassfish,我已经在web应用程序的beans.xml中指定了拦截器。
<beans
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>ServiceInterceptor</class>
</interceptors>
</beans>我正在尝试保护这个bean:
@Named
//@Stateless
@RequestScoped
public class SecuredMethodJSFBean /*implements Serializable*/{
@Inject
protected SecuredMethodSample securedMethodSample;
/*
@CurrentUser
@SessionScoped
@Inject
protected RuntimePrincipalAware principal;
//protected JSFLoginBean jsfLoginBean;
*/
public SecuredMethodJSFBean()
{
super();
System.out.println("creating secured method jsf bean");
}
@Secured("adfadfafd")
public void doSomething()
{
//System.out.println("\n\n\n\nprincipal:" + principal);
//System.out.println("principal:" + jsfLoginBean.getPrincipal());
//securedMethodSample.doSomething(jsfLoginBean.getPrincipal().getName());
//return(jsfLoginBean.getPrincipal().getName());
//securedMethodSample.doSomething(principal.getName());
//return(principal.getName());
//return("secured-method");
securedMethodSample.doSomething("testing ...");
}
}我需要做什么才能让我的拦截器运行?
另外,我正在尝试使用拦截器来拦截servlet使用的bean上的方法调用。由于这些bean是bean,我应该能够拦截它们。但是,我不能这样做。我最初试图直接拦截servlet中的方法调用,但它们不是CDI bean,所以这没有意义。
谢谢,
沃尔特
发布于 2013-02-22 11:50:12
为了更好地回答我的问题,我做了以下操作:
沃尔特
发布于 2013-02-24 02:28:02
“我已经在web应用程序的beans.xml中指定了拦截器”
@Secured是否在另一个项目/ jar中定义?在这种情况下,您需要在beans.xml中启用它。
https://stackoverflow.com/questions/14902500
复制相似问题