Commit a590f423 authored by Patrick Dowler's avatar Patrick Dowler
Browse files

Merge branch 'nep110' of /srv/cadc/git/wopencadc into s1689

parents f3b6172c d495d782
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@


<!DOCTYPE project>
<project default="build" basedir=".">
<project name="cadcAccessControl-Server" default="build" basedir=".">
    <property environment="env"/>
    <property file="local.build.properties" />

@@ -93,14 +93,16 @@
    <property name="cadcRegistry"        value="${lib}/cadcRegistryClient.jar" />
    <property name="cadcUtil"            value="${lib}/cadcUtil.jar" />
    <property name="cadcUWS"             value="${lib}/cadcUWS.jar" />
    <property name="wsUtil"              value="${lib}/wsUtil.jar" />

    <property name="javacsv"             value="${ext.lib}/javacsv.jar" />
    <property name="jdom2"               value="${ext.lib}/jdom2.jar" />
    <property name="log4j"               value="${ext.lib}/log4j.jar" />
    <property name="servlet"             value="${ext.lib}/servlet-api.jar" />
    <property name="unboundid"           value="${ext.lib}/unboundid-ldapsdk-se.jar" />
    <property name="xerces"              value="${ext.lib}/xerces.jar" />

    <property name="jars" value="${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}" />
    <property name="jars" value="${javacsv}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}:${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${wsUtil}" />

    <target name="build" depends="compile">
        <jar jarfile="${build}/lib/${project}.jar"
@@ -130,17 +132,17 @@
        </copy>
    </target>

<!--    <target name="test" depends="compile-test,resources">
        <echo message="Running test suite..." />
        <junit printsummary="yes" haltonfailure="yes" fork="yes">
            <classpath>
                <pathelement path="${build}/class"/>
                <pathelement path="${build}/test/class"/>
                <pathelement path="${testingJars}"/>
            </classpath>
            <test name="ca.nrc.cadc.ac.server.ldap.LdapDAOTest" />
            <formatter type="plain" usefile="false" />
        </junit>
    </target>-->
    <!--<target name="test" depends="compile,compile-test,resources">-->
        <!--<echo message="Running test suite..." />-->
        <!--<junit printsummary="yes" haltonfailure="yes" fork="yes">-->
            <!--<classpath>-->
                <!--<pathelement path="${build}/class"/>-->
                <!--<pathelement path="${build}/test/class"/>-->
                <!--<pathelement path="${testingJars}"/>-->
            <!--</classpath>-->
            <!--<test name="ca.nrc.cadc.ac.server.ldap.LdapGroupDAOTest" />-->
            <!--<formatter type="plain" usefile="false" />-->
        <!--</junit>-->
    <!--</target>-->

</project>
+2 −0
Original line number Diff line number Diff line
#server	proxyuser proxyUserDN password driver serverURL
<server hostname> <proxyUser in LdapConfig.properties> <proxyUserLdapDN> <password> N/A N/A
+7 −9
Original line number Diff line number Diff line
# This are the configuration fields required by the Ldap ldap-dao unit tests
server = mach275.cadc.dao.nrc.ca
port = 389
admin = uid=webproxy,ou=administrators,ou=topologymanagement,o=netscaperoot
passwd = go4it
usersDn = ou=Users,ou=ds,dc=canfar,dc=net
groupsDn = ou=Groups,ou=ds,dc=canfar,dc=net
deletedGroupsDN = ou=DeletedGroups,ou=ds,dc=canfar,dc=net
testGroupsDN = ou=TestGroups,ou=ds,dc=canfar,dc=net
 No newline at end of file
# This are the configuration fields required by the Ldap
server = <name of server> 
port = <389 or 636>
proxyUser = <name of proxy user>
usersDn = <DN of users branch>
groupsDn = <DN of groups branch>
adminGroupsDn = <DN of admin groups>
+14 −1
Original line number Diff line number Diff line
@@ -81,6 +81,16 @@ import ca.nrc.cadc.net.TransientException;

public abstract interface GroupPersistence<T extends Principal>
{
    /**
     * Get all group names.
     * 
     * @return A collection of strings.
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public Collection<String> getGroupNames()
            throws TransientException, AccessControlException;
    
    /**
     * Get the group with the given Group ID.
     *
@@ -108,10 +118,13 @@ public abstract interface GroupPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     * @throws UserNotFoundException If owner or a member not valid user.
     * @throws GroupNotFoundException if one of the groups in group members or
     * group admins does not exist in the server.
     */
    public abstract Group addGroup(Group group)
        throws GroupAlreadyExistsException, TransientException,
               AccessControlException, UserNotFoundException;
               AccessControlException, UserNotFoundException, 
               GroupNotFoundException;

