java - 如何将 OpenID 服务添加到嵌入式 Jetty 服务器。为 org.eclipse.jetty.security.openid.OpenIdAuthenticator 获取没有 IdentityService
问题描述
我正在尝试将 OpenId 服务添加到嵌入式 Jetty 服务器。我按照此处的 Jetty 文档进行操作,现在我收到以下错误。
org.eclipse.jetty.security.openid.OpenIdAuthenticator 没有 IdentityService
我似乎找不到在 Jetty 中进行设置的完整示例,而且我不确定如何设置身份服务。以下是我的代码。
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Usage: need a relative path to the war file to execute");
System.exit(1);
}
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StrErrLog");
System.setProperty("org.eclipse.jetty.LEVEL", "INFO");
// Create a basic Jetty server object that will listen on port defined by
// the PORT environment variable when present, otherwise on 8080.
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
Server server = new Server(port);
System.out.println("clientid = " + clientId);
System.out.println("clientSecret = " + clientSecret);
// The WebAppContext is the interface to provide configuration for a web
// application. In this example, the context path is being set to "/" so
// it is suitable for serving root context requests.
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar(args[0]);
ClassList classlist = ClassList.setServerDefault(server);
// Enable Annotation Scanning.
classlist.addBefore(
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration");
OpenIdConfiguration openIdConfig = new OpenIdConfiguration(issuer, clientId, clientSecret);
OpenIdLoginService loginService = new OpenIdLoginService(openIdConfig);
Authenticator authenticator = new OpenIdAuthenticator(openIdConfig, "/error");
SecurityHandler securityHandler = webapp.getSecurityHandler();
securityHandler.setLoginService(loginService);
securityHandler.setAuthenticator(authenticator);
securityHandler.setIdentityService(loginService.getIdentityService());
webapp.setSecurityHandler(securityHandler);
// Set the the WebAppContext as the ContextHandler for the server.
server.setHandler(webapp);
// Start the server! By using the server.join() the server thread will
// join with the current thread. See
// "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()"
// for more details.
server.start();
server.join();
}
如果有人有任何指导,我将不胜感激。谢谢。
解决方案
您正在将身份服务设置为 null,因为IdentityService
已在OpenIdLoginService
.
您可以使用以下方式IdentityService
显式设置:
SecurityHandler securityHandler = webapp.getSecurityHandler();
securityHandler.setAuthenticator(authenticator);
securityHandler.setLoginService(loginService);
securityHandler.setIdentityService(new DefaultIdentityService());
或者,如果您在未设置 的情况下定义领域名称IdentityService
,则启动时将自动创建一个。
SecurityHandler securityHandler = webapp.getSecurityHandler();
securityHandler.setRealmName(issuer);
securityHandler.setAuthenticator(authenticator);
securityHandler.setLoginService(loginService);
推荐阅读
- r - geom_line 在 R 中显示直线而不是平滑线
- c++ - 将 cplex 与 c++ 一起使用:添加条件约束
- python - 在 Pygame 中将鼠标悬停在某物上时显示一条消息?
- java - 我在构建同步时收到此错误“无法解析配置‘:app:debugRuntimeClasspath’的所有依赖项’
- java - Selenium ChromeWebDriver 在尝试登录网站时触发警报
- python - 如何使用python将文件从本地写入GCP
- reactjs - Redux 工具包布尔切换没有触发
- c - 如何使用 for 循环制作等腰三角形?
- nix - nix安装错误;未找到 GLIBC_2.33
- javascript - 如何在 node.js 的另一个路由中使用变量