我正在尝试配置嵌入式Jetty网络服务器以编程方式使用SPNEGO(不使用xml)。
我正在尝试将此http://www.eclipse.org/jetty/documentation/current/spnego-support.html转换为基于非xml的配置。这是我的尝试:
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)。
有什么想法吗?
答案 0 :(得分:1)
在ConstraintSecurityHandler中,您需要将身份验证器设置为SpnegoAuthenticator。