gpt4 book ai didi

java - Jetty + 程序化 SPNEGO 配置

转载 作者:搜寻专家 更新时间:2023-10-31 20:34:08 24 4
gpt4 key购买 nike

我正在尝试配置嵌入式 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)。

有什么想法吗?

最佳答案

在您的 ConstraintSecurityHandler 中,您需要将要使用的身份 validator 设置为 SpnegoAuthenticator。

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

关于java - Jetty + 程序化 SPNEGO 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25745228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com