У меня есть следующая инициализация для моего Jetty Servlet. Однако HashLoginService работает, но LdapLoginModule не подключен к JAASLoginService, «ldaploginmodule» относится к умолчанию ldap-loginModule.conf, который я хочу пропустить и передать все параметры в параметрах Map (или как-то указать как местоположение файла).Как настроить встроенный Jetty для использования LdapLoginModule?
Server jettyServer = new Server(8080);
ServletContextHandler context = new ServletContextHandler(jettyServer, "/", ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY);
context.addServlet(new ServletHolder(new DefaultServlet() {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getSession().invalidate(); // do logout
response.getWriter().append("<html><form method='POST' action='/j_security_check'>"
+ "<input type='text' name='j_username'/>"
+ "<input type='password' name='j_password'/>"
+ "<input type='submit' value='Login'/></form></html>");
}
}), "/login");
context.addServlet(new ServletHolder(new MyServlet()),"/*");
Constraint constraint = new Constraint();
constraint.setName(Constraint.__FORM_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec("/*");
ConstraintSecurityHandler securityHandler;
if (ldapEnabled) { // *** something is missing ****
LdapLoginModule lm = new LdapLoginModule();
Map options = new HashMap<>();
options.put("hostname", "127.0.0.1");
options.put("port", "389");
options.put("contextFactory", "com.sun.jndi.ldap.LdapCtxFactory");
options.put("bindDn", "CN=admin,OU=example,OU=com");
options.put("bindPassword", "password");
options.put("userBaseDn", "dc=example,dc=com");
lm.initialize(null,null,null,options);
securityHandler = new ConstraintSecurityHandler();
securityHandler.addConstraintMapping(constraintMapping);
JAASLoginService loginService = new JAASLoginService("ldaploginmodule");
loginService.setIdentityService(new DefaultIdentityService());
securityHandler.setLoginService(loginService);
} else { // This works
securityHandler = new ConstraintSecurityHandler();
securityHandler.addConstraintMapping(constraintMapping);
HashLoginService loginService = new HashLoginService();
loginService.putUser("username", new Password("password"), new String[]{"user"});
securityHandler.setLoginService(loginService);
}
Когда пользователь пытается войти в режим ldapEnabled
HTTP ERROR: 500
Проблема доступа/j_security_check. Причина:
java.io.IOException: ldap-loginModule.conf (No such file or directory)
Как я могу получить эту работу без использования файлов конфигурации (сервер Причала является внедренными внутри другого приложения, как динамически загружаемая банка)
переехал в https://github.com/eclipse/jetty.project/issues/1349 –