2017-02-16 59 views
1

我有我的Jetty Servlet的以下初始化。 HashLoginService的作品,但我的LdapLoginModule没有连接到JAASLoginService,“ldaploginmodule”是指我想跳过的默认ldap-loginModule.conf,并通过选项映射(或某种程度上指定为文件位置)的所有参数。如何配置嵌入式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错误登录:500

问题访问/ j_security_check。原因:

java.io.IOException: ldap-loginModule.conf (No such file or directory) 

我怎样才能得到这个工作,而无需使用配置文件(码头服务器嵌入式另一个应用程序中的动态装入罐子

+0

搬到https://github.com/eclipse/jetty.project/issues/1349 –

回答

相关问题