Verwaltung von LDAP Accounts und Gruppen
Peter Hormanns
2020-03-25 9ea2f82a7b7ac399aada0c563d34f83d1c582117
robuster, hsadmin
5 files modified
41 ■■■■ changed files
src/main/java/de/jalin/ldapadmin/ldap/GroupsDAO.java 12 ●●●● patch | view | raw | blame | history
src/main/java/de/jalin/ldapadmin/ldap/LDAPConfig.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/de/jalin/ldapadmin/ldap/UsersDAO.java 4 ●●●● patch | view | raw | blame | history
src/main/java/de/jalin/ldapadmin/web/AbstractLDAPServlet.java 11 ●●●●● patch | view | raw | blame | history
src/main/resources/config.properties 3 ●●●● patch | view | raw | blame | history
src/main/java/de/jalin/ldapadmin/ldap/GroupsDAO.java
@@ -33,9 +33,15 @@
            grp.setDn(result.getNameInNamespace());
            final List<String> listOfMembers = session.getListOfValues(attribs, "uniqueMember");
            final String dn = grp.getDn();
            listOfMembers.stream().map((userDN) -> users.get(userDN)).map((user) -> user.getGroups()).forEachOrdered((groups) -> {
                groups.add(dn);
            });
            for (final String userDN : listOfMembers) {
                final User user = users.get(userDN);
                if (user != null) {
                    final List<String> groups = user.getGroups();
                    groups.add(dn);
                } else {
                    System.out.println("Error: " + userDN + " in group " + dn);
                }
            }
            grp.setMembers(listOfMembers);
            list.put(dn, grp);
        }
src/main/java/de/jalin/ldapadmin/ldap/LDAPConfig.java
@@ -23,6 +23,8 @@
    private String smtpHost;
    private String smtpPort;
    private String smtpInternalDomains;
    private String pacAdmin;
    private String pacPassword;
    private String tempDir;
    private LDAPConfig() {
@@ -49,6 +51,8 @@
            smtpPort = props.getProperty("smtp.port", smtpPort);
            smtpFromAddress = props.getProperty("smtp.from", smtpFromAddress);
            smtpInternalDomains = props.getProperty("smtp.internal", smtpInternalDomains);
            pacAdmin = props.getProperty("pac.user", "xyz00");
            pacPassword = props.getProperty("pac.password", "secret");
            tempDir = props.getProperty("temp.dir", tempDir);
            final LDAPUriParser uriParser = new LDAPUriParser(ldapProviderUrl);
            ldapDistinguishedName = uriParser.getDn();
@@ -119,6 +123,13 @@
        return tempDir;
    }
    public String getPacAdmin() {
        return pacAdmin;
    }
    public String getPacPassword() {
        return pacPassword;
    }
    private Properties loadConfig() throws IOException {
        final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config.properties");
src/main/java/de/jalin/ldapadmin/ldap/UsersDAO.java
@@ -71,11 +71,11 @@
        if (hasValue(emailInternal)) {
            mail.add(emailInternal);
        }
        attributes.put(mail);
        final String emailExternal = usr.getEmailExternal();
        if (hasValue(emailExternal)) {
            mail.add(emailExternal);
            attributes.put("description", emailExternal);
        }
        attributes.put(mail);
        attributes.put("uid", uid);
        attributes.put("cn", uid);
        final String telephone = usr.getPhone();
src/main/java/de/jalin/ldapadmin/web/AbstractLDAPServlet.java
@@ -10,6 +10,7 @@
import de.jalin.ldapadmin.beans.Group;
import de.jalin.ldapadmin.beans.User;
import de.jalin.ldapadmin.hsadmin.TicketProvider;
import de.jalin.ldapadmin.ldap.LDAPConfig;
import de.jalin.ldapadmin.ldap.LDAPSession;
import de.jalin.ldapadmin.ldap.LDAPSessionException;
@@ -27,6 +28,7 @@
    protected LDAPSession ldapSession;
    protected LDAPConfig config;
    protected TicketProvider ticketProvider = null;
    protected void loadData() {
        users = new TreeMap<>();
@@ -73,5 +75,14 @@
        httpSession.removeAttribute("successmessage");
        httpSession.removeAttribute("servletexception");
    }
    protected TicketProvider getTicketProvider() {
        if (ticketProvider == null) {
            final String pacAdmin = config.getPacAdmin();
            final String pacPassword = config.getPacPassword();
            ticketProvider = new TicketProvider(pacAdmin, pacPassword);
        }
        return ticketProvider;
    }
}
src/main/resources/config.properties
@@ -3,4 +3,5 @@
security.password=streng-geheim
smtp.host=localhost
smtp.from=nobody@example.com
smtp.internal=example.com,example.org
pac.user=xyz00
pac.password=secret