mostly working

This commit is contained in:
Peter Hormanns 2019-07-23 20:43:32 +02:00
parent 2c168b0663
commit 8c1f3d7a40
22 changed files with 220 additions and 158 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
target/ target/
nb-configuration.xml
pom.xml.tag pom.xml.tag
pom.xml.releaseBackup pom.xml.releaseBackup
pom.xml.versionsBackup pom.xml.versionsBackup

View File

@ -3,7 +3,7 @@
<Call name="addBean"> <Call name="addBean">
<Arg> <Arg>
<New class="org.eclipse.jetty.security.HashLoginService"> <New class="org.eclipse.jetty.security.HashLoginService">
<Set name="name">Administration Area</Set> <Set name="name">LDAP</Set>
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set> <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
</New> </New>
</Arg> </Arg>

View File

@ -1 +1 @@
peter: Test123,login,admins admin: Test123,login,admins

View File

@ -52,11 +52,6 @@
<artifactId>commons-net</artifactId> <artifactId>commons-net</artifactId>
<version>3.6</version> <version>3.6</version>
</dependency> </dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.webjars</groupId> <groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId> <artifactId>bootstrap</artifactId>

View File

@ -3,9 +3,7 @@ package de.jalin.ldapadmin.ldap;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.sf.ehcache.Cache; import net.sf.ehcache.Cache;
import org.apache.directory.api.ldap.model.entry.Entry; import org.apache.directory.api.ldap.model.entry.Entry;
import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.api.ldap.model.name.Dn; import org.apache.directory.api.ldap.model.name.Dn;
@ -24,16 +22,40 @@ import org.apache.directory.server.protocol.shared.transport.TcpTransport;
public class DirectoryServiceRunner { public class DirectoryServiceRunner {
private static DirectoryServiceRunner serviceRunner = null; private static DirectoryServiceRunner serviceRunner = null;
public static void assureServiceRunning(final String name) throws DirectoryServiceException {
if (serviceRunner == null) {
final String dnName = "dc=" + name + ",dc=example,dc=com";
try {
serviceRunner = new DirectoryServiceRunner("example", dnName, "127.0.0.1", "10389", false);
} catch (Exception e) {
throw new DirectoryServiceException(e);
}
}
}
public static void main(final String[] args) {
final String dnString = "dc=" + args[0] + ",dc=example,dc=com";
final String ip = args[1];
final String port = args[2];
try {
final DirectoryServiceRunner ads = new DirectoryServiceRunner("example", dnString, ip, port, false);
final Entry result = ads.service.getAdminSession().lookup(new Dn(dnString));
System.out.println("Found entry : " + result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
private final DirectoryService service; private final DirectoryService service;
public DirectoryServiceRunner(final String partition, final String dnString, final String ip, final String port) throws Exception { public DirectoryServiceRunner(final String partition, final String dnString, final String ip, final String port, final boolean useTLS) throws Exception {
this.service = initService(partition); this.service = initService(partition);
addPartition("ou=config", "config"); addPartition("ou=config", "config");
addPartition(dnString, partition); addPartition(dnString, partition);
this.service.startup(); this.service.startup();
loadData(); loadData();
startServer(ip, port); startServer(ip, port, useTLS);
} }
private DirectoryService initService(final String partition) throws Exception { private DirectoryService initService(final String partition) throws Exception {
@ -58,13 +80,19 @@ public class DirectoryServiceRunner {
service.addPartition(partition); service.addPartition(partition);
} }
private void startServer(final String ip, final String port) throws Exception { private void startServer(final String ip, final String port, final boolean useTLS) throws Exception {
final LdapServer ldapServer = new LdapServer(); final LdapServer ldapServer = new LdapServer();
ldapServer.setTransports(new TcpTransport(ip, Integer.parseInt(port))); final TcpTransport tcpTransport = new TcpTransport(ip, Integer.parseInt(port));
tcpTransport.enableSSL(useTLS);
ldapServer.setTransports(tcpTransport);
ldapServer.setDirectoryService(service); ldapServer.setDirectoryService(service);
ldapServer.start(); ldapServer.start();
} }
public void shutdown() throws Exception {
service.shutdown();
}
private void loadData() { private void loadData() {
final File ldifDirectory = new File("ldif"); final File ldifDirectory = new File("ldif");
if (ldifDirectory.exists() && ldifDirectory.isDirectory()) { if (ldifDirectory.exists() && ldifDirectory.isDirectory()) {
@ -80,29 +108,6 @@ public class DirectoryServiceRunner {
} }
} }
public static void assureServiceRunning(final String name) throws DirectoryServiceException {
if (serviceRunner == null) {
final String dnName = "dc=" + name + ",dc=example,dc=com";
try {
serviceRunner = new DirectoryServiceRunner("example", dnName, "127.0.0.1", "10389");
} catch (Exception e) {
throw new DirectoryServiceException(e);
}
}
}
public static void main(final String[] args) {
final String dnString = "dc=" + args[0] + ",dc=example,dc=com";
final String ip = args[1];
final String port = args[2];
try {
final DirectoryServiceRunner ads = new DirectoryServiceRunner("example", dnString, ip, port);
final Entry result = ads.service.getAdminSession().lookup(new Dn(dnString));
System.out.println("Found entry : " + result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
static class DirectoryServiceException extends Exception { static class DirectoryServiceException extends Exception {

View File

@ -0,0 +1,37 @@
package de.jalin.ldapadmin.server;
public class LDAPUriParser {
private final boolean useTLS;
private final String dn;
private final String port;
private final String host;
public LDAPUriParser (final String uri) {
final String[] uriParts = uri.split("\\/");
final String protocol = uriParts[0];
final String hostAndPort = uriParts[2];
final String[] hostAndPortParts = hostAndPort.split(":");
host = hostAndPortParts[0];
port = hostAndPortParts[1];
dn = uriParts[3];
useTLS = protocol.toLowerCase().startsWith("ldaps");
}
public String getDn() {
return dn;
}
public String getHost() {
return host;
}
public String getPort() {
return port;
}
public boolean isUseTLS() {
return useTLS;
}
}

View File

@ -1,20 +1,37 @@
package de.jalin.ldapadmin.server; package de.jalin.ldapadmin.server;
import de.jalin.ldapadmin.ldap.DirectoryServiceRunner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class WebappDirectoryServer implements ServletContextListener { public class WebappDirectoryServer implements ServletContextListener {
private DirectoryServiceRunner directoryServer;
@Override @Override
public void contextInitialized(final ServletContextEvent evt) { public void contextInitialized(final ServletContextEvent evt) {
final ServletContext ctx = evt.getServletContext(); try {
final String uri = ctx.getInitParameter("uri"); final ServletContext ctx = evt.getServletContext();
final String uri = ctx.getInitParameter("uri");
final LDAPUriParser uriParser = new LDAPUriParser(uri);
directoryServer = new DirectoryServiceRunner("main", uriParser.getDn(), uriParser.getHost(), uriParser.getPort(), uriParser.isUseTLS());
} catch (Exception ex) {
Logger.getLogger(WebappDirectoryServer.class.getName()).log(Level.SEVERE, null, ex);
}
} }
@Override @Override
public void contextDestroyed(final ServletContextEvent evt) { public void contextDestroyed(final ServletContextEvent evt) {
try {
directoryServer.shutdown();
} catch (Exception ex) {
Logger.getLogger(WebappDirectoryServer.class.getName()).log(Level.SEVERE, null, ex);
}
} }
} }

View File

@ -20,7 +20,7 @@ import de.jalin.ldapadmin.ldap.LDAPSessionException;
import de.jalin.ldapadmin.ldap.NoGroupMembersException; import de.jalin.ldapadmin.ldap.NoGroupMembersException;
import de.jalin.ldapadmin.ldap.UsersDAO; import de.jalin.ldapadmin.ldap.UsersDAO;
@WebServlet(name = "LdapGroup", urlPatterns = {"/group/*"}) @WebServlet(name = "LdapGroup", urlPatterns = {"/group/*"}, loadOnStartup = 1)
public class GroupServlet extends AbstractLDAPServlet { public class GroupServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -56,7 +56,7 @@ public class GroupServlet extends AbstractLDAPServlet {
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
throwServletException(httpSession, e); throwServletException(httpSession, e);
} }
req.getRequestDispatcher("/WEB-INF/group.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
} }
@Override @Override
@ -98,7 +98,7 @@ public class GroupServlet extends AbstractLDAPServlet {
if (grp.getMembers().isEmpty()) { if (grp.getMembers().isEmpty()) {
httpSession.setAttribute("group", grp); //$NON-NLS-1$ httpSession.setAttribute("group", grp); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/group.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
try { try {
@ -106,7 +106,7 @@ public class GroupServlet extends AbstractLDAPServlet {
} catch (NoGroupMembersException e) { } catch (NoGroupMembersException e) {
httpSession.setAttribute("group", grp); //$NON-NLS-1$ httpSession.setAttribute("group", grp); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/group.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
} }
@ -122,7 +122,7 @@ public class GroupServlet extends AbstractLDAPServlet {
if (grp.getMembers().isEmpty()) { if (grp.getMembers().isEmpty()) {
httpSession.setAttribute("group", grp); //$NON-NLS-1$ httpSession.setAttribute("group", grp); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("GroupServlet.no_empty_group")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/group.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
try { try {
@ -130,7 +130,7 @@ public class GroupServlet extends AbstractLDAPServlet {
} catch (AlreadyBoundException e) { } catch (AlreadyBoundException e) {
httpSession.setAttribute("group", grp); //$NON-NLS-1$ httpSession.setAttribute("group", grp); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("GroupServlet.group_exists")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("GroupServlet.group_exists")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/group.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/group.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/" + grp.getDn()); //$NON-NLS-1$ resp.sendRedirect(req.getContextPath() + req.getServletPath() + "/" + grp.getDn()); //$NON-NLS-1$

View File

@ -14,7 +14,7 @@ import de.jalin.ldapadmin.ldap.GroupsDAO;
import de.jalin.ldapadmin.ldap.LDAPSessionException; import de.jalin.ldapadmin.ldap.LDAPSessionException;
import de.jalin.ldapadmin.ldap.UsersDAO; import de.jalin.ldapadmin.ldap.UsersDAO;
@WebServlet(name = "LdapGroups", urlPatterns = {"/groups"}) @WebServlet(name = "LdapGroups", urlPatterns = {"/groups"}, loadOnStartup = 1)
public class GroupsServlet extends AbstractLDAPServlet { public class GroupsServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -33,7 +33,7 @@ public class GroupsServlet extends AbstractLDAPServlet {
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
throwServletException(httpSession, e); throwServletException(httpSession, e);
} }
req.getRequestDispatcher("/WEB-INF/groups.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/groups.jsp").forward(req, resp); //$NON-NLS-1$
} }
} }

View File

@ -8,7 +8,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@WebServlet(name = "Logout", urlPatterns = {"/logout"}) @WebServlet(name = "Logout", urlPatterns = {"/logout"}, loadOnStartup = 1)
public class LogoutServlet extends AbstractLDAPServlet { public class LogoutServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@ -6,7 +6,7 @@ import java.util.ResourceBundle;
public class Messages { public class Messages {
private static final String BUNDLE_NAME = "de.jalin.ldapadmin.admin.web.messages"; //$NON-NLS-1$ private static final String BUNDLE_NAME = "de.jalin.ldapadmin.web.messages"; //$NON-NLS-1$
private final ResourceBundle resourceBundle; private final ResourceBundle resourceBundle;

View File

@ -18,7 +18,7 @@ import de.jalin.ldapadmin.ldap.LDAPSessionException;
import de.jalin.ldapadmin.ldap.SimplePasswordException; import de.jalin.ldapadmin.ldap.SimplePasswordException;
import de.jalin.ldapadmin.ldap.UsersDAO; import de.jalin.ldapadmin.ldap.UsersDAO;
@WebServlet(name = "LdapProfile", urlPatterns = {"/profile", "/profile/*"}) @WebServlet(name = "LdapProfile", urlPatterns = {"/profile", "/profile/*"}, loadOnStartup = 1)
public class ProfileServlet extends AbstractLDAPServlet { public class ProfileServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -52,7 +52,7 @@ public class ProfileServlet extends AbstractLDAPServlet {
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
throwServletException(httpSession, e); throwServletException(httpSession, e);
} }
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
} }
@Override @Override
@ -85,12 +85,12 @@ public class ProfileServlet extends AbstractLDAPServlet {
} catch (SimplePasswordException e) { } catch (SimplePasswordException e) {
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} catch (ValidationException e) { } catch (ValidationException e) {
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.inputfield") + e.getFieldname() + " " + e.getCondition()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.inputfield") + e.getFieldname() + " " + e.getCondition()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
try { try {
@ -102,14 +102,14 @@ public class ProfileServlet extends AbstractLDAPServlet {
httpSession.setAttribute("successmessage", messages.getString("ProfileServlet.password_changed")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("successmessage", messages.getString("ProfileServlet.password_changed")); //$NON-NLS-1$ //$NON-NLS-2$
httpSession.setAttribute("operation", "profile"); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("operation", "profile"); //$NON-NLS-1$ //$NON-NLS-2$
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); req.getRequestDispatcher("/user.jsp").forward(req, resp);
} }
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
final String excMessage = e.getMessage(); final String excMessage = e.getMessage();
if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$ if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.invalid_reuse")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ProfileServlet.invalid_reuse")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
throwServletException(httpSession, e); throwServletException(httpSession, e);

View File

@ -26,7 +26,7 @@ import de.jalin.ldapadmin.ldap.LDAPSessionException;
import de.jalin.ldapadmin.ldap.SimplePasswordException; import de.jalin.ldapadmin.ldap.SimplePasswordException;
import de.jalin.ldapadmin.ldap.UsersDAO; import de.jalin.ldapadmin.ldap.UsersDAO;
@WebServlet(name = "ResetPassword", urlPatterns = {"/passwordreset"}) @WebServlet(name = "ResetPassword", urlPatterns = {"/passwordreset"}, loadOnStartup = 1)
public class ResetPasswordServlet extends AbstractLDAPServlet { public class ResetPasswordServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -57,17 +57,17 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
final UsersDAO usrDAO = new UsersDAO(ldapSession); final UsersDAO usrDAO = new UsersDAO(ldapSession);
final User usr = usrDAO.read("uid=" + uidAndEMail[0] + ",ou=users,"); //$NON-NLS-1$ //$NON-NLS-2$ final User usr = usrDAO.read("uid=" + uidAndEMail[0] + ",ou=users,"); //$NON-NLS-1$ //$NON-NLS-2$
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
req.getRequestDispatcher("/WEB-INF/new-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
LOG.warning("no valid password reset request"); LOG.warning("no valid password reset request");
httpSession.setAttribute("errormessage", new Messages(req.getLocale()).getString("ResetPasswordServlet.no_valid_passwordreset_request")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", new Messages(req.getLocale()).getString("ResetPasswordServlet.no_valid_passwordreset_request")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/reset-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
} }
} }
req.getRequestDispatcher("/WEB-INF/reset-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
} }
@Override @Override
@ -85,26 +85,26 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
if (password1 != null && !password1.isEmpty()) { if (password1 != null && !password1.isEmpty()) {
if (password2 == null || !password2.equals(password1)) { if (password2 == null || !password2.equals(password1)) {
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.passwords_donot_match")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.passwords_donot_match")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/new-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} else { } else {
try { try {
sessUsr.setAndValidatePassword(password1); sessUsr.setAndValidatePassword(password1);
usrDAO.update(sessUsr); usrDAO.update(sessUsr);
httpSession.setAttribute("successmessage", messages.getString("ResetPasswordServlet.password_changed")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("successmessage", messages.getString("ResetPasswordServlet.password_changed")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/new-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} catch (SimplePasswordException e) { } catch (SimplePasswordException e) {
httpSession.setAttribute("user", sessUsr); //$NON-NLS-1$ httpSession.setAttribute("user", sessUsr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/new-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
final String excMessage = e.getMessage(); final String excMessage = e.getMessage();
if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$ if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$
httpSession.setAttribute("user", sessUsr); //$NON-NLS-1$ httpSession.setAttribute("user", sessUsr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.invalid_password_reuse")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.invalid_password_reuse")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/new-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/new-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
throwServletException(httpSession, e); throwServletException(httpSession, e);
@ -139,7 +139,7 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
} }
if (login.isEmpty() || email.isEmpty()) { if (login.isEmpty() || email.isEmpty()) {
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/reset-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
printStream.println(login + ":" + email); //$NON-NLS-1$ printStream.println(login + ":" + email); //$NON-NLS-1$
@ -156,7 +156,7 @@ public class ResetPasswordServlet extends AbstractLDAPServlet {
} catch (LDAPSessionException | IOException e) { } catch (LDAPSessionException | IOException e) {
LOG.severe("smtp problem"); LOG.severe("smtp problem");
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.error_sending_password_reset")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/reset-password.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/reset-password.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
httpSession.invalidate(); httpSession.invalidate();

View File

@ -23,7 +23,7 @@ import de.jalin.ldapadmin.ldap.RequiredAttributeException;
import de.jalin.ldapadmin.ldap.SimplePasswordException; import de.jalin.ldapadmin.ldap.SimplePasswordException;
import de.jalin.ldapadmin.ldap.UsersDAO; import de.jalin.ldapadmin.ldap.UsersDAO;
@WebServlet(name = "LdapUser", urlPatterns = {"/user/*"}) @WebServlet(name = "LdapUser", urlPatterns = {"/user/*"}, loadOnStartup = 1)
public class UserServlet extends AbstractLDAPServlet { public class UserServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -59,7 +59,7 @@ public class UserServlet extends AbstractLDAPServlet {
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
throwServletException(httpSession, e); throwServletException(httpSession, e);
} }
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
} }
@Override @Override
@ -126,12 +126,12 @@ public class UserServlet extends AbstractLDAPServlet {
} catch (SimplePasswordException e) { } catch (SimplePasswordException e) {
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("ResetPasswordServlet.simple_password")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} catch (ValidationException e) { } catch (ValidationException e) {
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("UserServlet.input_field") + " \"" + e.getFieldname() + "\" " + e.getCondition()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ httpSession.setAttribute("errormessage", messages.getString("UserServlet.input_field") + " \"" + e.getFieldname() + "\" " + e.getCondition()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession); final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
@ -168,22 +168,22 @@ public class UserServlet extends AbstractLDAPServlet {
if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$ if (excMessage != null && excMessage.contains("invalid reuse of password")) { //$NON-NLS-1$
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("UserServlet.invalid_password_reuse")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("UserServlet.invalid_password_reuse")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
return; return;
} }
throwServletException(httpSession, e); throwServletException(httpSession, e);
} catch (NoGroupMembersException e) { } catch (NoGroupMembersException e) {
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("UserServlet.group_last_member")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("UserServlet.group_last_member")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
} catch (RequiredAttributeException e) { } catch (RequiredAttributeException e) {
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("UserServlet.the_input_field") + " " + e.getFieldname() + " " + messages.getString("UserServlet.is_required")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ httpSession.setAttribute("errormessage", messages.getString("UserServlet.the_input_field") + " " + e.getFieldname() + " " + messages.getString("UserServlet.is_required")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
} catch (AlreadyBoundException e) { } catch (AlreadyBoundException e) {
httpSession.setAttribute("user", usr); //$NON-NLS-1$ httpSession.setAttribute("user", usr); //$NON-NLS-1$
httpSession.setAttribute("errormessage", messages.getString("UserServlet.user_exists")); //$NON-NLS-1$ //$NON-NLS-2$ httpSession.setAttribute("errormessage", messages.getString("UserServlet.user_exists")); //$NON-NLS-1$ //$NON-NLS-2$
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/user.jsp").forward(req, resp); //$NON-NLS-1$
} }
} }

View File

@ -15,7 +15,7 @@ import de.jalin.ldapadmin.ldap.GroupsDAO;
import de.jalin.ldapadmin.ldap.LDAPSessionException; import de.jalin.ldapadmin.ldap.LDAPSessionException;
import de.jalin.ldapadmin.ldap.UsersDAO; import de.jalin.ldapadmin.ldap.UsersDAO;
@WebServlet(name = "LdapUsers", urlPatterns = {"/users"}) @WebServlet(name = "LdapUsers", urlPatterns = {"/users"}, loadOnStartup = 1)
public class UsersServlet extends AbstractLDAPServlet { public class UsersServlet extends AbstractLDAPServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -35,7 +35,7 @@ public class UsersServlet extends AbstractLDAPServlet {
} catch (LDAPSessionException e) { } catch (LDAPSessionException e) {
throwServletException(httpSession, e); throwServletException(httpSession, e);
} }
req.getRequestDispatcher("/WEB-INF/users.jsp").forward(req, resp); //$NON-NLS-1$ req.getRequestDispatcher("/users.jsp").forward(req, resp); //$NON-NLS-1$
} }
} }

View File

@ -1,4 +1,4 @@
provider.url=ldap://localhost:10389/dc=example,dc=com provider.url=ldap://localhost:10389/dc=domain,dc=example,dc=com
security.principal=uid=admin,ou=system security.principal=uid=admin,ou=system
security.password=secret security.password=streng-geheim
smtp.host=localhost smtp.host=localhost

View File

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<session-config> <session-config>
<tracking-mode>COOKIE</tracking-mode> <tracking-mode>COOKIE</tracking-mode>
</session-config> </session-config>
<context-param>
<param-name>uri</param-name>
<param-value>ldap://localhost:10389/dc=domain,dc=example,dc=com</param-value>
</context-param>
<servlet-mapping> <servlet-mapping>
<servlet-name>default</servlet-name> <servlet-name>default</servlet-name>
<url-pattern>/css/*</url-pattern> <url-pattern>/css/*</url-pattern>
@ -15,11 +14,9 @@
<url-pattern>*.css</url-pattern> <url-pattern>*.css</url-pattern>
<url-pattern>*.js</url-pattern> <url-pattern>*.js</url-pattern>
</servlet-mapping> </servlet-mapping>
<welcome-file-list> <welcome-file-list>
<welcome-file>/contact.jsp</welcome-file> <welcome-file>/contact.jsp</welcome-file>
</welcome-file-list> </welcome-file-list>
<error-page> <error-page>
<error-code>403</error-code> <error-code>403</error-code>
<location>/access-denied.jsp</location> <location>/access-denied.jsp</location>
@ -32,7 +29,6 @@
<error-code>503</error-code> <error-code>503</error-code>
<location>/servlet-exception.jsp</location> <location>/servlet-exception.jsp</location>
</error-page> </error-page>
<security-constraint> <security-constraint>
<web-resource-collection> <web-resource-collection>
<web-resource-name>Public access</web-resource-name> <web-resource-name>Public access</web-resource-name>
@ -47,7 +43,6 @@
<url-pattern>/servlet-exception.jsp</url-pattern> <url-pattern>/servlet-exception.jsp</url-pattern>
</web-resource-collection> </web-resource-collection>
</security-constraint> </security-constraint>
<security-constraint> <security-constraint>
<web-resource-collection> <web-resource-collection>
<web-resource-name>Profile Area</web-resource-name> <web-resource-name>Profile Area</web-resource-name>
@ -60,7 +55,6 @@
<role-name>login</role-name> <role-name>login</role-name>
</auth-constraint> </auth-constraint>
</security-constraint> </security-constraint>
<security-constraint> <security-constraint>
<web-resource-collection> <web-resource-collection>
<web-resource-name>Administrative Area</web-resource-name> <web-resource-name>Administrative Area</web-resource-name>
@ -73,22 +67,18 @@
<role-name>admins</role-name> <role-name>admins</role-name>
</auth-constraint> </auth-constraint>
</security-constraint> </security-constraint>
<login-config> <login-config>
<auth-method>FORM</auth-method> <auth-method>FORM</auth-method>
<realm-name>Administration Area</realm-name> <realm-name>LDAP</realm-name>
<form-login-config> <form-login-config>
<form-login-page>/login.jsp</form-login-page> <form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginfail.jsp</form-error-page> <form-error-page>/loginfail.jsp</form-error-page>
</form-login-config> </form-login-config>
</login-config> </login-config>
<security-role> <security-role>
<role-name>admins</role-name> <role-name>admins</role-name>
</security-role> </security-role>
<security-role> <security-role>
<role-name>login</role-name> <role-name>login</role-name>
</security-role> </security-role>
</web-app>
</web-app>

View File

@ -50,7 +50,7 @@
<div class="col-sm-9" id ="membership"> <div class="col-sm-9" id ="membership">
<c:forEach items="${users}" var="userentry" > <c:forEach items="${users}" var="userentry" >
<div class="checkbox"> <div class="checkbox">
<jsp:useBean id="checker" class="de.jalin.ldapadmin.admin.beans.MembershipCheck" /> <jsp:useBean id="checker" class="de.jalin.ldapadmin.beans.MembershipCheck" />
<jsp:setProperty property="user" name="checker" value="${userentry.value}" /> <jsp:setProperty property="user" name="checker" value="${userentry.value}" />
<jsp:setProperty property="group" name="checker" value="${group}" /> <jsp:setProperty property="group" name="checker" value="${group}" />
<label><input type="checkbox" id="${userentry.value.login}" name="check_user_${userentry.value.login}" ${checker.checked}>${userentry.value.firstname} ${userentry.value.lastname} (${userentry.value.login})</label> <label><input type="checkbox" id="${userentry.value.login}" name="check_user_${userentry.value.login}" ${checker.checked}>${userentry.value.firstname} ${userentry.value.lastname} (${userentry.value.login})</label>

View File

@ -6,39 +6,39 @@
<html lang="{language}"> <html lang="{language}">
<jsp:include page="template/header.jsp"/> <jsp:include page="template/header.jsp"/>
<body> <body>
<jsp:include page="template/empty-navbar.jsp"/> <jsp:include page="template/empty-navbar.jsp"/>
<!-- Page Content --> <!-- Page Content -->
<c:url var="formaction" value="j_security_check" /> <c:url var="formaction" value="j_security_check" />
<c:url var="passwordreset" value="/passwordreset" /> <c:url var="passwordreset" value="/passwordreset" />
<div class="container"> <div class="container">
<h1><fmt:message key="login.title"/></h1> <h1><fmt:message key="login.title"/></h1>
<div class="control-group col-sm-8 additional-space-top"> <div class="control-group col-sm-8 additional-space-top">
<form class="form-horizontal" method="post" action="${formaction}"> <form class="form-horizontal" method="post" action="${formaction}">
<fieldset class=""> <fieldset class="">
<div class="form-group"> <div class="form-group">
<label for="j_username" class="col-sm-4 control-label"><fmt:message key="login.username"/></label> <label for="j_username" class="col-sm-4 control-label"><fmt:message key="login.username"/></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input <input
type="text" class="form-control" id="j_username" name="j_username" type="text" class="form-control" id="j_username" name="j_username"
value="" placeholder="Login name"> value="" placeholder="Login name">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="j_password" class="col-sm-4 control-label"><fmt:message key="login.password"/></label> <label for="j_password" class="col-sm-4 control-label"><fmt:message key="login.password"/></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input <input
type="password" class="form-control" id="j_password" name="j_password" type="password" class="form-control" id="j_password" name="j_password"
value="" placeholder="Password"> value="" placeholder="Password">
</div> </div>
</div> </div>
<button type="submit" class="col-sm-offset-4 btn btn-primary additional-space-top"><fmt:message key="login.submit"/></button> <button type="submit" class="col-sm-offset-4 btn btn-primary additional-space-top"><fmt:message key="login.submit"/></button>
<div class="form-group additional-space-top"> <div class="form-group additional-space-top">
<a href="${passwordreset}" class="col-sm-offset-4"><fmt:message key="login.reset.password"/></a> <a href="${passwordreset}" class="col-sm-offset-4"><fmt:message key="login.reset.password"/></a>
</div> </div>
</fieldset> </fieldset>
</form> </form>
</div> </div>
</div> </div>
<jsp:include page="template/footer.jsp"/> <jsp:include page="template/footer.jsp"/>
</body> </body>
</html> </html>

View File

@ -6,43 +6,43 @@
<html lang="{language}"> <html lang="{language}">
<jsp:include page="template/header.jsp"/> <jsp:include page="template/header.jsp"/>
<body> <body>
<jsp:include page="template/empty-navbar.jsp"/> <jsp:include page="template/empty-navbar.jsp"/>
<!-- Page Content --> <!-- Page Content -->
<c:url var="formaction" value="j_security_check" /> <c:url var="formaction" value="j_security_check" />
<c:url var="passwordreset" value="/passwordreset" /> <c:url var="passwordreset" value="/passwordreset" />
<div class="container"> <div class="container">
<h1><fmt:message key="login.title"/></h1> <h1><fmt:message key="login.title"/></h1>
<div class="alert"> <div class="alert">
<a class="close" data-dismiss="alert">×</a> <a class="close" data-dismiss="alert">×</a>
<strong><fmt:message key="login.error.title"/></strong><fmt:message key="login.error.message"/> <strong><fmt:message key="login.error.title"/></strong> <fmt:message key="login.error.message"/>
</div> </div>
<div class="control-group col-sm-6 additional-space-top"> <div class="control-group col-sm-6 additional-space-top">
<form class="form-horizontal" method="post" action="${formaction}"> <form class="form-horizontal" method="post" action="${formaction}">
<fieldset class=""> <fieldset class="">
<div class="form-group"> <div class="form-group">
<label for="j_username" class="col-sm-4 control-label"><fmt:message key="login.username"/></label> <label for="j_username" class="col-sm-4 control-label"><fmt:message key="login.username"/></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input <input
type="text" class="form-control" id="j_username" name="j_username" type="text" class="form-control" id="j_username" name="j_username"
value="" placeholder="Login name"> value="" placeholder="Login name">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="j_password" class="col-sm-4 control-label"><fmt:message key="login.password"/></label> <label for="j_password" class="col-sm-4 control-label"><fmt:message key="login.password"/></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input <input
type="password" class="form-control" id="j_password" name="j_password" type="password" class="form-control" id="j_password" name="j_password"
value="" placeholder="Password"> value="" placeholder="Password">
</div> </div>
</div> </div>
<button type="submit" class="col-sm-offset-4 btn btn-primary additional-space-top"><fmt:message key="login.submit"/></button> <button type="submit" class="col-sm-offset-4 btn btn-primary additional-space-top"><fmt:message key="login.submit"/></button>
<div class="form-group additional-space-top"> <div class="form-group additional-space-top">
<a href="${passwordreset}" class="col-sm-offset-4"><fmt:message key="login.reset.password"/></a> <a href="${passwordreset}" class="col-sm-offset-4"><fmt:message key="login.reset.password"/></a>
</div> </div>
</fieldset> </fieldset>
</form> </form>
</div> </div>
</div> </div>
<jsp:include page="template/footer.jsp"/> <jsp:include page="template/footer.jsp"/>
</body> </body>
</html> </html>

View File

@ -128,7 +128,7 @@
<div class="col-sm-9" id ="membership"> <div class="col-sm-9" id ="membership">
<c:forEach items="${groups}" var="groupentry" > <c:forEach items="${groups}" var="groupentry" >
<div class="checkbox"> <div class="checkbox">
<jsp:useBean id="checker" class="de.jalin.ldapadmin.admin.beans.MembershipCheck" /> <jsp:useBean id="checker" class="de.jalin.ldapadmin.beans.MembershipCheck" />
<jsp:setProperty property="user" name="checker" value="${user}" /> <jsp:setProperty property="user" name="checker" value="${user}" />
<jsp:setProperty property="group" name="checker" value="${groupentry.value}" /> <jsp:setProperty property="group" name="checker" value="${groupentry.value}" />
<label><input type="checkbox" id="${groupentry.value.name}" name="check_group_${groupentry.value.name}" ${checker.checked}>${groupentry.value.name}</label> <label><input type="checkbox" id="${groupentry.value.name}" name="check_group_${groupentry.value.name}" ${checker.checked}>${groupentry.value.name}</label>

View File

@ -0,0 +1,17 @@
package de.jalin.ldapadmin.server;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class TestLDAPUriParser {
@Test
public void testLDAPUriParser() {
final LDAPUriParser ldapUriParser = new LDAPUriParser("ldap://localhost:10389/dc=example,dc=com");
assertEquals("localhost", ldapUriParser.getHost());
assertEquals("10389", ldapUriParser.getPort());
assertEquals("dc=example,dc=com", ldapUriParser.getDn());
assertEquals(false, ldapUriParser.isUseTLS());
}
}