clean code
This commit is contained in:
parent
90d4d77e4b
commit
904f4c330f
@ -75,7 +75,8 @@ public class GroupServlet extends AbstractLDAPServlet {
|
||||
}
|
||||
final GroupsDAO groupsDAO = new GroupsDAO(ldapSession);
|
||||
final Group grp = new Group();
|
||||
final List<String> members = new ArrayList<String>();
|
||||
final List<String> members;
|
||||
members = new ArrayList<>();
|
||||
final HttpSession httpSession = req.getSession();
|
||||
cleanSession(httpSession);
|
||||
@SuppressWarnings("unchecked") final SortedMap<String, User> usersHash = (SortedMap<String, User>) httpSession.getAttribute("users"); //$NON-NLS-1$
|
||||
@ -94,7 +95,7 @@ public class GroupServlet extends AbstractLDAPServlet {
|
||||
final Group oldValue = groupsDAO.readGroup(dn, usersHash);
|
||||
grp.setDn(dn);
|
||||
grp.setName(oldValue.getName());
|
||||
if (grp.getMembers().size() == 0) {
|
||||
if (grp.getMembers().isEmpty()) {
|
||||
httpSession.setAttribute("group", grp); //$NON-NLS-1$
|
||||
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$
|
||||
@ -118,7 +119,7 @@ public class GroupServlet extends AbstractLDAPServlet {
|
||||
if ("create".equals(operation)) { //$NON-NLS-1$
|
||||
final String grpName = req.getParameter("name"); //$NON-NLS-1$
|
||||
grp.setName(grpName);
|
||||
if (grp.getMembers().size() == 0) {
|
||||
if (grp.getMembers().isEmpty()) {
|
||||
httpSession.setAttribute("group", grp); //$NON-NLS-1$
|
||||
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$
|
||||
|
@ -14,16 +14,14 @@ import javax.net.ssl.X509TrustManager;
|
||||
|
||||
public class NaiveTrustManager implements X509TrustManager {
|
||||
|
||||
private static SSLContext SSL_CONTEXT;
|
||||
private static final SSLContext SSL_CONTEXT;
|
||||
|
||||
static {
|
||||
try {
|
||||
SSL_CONTEXT = SSLContext.getInstance("TLSv1.2");
|
||||
SSL_CONTEXT.init(null, new TrustManager[] { new NaiveTrustManager() }, null);
|
||||
SSLContext.setDefault(SSL_CONTEXT);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("Unable to initialise SSL context", e);
|
||||
} catch (KeyManagementException e) {
|
||||
} catch (NoSuchAlgorithmException | KeyManagementException e) {
|
||||
throw new RuntimeException("Unable to initialise SSL context", e);
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,8 @@ public class UserServlet extends AbstractLDAPServlet {
|
||||
usr.setEmail(email);
|
||||
usr.setPhone(phone);
|
||||
usr.setMobile(mobile);
|
||||
final List<String> memberships = new ArrayList<String>();
|
||||
final List<String> memberships;
|
||||
memberships = new ArrayList<>();
|
||||
@SuppressWarnings("unchecked") final SortedMap<String, Group> groupsHash = (SortedMap<String, Group>) httpSession.getAttribute("groups"); //$NON-NLS-1$
|
||||
final Iterator<String> groupDNIterator = groupsHash.keySet().iterator();
|
||||
while (groupDNIterator.hasNext()) {
|
||||
@ -174,17 +175,14 @@ public class UserServlet extends AbstractLDAPServlet {
|
||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
||||
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$
|
||||
return;
|
||||
} catch (RequiredAttributeException e) {
|
||||
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$
|
||||
req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp); //$NON-NLS-1$
|
||||
return;
|
||||
} catch (AlreadyBoundException e) {
|
||||
httpSession.setAttribute("user", usr); //$NON-NLS-1$
|
||||
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$
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,13 @@ import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
|
||||
import org.apache.directory.server.protocol.shared.store.LdifLoadFilter;
|
||||
import org.apache.directory.server.protocol.shared.transport.TcpTransport;
|
||||
|
||||
public class DirectoryServiceRunner
|
||||
{
|
||||
public class DirectoryServiceRunner {
|
||||
|
||||
private static DirectoryServiceRunner serviceRunner = null;
|
||||
|
||||
private final DirectoryService service;
|
||||
|
||||
public DirectoryServiceRunner(final String dnString, final String ip, final String port) throws Exception
|
||||
{
|
||||
public DirectoryServiceRunner(final String dnString, final String ip, final String port) throws Exception {
|
||||
service = initService();
|
||||
addPartition("ou=config", "config");
|
||||
addPartition(dnString, "example");
|
||||
@ -70,11 +69,9 @@ public class DirectoryServiceRunner
|
||||
private void loadData() {
|
||||
final File ldifDirectory = new File("ldif");
|
||||
if (ldifDirectory.exists() && ldifDirectory.isDirectory()) {
|
||||
final File[] ldifFiles = ldifDirectory.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
final File[] ldifFiles;
|
||||
ldifFiles = ldifDirectory.listFiles((final File dir, final String name) -> {
|
||||
return name.endsWith(".ldif");
|
||||
}
|
||||
});
|
||||
for (final File ldifFile : ldifFiles) {
|
||||
final LdifFileLoader ldifFileLoader = new LdifFileLoader(service.getAdminSession(), ldifFile, (List<? extends LdifLoadFilter>) new ArrayList<LdifLoadFilter>());
|
||||
@ -84,8 +81,7 @@ public class DirectoryServiceRunner
|
||||
}
|
||||
}
|
||||
|
||||
public static void assureServiceRunning(final String name) throws DirectoryServiceException
|
||||
{
|
||||
public static void assureServiceRunning(final String name) throws DirectoryServiceException {
|
||||
if (serviceRunner == null) {
|
||||
final String dnName = "dc=" + name + ",dc=example,dc=com";
|
||||
try {
|
||||
@ -96,19 +92,15 @@ public class DirectoryServiceRunner
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(final String[] args)
|
||||
{
|
||||
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
|
||||
{
|
||||
try {
|
||||
final DirectoryServiceRunner ads = new DirectoryServiceRunner(dnString, ip, port);
|
||||
final Entry result = ads.service.getAdminSession().lookup(new Dn(dnString));
|
||||
System.out.println("Found entry : " + result);
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,5 @@
|
||||
package de.jalin.ldapadmin.ldap;
|
||||
|
||||
import de.jalin.ldapadmin.ldap.LDAPSession;
|
||||
import de.jalin.ldapadmin.ldap.AlreadyBoundException;
|
||||
import de.jalin.ldapadmin.ldap.RequiredAttributeException;
|
||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||
import de.jalin.ldapadmin.ldap.GroupsDAO;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -1,10 +1,5 @@
|
||||
package de.jalin.ldapadmin.ldap;
|
||||
|
||||
import de.jalin.ldapadmin.ldap.LDAPSession;
|
||||
import de.jalin.ldapadmin.ldap.AlreadyBoundException;
|
||||
import de.jalin.ldapadmin.ldap.RequiredAttributeException;
|
||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
|
@ -1,10 +1,5 @@
|
||||
package de.jalin.ldapadmin.ldap;
|
||||
|
||||
import de.jalin.ldapadmin.ldap.LDAPSession;
|
||||
import de.jalin.ldapadmin.ldap.AlreadyBoundException;
|
||||
import de.jalin.ldapadmin.ldap.RequiredAttributeException;
|
||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
|
@ -1,10 +1,5 @@
|
||||
package de.jalin.ldapadmin.ldap;
|
||||
|
||||
import de.jalin.ldapadmin.ldap.LDAPSession;
|
||||
import de.jalin.ldapadmin.ldap.AlreadyBoundException;
|
||||
import de.jalin.ldapadmin.ldap.RequiredAttributeException;
|
||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
|
@ -1,10 +1,5 @@
|
||||
package de.jalin.ldapadmin.ldap;
|
||||
|
||||
import de.jalin.ldapadmin.ldap.LDAPSession;
|
||||
import de.jalin.ldapadmin.ldap.AlreadyBoundException;
|
||||
import de.jalin.ldapadmin.ldap.RequiredAttributeException;
|
||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -1,10 +1,5 @@
|
||||
package de.jalin.ldapadmin.ldap;
|
||||
|
||||
import de.jalin.ldapadmin.ldap.LDAPSession;
|
||||
import de.jalin.ldapadmin.ldap.AlreadyBoundException;
|
||||
import de.jalin.ldapadmin.ldap.RequiredAttributeException;
|
||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -1,10 +1,5 @@
|
||||
package de.jalin.ldapadmin.ldap;
|
||||
|
||||
import de.jalin.ldapadmin.ldap.LDAPSession;
|
||||
import de.jalin.ldapadmin.ldap.AlreadyBoundException;
|
||||
import de.jalin.ldapadmin.ldap.RequiredAttributeException;
|
||||
import de.jalin.ldapadmin.ldap.UsersDAO;
|
||||
import de.jalin.ldapadmin.ldap.LDAPSessionException;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
Loading…
Reference in New Issue
Block a user