    /**
     * Deletes the group.
+104 −91
Original line number Diff line number Diff line
@@ -68,14 +68,24 @@
 */
package ca.nrc.cadc.ac.server.ldap;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import java.util.List;

import org.apache.log4j.Logger;

import ca.nrc.cadc.db.ConnectionConfig;
import ca.nrc.cadc.db.DBConfig;
import ca.nrc.cadc.util.MultiValuedProperties;
import ca.nrc.cadc.util.PropertiesReader;
import ca.nrc.cadc.util.StringUtil;

/**
 * Reads and stores the LDAP configuration information. The information 
 * 
 * @author adriand
 *
 */
public class LdapConfig
{
    private static final Logger logger = Logger.getLogger(LdapConfig.class);
@@ -84,125 +94,122 @@ public class LdapConfig
                                        ".properties";
    public static final String LDAP_SERVER = "server";
    public static final String LDAP_PORT = "port";
    public static final String LDAP_ADMIN = "admin";
    public static final String LDAP_PASSWD = "passwd";
    public static final String LDAP_SERVER_PROXY_USER = "proxyUser";
    public static final String LDAP_USERS_DN = "usersDn";
    public static final String LDAP_GROUPS_DN = "groupsDn";
    public static final String LDAP_ADMIN_GROUPS_DN  = "adminGroupsDn";

    public static final String LDAP_AVAIL_TEST_GROUP  = "availabilityTestGroup";
    public static final String LDAP_AVAIL_TEST_CALLING_USER_DN  = "availabilityTestCallingUserDN";
    private final static int SECURE_PORT = 636;

    private String usersDN;
    private String groupsDN;
    private String adminGroupsDN;
    private String server;
    private int port;
    private String adminUserDN;
    private String adminPasswd;
    private String proxyUserDN;
    private String proxyPasswd;
    
    private String availabilityTestGroup;
    private String availabilityTestCallingUserDN;

