2017-02-16 63 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 –

回答

相關問題