Jetty + 编程式 SPNEGO 配置

5
我想要将一个嵌入式Jetty web服务器通过编程方式配置成使用SPNEGO(不使用xml)。
我正在尝试将这个网站转换成非基于xml的配置:http://www.eclipse.org/jetty/documentation/current/spnego-support.html。以下是我的尝试内容:
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();

// ...

String domainRealm = "MY.DOMAIN.COM";

Constraint constraint = new Constraint();
constraint.setName(Constraint.__SPNEGO_AUTH);
constraint.setRoles(new String[] { domainRealm });
constraint.setAuthenticate(true);

ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");

SpnegoLoginService loginService = new SpnegoLoginService();
loginService.setConfig(System.getProperty("spnego.properties"));
loginService.setName(domainRealm);

ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
sh.setLoginService(loginService);
sh.setConstraintMappings(new ConstraintMapping[]{cm});
sh.setRealmName(domainRealm);

ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setErrorHandler(new ErrorHandler() { }); // TODO
contextHandler.setContextPath(contextPath);
contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), "/*");
contextHandler.addEventListener(new ContextLoaderListener(context));
contextHandler.setSecurityHandler(sh);

Server server = new Server(port);
server.setHandler(contextHandler);

然而,当我访问服务器时,它试图使用基本认证(base 64)。
有任何想法吗?

你会使用war/WebAppContext吗?还是也会完全使用嵌入式Jetty技术? - Joakim Erdfelt
@JoakimErdfelt 使用 AnnotationConfigWebApplicationContext(Spring)进行编程。在代码片段中添加了一些额外的代码。(没有WAR文件) - Cheetah
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接