5

I am trying to configure an embedded Jetty webserver to use SPNEGO programatically (without xml).

I am trying to convert this: http://www.eclipse.org/jetty/documentation/current/spnego-support.html to a non-xml based configuration. Here is my attempt:

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);

However, it is trying to use basic authentication (base 64) when I hit the server.

Any ideas?

Cheetah
  • 13,785
  • 31
  • 106
  • 190
  • Will you be using a war / WebAppContext? or will that also be using entirely embedded-jetty techniques too? – Joakim Erdfelt Sep 09 '14 at 14:25
  • @JoakimErdfelt Using with a `AnnotationConfigWebApplicationContext` (Spring). Added some extra code to the snippet. (No WAR files) – Cheetah Sep 09 '14 at 14:31

1 Answers1

1

In your ConstraintSecurityHandler you need to set the authenticator to use to be SpnegoAuthenticator.

https://github.com/eclipse/jetty.project/blob/master/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/SpnegoAuthenticator.java

jesse mcconnell
  • 7,102
  • 1
  • 22
  • 33