Commit 3f22fd66 authored by Brian Major's avatar Brian Major
Browse files

issue-10 - more work towards full group URI use.

parent 1fd509e1
Loading
Loading
Loading
Loading
+32 −41
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ package ca.nrc.cadc.ac.server.ldap;

import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Collection;
@@ -752,8 +751,6 @@ public class LdapGroupDAO extends LdapDAO

    private Group createGroupFromSearchResult(SearchResultEntry result, String[] attributes)
            throws LDAPException, TransientException
    {
        try
    {
        if (result.getAttribute(LDAP_NSACCOUNTLOCK) != null)
        {
@@ -798,12 +795,6 @@ public class LdapGroupDAO extends LdapDAO
                                        ownerDN + " group: " + entryDN);
        }
    }
        catch (URISyntaxException e)
        {
            logger.error("invalid group URI", e);
            throw new IllegalStateException("Invalid group URI", e);
        }
    }

    /**
     * @param groupID
+2 −10
Original line number Diff line number Diff line
@@ -787,18 +787,10 @@ public class LdapUserDAO extends LdapDAO
        String cn = groupDN.getRDNString();
        String[] parts = cn.split("=");
        if (parts.length == 2 && parts[0].equals("cn"))
        {
            try
        {
            GroupURI groupID = new GroupURI(gmsServiceURI.toString() + "?" + parts[1]);
            return new Group(groupID);
        }
            catch (URISyntaxException e)
            {
                logger.error("Illegal Group ID", e);
                throw new IllegalStateException("Illegal Group ID", e);
            }
        }
        throw new RuntimeException("BUG: failed to extract group name from " + groupDN
                .toString());
    }
+34 −33
Original line number Diff line number Diff line
@@ -82,10 +82,8 @@ public class GroupURI
{
    private static Logger log = Logger.getLogger(GroupURI.class);

    public static final String SCHEME = "ivo";
    public static final String PATH = "/gms";

    private URI uri;
    private String name;

    /**
     * Attempts to create a URI using the specified uri. The is expected
@@ -104,26 +102,12 @@ public class GroupURI
            throw new IllegalArgumentException("Null URI");
        }

        String fragment = uri.getFragment();
        if (fragment != null && fragment.length() > 0)
        {
            throw new IllegalArgumentException("Fragment not allowed in group URIs");
        }

        try
        {
            this.uri = new URI(uri.getScheme(), uri.getAuthority(),
                    uri.getPath(), uri.getQuery(), fragment);
        }
        catch (URISyntaxException e)
        {
            throw new IllegalArgumentException("URI malformed: " + uri.toString());
        }
        this.uri = uri;

        // Ensure the scheme is correct
        if (uri.getScheme() == null || !uri.getScheme().equalsIgnoreCase(SCHEME))
        if (uri.getScheme() == null)
        {
            throw new IllegalArgumentException("GroupURI scheme must be " + SCHEME);
            throw new IllegalArgumentException("GroupURI scheme is required.");
        }

        if (uri.getAuthority() == null)
@@ -131,20 +115,38 @@ public class GroupURI
            throw new IllegalArgumentException("Group authority is required.");
        }

        if (uri.getPath() == null || !uri.getPath().equalsIgnoreCase(PATH))
        {
            if (PATH.contains(uri.getAuthority()))
        if (uri.getPath() == null || uri.getPath().length() == 0)
        {
                throw new IllegalArgumentException("Missing authority");
            }
            throw new IllegalArgumentException("GroupURI path must be " + PATH);
            throw new IllegalArgumentException("Missing authority and/or path.");
        }

        if (uri.getQuery() == null)
        log.debug("URI: " + uri);
        log.debug("  scheme: " + uri.getScheme());
        log.debug("  authority: " + uri.getAuthority());
        log.debug("  path: " + uri.getPath());

        String fragment = uri.getFragment();
        String query = uri.getQuery();
        if (query == null)
        {
            if (fragment != null)
            {
                // allow the fragment to define the group name (old style)
                name = fragment;
            }
            else
            {
                throw new IllegalArgumentException("Group name is required.");
            }

        }
        else
        {
            if (fragment != null)
            {
                throw new IllegalArgumentException("Fragment not allowed in group URIs");
            }
            name = query;
        }
    }

    /**
@@ -152,9 +154,8 @@ public class GroupURI
     * that takes a URI object.
     */
    public GroupURI(String uri)
        throws URISyntaxException
    {
        this(new URI(uri));
        this(URI.create(uri));
    }

    @Override
@@ -167,7 +168,7 @@ public class GroupURI
        if (rhs instanceof GroupURI)
        {
            GroupURI vu = (GroupURI) rhs;
            return uri.equals(vu.uri);
            return uri.toString().equals(vu.uri.toString());
        }
        return false;
    }
@@ -199,7 +200,7 @@ public class GroupURI
     */
    public String getName()
    {
        return uri.getQuery();
        return name;
    }

    public URI getServiceID()
@@ -222,7 +223,7 @@ public class GroupURI
    @Override
    public String toString()
    {
        return uri.toString();
        return getServiceID() + "?" + name;
    }

}
+1 −13
Original line number Diff line number Diff line
@@ -489,19 +489,7 @@ public abstract class AbstractReaderWriter
            user = getUser(userElement);
        }

        GroupURI groupURI = null;
        try
        {
            groupURI = new GroupURI(uri);
        }
        catch (URISyntaxException e)
        {
            throw new ReaderException("Invalid uri: " + uri + ": " + e.getMessage());
        }
        catch (IllegalArgumentException e)
        {
            throw new ReaderException("Invalid group uri: " + uri + ": " + e.getMessage());
        }
        GroupURI groupURI = new GroupURI(uri);
        Group group = new Group(groupURI);

        // set owner field
+2 −2
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public class GroupTest
        {
            new Group(new GroupURI("ivo://example.org/New%Test%Group"));
        }
        catch(URISyntaxException e)
        catch(IllegalArgumentException e)
        {
            thrown = true;
        }
@@ -176,7 +176,7 @@ public class GroupTest
        {
            new Group(new GroupURI("ivo://example.org/New\\Test\\Group"));
        }
        catch(URISyntaxException e)
        catch(IllegalArgumentException e)
        {
            thrown = true;
        }
Loading