Java 使用嵌入式Jetty进行身份验证
我试图使用嵌入Jetty将摘要身份验证添加到通过HTTP提供的API中。我没有web.xml,这不是一个webapp。应用程序通过从我的文件“spring config.xml”创建ClassPathXmlApplicationContext对象启动。在“springconfig.xml”中,我为服务等定义了很多bean,还定义了一个启动Jetty服务器的bean Jetty服务器配置了一个DispatcherServlet(实际上是一个DispatcherServletWrapper类,它实现ApplicationContextAware并将ClassPathXmlApplicationContext对象设置为它创建的GenericWebApplicationContext的父对象,这样它就可以访问我的spring-config.xml文件中定义的bean) 这一切都是可行的,但失败的地方是尝试添加身份验证。我添加了所有用于设置摘要身份验证的spring安全配置,但我不知道如何让Jetty知道过滤器链 我的spring-config.xml的相关部分如下所示:Java 使用嵌入式Jetty进行身份验证,java,spring,spring-mvc,spring-security,embedded-jetty,Java,Spring,Spring Mvc,Spring Security,Embedded Jetty,我试图使用嵌入Jetty将摘要身份验证添加到通过HTTP提供的API中。我没有web.xml,这不是一个webapp。应用程序通过从我的文件“spring config.xml”创建ClassPathXmlApplicationContext对象启动。在“springconfig.xml”中,我为服务等定义了很多bean,还定义了一个启动Jetty服务器的bean Jetty服务器配置了一个DispatcherServlet(实际上是一个DispatcherServletWrapper类,它实现
public class DispatcherServletWrapper extends DispatcherServlet implements ApplicationContextAware {
private static final long serialVersionUID = -2281511575328213502L;
private ApplicationContext appContext;
@Override
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
this.appContext = arg0;
}
protected WebApplicationContext createWebApplicationContext(WebApplicationContext arg0) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.setParent(appContext);
wac.refresh();
return wac;
}
}
/*
/
我尝试直接在jetty的过滤器列表中引用DigestAuthenticationFilter,这似乎不会导致任何事情发生。我尝试了上面所示的方法,其中我尝试引用一个DelegatingFilterProxy,这会导致“ServletContext不能为null”异常。根据我读到的一些spring文档和其他问题,尝试这种方法并将其命名为“springSecurityFilterChain”完全是猜测
谁能告诉我如何获得Jetty使用的这些身份验证配置?我想做的有意义吗
作为参考,我的DispatcherServletWrapper如下所示:
public class DispatcherServletWrapper extends DispatcherServlet implements ApplicationContextAware {
private static final long serialVersionUID = -2281511575328213502L;
private ApplicationContext appContext;
@Override
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
this.appContext = arg0;
}
protected WebApplicationContext createWebApplicationContext(WebApplicationContext arg0) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.setParent(appContext);
wac.refresh();
return wac;
}
}
我已经成功地在没有web.xml的情况下配置了嵌入式Jetty+spring安全性 您可以通过编程方式添加DelegatingFilterProxy,并将目标bean名称“springSecurityFilterChain”传递给它 我还尝试使用DigestAuthenticationFilter,但没有成功 希望这能对您有所帮助。类似于。