我正在尝试配置一个嵌入式Jetty xml服务器,以编程方式使用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);但是,当我访问服务器时,它试图使用基本身份验证(Base64)。
有什么想法吗?
发布于 2014-09-09 23:03:44
在您的ConstraintSecurityHandler中,您需要将验证器设置为SpnegoAuthenticator。
https://stackoverflow.com/questions/25745228
复制相似问题