Loading cadc-access-control-server/src/main/java/ca/nrc/cadc/ac/server/ldap/LdapGroupDAO.java +32 −41 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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 Loading cadc-access-control-server/src/main/java/ca/nrc/cadc/ac/server/ldap/LdapUserDAO.java +2 −10 Original line number Diff line number Diff line Loading @@ -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()); } Loading cadc-access-control/src/main/java/ca/nrc/cadc/ac/GroupURI.java +34 −33 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading @@ -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; } } /** Loading @@ -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 Loading @@ -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; } Loading Loading @@ -199,7 +200,7 @@ public class GroupURI */ public String getName() { return uri.getQuery(); return name; } public URI getServiceID() Loading @@ -222,7 +223,7 @@ public class GroupURI @Override public String toString() { return uri.toString(); return getServiceID() + "?" + name; } } cadc-access-control/src/main/java/ca/nrc/cadc/ac/xml/AbstractReaderWriter.java +1 −13 Original line number Diff line number Diff line Loading @@ -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 Loading cadc-access-control/src/test/java/ca/nrc/cadc/ac/GroupTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -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 Loading
cadc-access-control-server/src/main/java/ca/nrc/cadc/ac/server/ldap/LdapGroupDAO.java +32 −41 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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 Loading
cadc-access-control-server/src/main/java/ca/nrc/cadc/ac/server/ldap/LdapUserDAO.java +2 −10 Original line number Diff line number Diff line Loading @@ -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()); } Loading
cadc-access-control/src/main/java/ca/nrc/cadc/ac/GroupURI.java +34 −33 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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) Loading @@ -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; } } /** Loading @@ -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 Loading @@ -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; } Loading Loading @@ -199,7 +200,7 @@ public class GroupURI */ public String getName() { return uri.getQuery(); return name; } public URI getServiceID() Loading @@ -222,7 +223,7 @@ public class GroupURI @Override public String toString() { return uri.toString(); return getServiceID() + "?" + name; } }
cadc-access-control/src/main/java/ca/nrc/cadc/ac/xml/AbstractReaderWriter.java +1 −13 Original line number Diff line number Diff line Loading @@ -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 Loading
cadc-access-control/src/test/java/ca/nrc/cadc/ac/GroupTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -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