    public static LdapConfig getLdapConfig()
    public String getProxyUserDN()
    {
        Properties config = new Properties();
        URL url = null;
        try
        {
            url = LdapConfig.class.getClassLoader().getResource(CONFIG);
            logger.debug("Using config from: " + url);
            if (url != null)
            {
                config.load(url.openStream());
        return proxyUserDN;
    }
            else

    public String getProxyPasswd()
    {
                throw new IOException("File not found");
        return proxyPasswd;
    }

    public static LdapConfig getLdapConfig()
    {
        return getLdapConfig(CONFIG);
    }
        catch (Exception ex)

    public static LdapConfig getLdapConfig(final String ldapProperties)
    {
            throw new RuntimeException("failed to read " + CONFIG + 
                                       " from " + url, ex);
        PropertiesReader pr = new PropertiesReader(ldapProperties);
        
        MultiValuedProperties config = pr.getAllProperties();
        
        if (config.keySet() == null)
        {
            throw new RuntimeException("failed to read any LDAP property ");
        }
        
        String server = config.getProperty(LDAP_SERVER);
        if (!StringUtil.hasText(server))
        List<String> prop = config.getProperty(LDAP_SERVER);
        if ((prop == null) || (prop.size() != 1))
        {
            throw new RuntimeException("failed to read property " + 
                                       LDAP_SERVER);
        }
        String server = prop.get(0);

        String port = config.getProperty(LDAP_PORT);
        if (!StringUtil.hasText(port))
        prop = config.getProperty(LDAP_PORT);
        if ((prop == null) || (prop.size() != 1))
        {
            throw new RuntimeException("failed to read property " + LDAP_PORT);
        }
        int port = Integer.valueOf(prop.get(0));
        
        String ldapAdmin = config.getProperty(LDAP_ADMIN);
        if (!StringUtil.hasText(ldapAdmin))
        {
            throw new RuntimeException("failed to read property " + LDAP_ADMIN);
        }

        String ldapPasswd = config.getProperty(LDAP_PASSWD);
        if (!StringUtil.hasText(ldapPasswd))
        prop = config.getProperty(LDAP_SERVER_PROXY_USER);
        if ((prop == null) || (prop.size() != 1))
        {
            throw new RuntimeException("failed to read property " + 
                                       LDAP_PASSWD);
                    LDAP_SERVER_PROXY_USER);
        }
        String ldapProxy = prop.get(0);
        
        String ldapUsersDn = config.getProperty(LDAP_USERS_DN);
        if (!StringUtil.hasText(ldapUsersDn))
        prop = config.getProperty(LDAP_USERS_DN);
        if ((prop == null) || (prop.size() != 1))
        {
            throw new RuntimeException("failed to read property " + 
                                       LDAP_USERS_DN);
        }
        String ldapUsersDn = prop.get(0);

        String ldapGroupsDn = config.getProperty(LDAP_GROUPS_DN);
        if (!StringUtil.hasText(ldapGroupsDn))
        prop = config.getProperty(LDAP_GROUPS_DN);
        if ((prop == null) || (prop.size() != 1))
        {
            throw new RuntimeException("failed to read property " + 
                                       LDAP_GROUPS_DN);
        }
        String ldapGroupsDn = prop.get(0);
        
        String ldapAdminGroupsDn = config.getProperty(LDAP_ADMIN_GROUPS_DN);
        if (!StringUtil.hasText(ldapAdminGroupsDn))
        prop = config.getProperty(LDAP_ADMIN_GROUPS_DN);
        if ((prop == null) || (prop.size() != 1))
        {
            throw new RuntimeException("failed to read property " + 
                                       LDAP_ADMIN_GROUPS_DN);
        }
        String ldapAdminGroupsDn = prop.get(0);
        
        String availGroup = config.getProperty(LDAP_AVAIL_TEST_GROUP);
        if (!StringUtil.hasText(availGroup))
        DBConfig dbConfig;
        try
        {
            throw new RuntimeException("failed to read property " + 
                                       LDAP_AVAIL_TEST_GROUP);
            dbConfig = new DBConfig();
        } 
        
        String availUser = config.getProperty(LDAP_AVAIL_TEST_CALLING_USER_DN);
        if (!StringUtil.hasText(availUser))
        catch (FileNotFoundException e)
        {
            throw new RuntimeException("failed to read property " + 
                                       LDAP_AVAIL_TEST_CALLING_USER_DN);
            throw new RuntimeException("failed to find .dbrc file ");
        } 

        return new LdapConfig(server, Integer.valueOf(port), ldapAdmin, 
                              ldapPasswd, ldapUsersDn, ldapGroupsDn,
                              ldapAdminGroupsDn, availGroup, availUser);
        catch (IOException e)
        {
            throw new RuntimeException("failed to read .dbrc file ");
        }
    
    public LdapConfig(String server, int port, String adminUserDN, 
            String adminPasswd, String usersDN, String groupsDN,
            String adminGroupsDN)
        ConnectionConfig cc = dbConfig.getConnectionConfig(server, ldapProxy);
        if ( (cc == null) || (cc.getUsername() == null) || (cc.getPassword() == null))
        {
        this(server, port, adminUserDN, adminPasswd, usersDN, groupsDN, adminGroupsDN, null, null);
            throw new RuntimeException("failed to find connection info in ~/.dbrc");
        }
        
    public LdapConfig(String server, int port, String adminUserDN, 
                      String adminPasswd, String usersDN, String groupsDN,
                      String adminGroupsDN, String availGroup, String availUser)
        return new LdapConfig(server, Integer.valueOf(port), cc.getUsername(), 
                              cc.getPassword(), ldapUsersDn, ldapGroupsDn,
                              ldapAdminGroupsDn);
    }
    

    public LdapConfig(String server, int port, String proxyUserDN, 
                      String proxyPasswd, String usersDN, String groupsDN,
                      String adminGroupsDN)
    {
        if (!StringUtil.hasText(server))
        {
@@ -213,11 +220,11 @@ public class LdapConfig
            throw new IllegalArgumentException("Illegal LDAP server port: " + 
                                               port);
        }
        if (!StringUtil.hasText(adminUserDN))
        if (!StringUtil.hasText(proxyUserDN))
        {
            throw new IllegalArgumentException("Illegal Admin DN");
        }
        if (!StringUtil.hasText(adminPasswd))
        if (!StringUtil.hasText(proxyPasswd))
        {
            throw new IllegalArgumentException("Illegal Admin password");
        }
@@ -234,16 +241,14 @@ public class LdapConfig
            throw new IllegalArgumentException("Illegal admin groups LDAP DN");
        }
        

        this.server = server;
        this.port = port;
        this.adminUserDN = adminUserDN;
        this.adminPasswd = adminPasswd;
        this.proxyUserDN = proxyUserDN;
        this.proxyPasswd = proxyPasswd;
        this.usersDN = usersDN;
        this.groupsDN = groupsDN;
        this.adminGroupsDN = adminGroupsDN;
        this.availabilityTestGroup = availGroup;
        this.availabilityTestCallingUserDN = availUser;
        logger.debug(toString());
    }

    public String getUsersDN()
@@ -271,24 +276,32 @@ public class LdapConfig
        return this.port;
    }

    public String getAdminUserDN()
    public boolean isSecure()
    {
        return this.adminUserDN;
        return getPort() == SECURE_PORT;
    }

    public String getAdminPasswd()
    public String getAdminUserDN()
    {
        return this.adminPasswd;
        return this.proxyUserDN;
    }

    public String getAvailabilityTestGroup()
    public String getAdminPasswd()
    {
        return this.availabilityTestGroup;
        return this.proxyPasswd;
    }

    public String getAvailabilityTestCallingUserDN()
    public String toString()
    {
        return this.availabilityTestCallingUserDN;
        StringBuilder sb = new StringBuilder();
        sb.append("server = ");
        sb.append(server);
        sb.append(" port = ");
        sb.append(port);
        sb.append(" proxyUserDN = ");
        sb.append(proxyUserDN);
        sb.append(" proxyPasswd = ");
        sb.append(proxyPasswd);
        return sb.toString(); 
    }

}
Loading