Commit 814bfe88 authored by Brian Major's avatar Brian Major
Browse files

s1885 - Removed hardcoded references to AC service URIs

parent 7b9232ef
......@@ -115,6 +115,9 @@
<mkdir dir="${user.home}/config" />
<copy overwrite="true" file="test/LdapConfig.test.properties"
todir="${user.home}/config/"/>
<copy overwrite="true"
file="${env.CADC_PREFIX}/etc/LocalAuthority.properties"
tofile="${build}/class/LocalAuthority.properties"/>
</target>
<!-- JAR files needed to run the test suite -->
......
......@@ -1273,11 +1273,6 @@ public class LdapUserDAO extends LdapDAO
return uuid.getLeastSignificantBits();
}
protected void setInternalIdUriPrefix(String internalIdUriPrefix)
{
this.internalIdUriPrefix = internalIdUriPrefix;
}
protected InternalID getInternalID(String numericID)
{
UUID uuid = new UUID(0L, Long.parseLong(numericID));
......
......@@ -81,10 +81,10 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import ca.nrc.cadc.ac.AC;
import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.log.ServletLogInfo;
import ca.nrc.cadc.reg.client.LocalAuthority;
import ca.nrc.cadc.reg.client.RegistryClient;
/**
......@@ -164,9 +164,15 @@ public class WhoAmIServlet extends HttpServlet
final String scheme) throws IOException
{
final RegistryClient registryClient = getRegistryClient();
LocalAuthority localAuthority = new LocalAuthority();
URI umsServiceURI = localAuthority.getServiceURI("ums");
log.debug("ums service uri: " + umsServiceURI);
final URL redirectURL =
registryClient.getServiceURL(
URI.create(AC.UMS_SERVICE_URI + "#users"), scheme, USER_GET_PATH);
URI.create(umsServiceURI.toString() + "#users"), scheme, USER_GET_PATH);
// Take the first one.
final String redirectUrl =
......
......@@ -84,8 +84,8 @@ import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import ca.nrc.cadc.ac.AC;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.reg.client.LocalAuthority;
import ca.nrc.cadc.reg.client.RegistryClient;
......@@ -132,7 +132,10 @@ public class WhoAmIServletTest
mockResponse.sendRedirect("/ac/users/CADCtest?idType=HTTP");
expectLastCall().once();
expect(mockRegistry.getServiceURL(URI.create(AC.UMS_SERVICE_URI + "#users"),
LocalAuthority localAuthority = new LocalAuthority();
URI umsServiceURI = localAuthority.getServiceURI("ums");
expect(mockRegistry.getServiceURL(URI.create(umsServiceURI.toString() + "#users"),
"http", "/%s?idType=HTTP")).
andReturn(new URL("http://mysite.com/ac/users/CADCtest?idType=HTTP")).once();
......
......@@ -77,10 +77,6 @@ import java.util.UUID;
import javax.security.auth.x500.X500Principal;
import ca.nrc.cadc.ac.AC;
import ca.nrc.cadc.ac.InternalID;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.util.ObjectUtil;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.easymock.EasyMock;
......@@ -88,13 +84,17 @@ import org.junit.BeforeClass;
import org.junit.Test;
import ca.nrc.cadc.ac.Group;
import ca.nrc.cadc.ac.InternalID;
import ca.nrc.cadc.ac.MemberNotFoundException;
import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.server.GroupPersistence;
import ca.nrc.cadc.ac.server.UserPersistence;
import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.auth.IdentityType;
import ca.nrc.cadc.reg.client.LocalAuthority;
import ca.nrc.cadc.util.Log4jInit;
import ca.nrc.cadc.util.ObjectUtil;
/**
*
......@@ -117,7 +117,9 @@ public class RemoveUserMemberActionTest
try
{
User user = new User();
InternalID internalID = new InternalID(new URI(AC.USER_URI + "?" + UUID.randomUUID()));
LocalAuthority localAuthority = new LocalAuthority();
URI umsServiceURI = localAuthority.getServiceURI("ums");
InternalID internalID = new InternalID(new URI(umsServiceURI.toASCIIString() + "?" + UUID.randomUUID()));
ObjectUtil.setField(user, internalID, "id");
String userID = "cn=foo,c=ca";
......@@ -169,7 +171,9 @@ public class RemoveUserMemberActionTest
try
{
User user = new User();
InternalID internalID = new InternalID(new URI(AC.USER_URI + "?" + UUID.randomUUID()));
LocalAuthority localAuthority = new LocalAuthority();
URI umsServiceURI = localAuthority.getServiceURI("ums");
InternalID internalID = new InternalID(new URI(umsServiceURI.toString() + "?" + UUID.randomUUID()));
ObjectUtil.setField(user, internalID, "id");
String userID = "cn=foo,c=ca";
......
......@@ -114,6 +114,12 @@
<property name="jsonassert" value="${ext.dev}/jsonassert.jar" />
<property name="testingJars" value="${build}/class:${jsonassert}:${jars}:${xerces}:${asm}:${cglib}:${easymock}:${junit}:${objenesis}" />
<target name="setup-test">
<copy overwrite="true"
file="${env.CADC_PREFIX}/etc/LocalAuthority.properties"
tofile="${build}/class/LocalAuthority.properties"/>
</target>
<target name="single-test" depends="compile,compile-test">
<echo message="Running test suite..." />
......
......@@ -85,10 +85,4 @@ public class AC
// Denotes a group readable by public
public static final String PROPERTY_PUBLIC = "ivo://ivoa.net/gms#public";
public static final String UMS_SERVICE_URI = "ivo://cadc.nrc.ca/ums";
public static final String GMS_SERVICE_URI = "ivo://cadc.nrc.ca/gms";
// Group URI attribute once the group name is appended
public static final String GROUP_URI = "ivo://cadc.nrc.ca/gms#";
}
......@@ -69,7 +69,26 @@
package ca.nrc.cadc.ac.xml;
import ca.nrc.cadc.ac.AC;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.Principal;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.security.auth.x500.X500Principal;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import ca.nrc.cadc.ac.Group;
import ca.nrc.cadc.ac.GroupProperty;
import ca.nrc.cadc.ac.InternalID;
......@@ -85,24 +104,7 @@ import ca.nrc.cadc.auth.IdentityType;
import ca.nrc.cadc.auth.NumericPrincipal;
import ca.nrc.cadc.auth.OpenIdPrincipal;
import ca.nrc.cadc.date.DateUtil;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import javax.security.auth.x500.X500Principal;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.Principal;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import ca.nrc.cadc.reg.client.LocalAuthority;
/**
* AbstractReaderWriter TODO describe class
......@@ -149,6 +151,15 @@ public abstract class AbstractReaderWriter
public static final String USER_MEMBERS = "userMembers";
public static final String USER_REQUEST = "userRequest";
private String gmsServiceURI;
public AbstractReaderWriter()
{
LocalAuthority localAuthority = new LocalAuthority();
URI serviceURI = localAuthority.getServiceURI("gms");
gmsServiceURI = serviceURI.toString();
}
/**
* Write to root Element to a writer.
*
......@@ -469,13 +480,13 @@ public abstract class AbstractReaderWriter
}
// Group groupID
int index = uri.indexOf(AC.GROUP_URI);
int index = uri.indexOf(gmsServiceURI);
if (index == -1)
{
String error = "group uri attribute malformed: " + uri;
throw new ReaderException(error);
}
String groupID = uri.substring(AC.GROUP_URI.length());
String groupID = uri.substring(gmsServiceURI.length() + 1);
// Group owner
User user = null;
......@@ -922,7 +933,7 @@ public abstract class AbstractReaderWriter
// Create the root group element.
Element groupElement = new Element(GROUP);
String groupURI = AC.GROUP_URI + group.getID();
String groupURI = gmsServiceURI + "#" + group.getID();
groupElement.setAttribute(new Attribute(URI, groupURI));
// Group owner
......
......@@ -84,10 +84,9 @@ import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;
import ca.nrc.cadc.ac.AC;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.auth.NumericPrincipal;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.reg.client.LocalAuthority;
import ca.nrc.cadc.util.Log4jInit;
......@@ -96,9 +95,13 @@ public class UserClientTest
private static final Logger log = Logger.getLogger(UserClientTest.class);
private URI umsServiceURI;
public UserClientTest()
{
Log4jInit.setLevel("ca.nrc.cadc.ac", Level.INFO);
LocalAuthority localAuthority = new LocalAuthority();
umsServiceURI = localAuthority.getServiceURI("ums");
}
@Test
......@@ -178,9 +181,7 @@ public class UserClientTest
protected UserClient createUserClient() throws URISyntaxException, MalformedURLException
{
RegistryClient regClient = new RegistryClient();
URI serviceURI = new URI(AC.UMS_SERVICE_URI);
return new UserClient(serviceURI);
return new UserClient(umsServiceURI);
}
......@@ -189,7 +190,7 @@ public class UserClientTest
{
try
{
UserClient c = new UserClient(new URI(AC.UMS_SERVICE_URI));
UserClient c = new UserClient(umsServiceURI);
Subject s = new Subject();
s.getPrincipals().add(new HttpPrincipal("bob"));
......@@ -209,7 +210,7 @@ public class UserClientTest
{
try
{
UserClient c = new UserClient(new URI(AC.UMS_SERVICE_URI));
UserClient c = new UserClient(umsServiceURI);
Subject s = new Subject();
s.getPrincipals().add(new HttpPrincipal("bob"));
......@@ -231,7 +232,7 @@ public class UserClientTest
{
try
{
UserClient c = new UserClient(new URI(AC.UMS_SERVICE_URI));
UserClient c = new UserClient(umsServiceURI);
Subject s = new Subject();
UUID uuid = UUID.randomUUID();
......@@ -253,7 +254,7 @@ public class UserClientTest
{
try
{
UserClient c = new UserClient(new URI(AC.UMS_SERVICE_URI));
UserClient c = new UserClient(umsServiceURI);
Subject s = new Subject();
UUID uuid = UUID.randomUUID();
......
......@@ -71,7 +71,6 @@ package ca.nrc.cadc.tomcat;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
......@@ -79,11 +78,6 @@ import java.security.Principal;
import java.util.Arrays;
import java.util.List;
import org.apache.catalina.realm.GenericPrincipal;
import org.apache.catalina.realm.RealmBase;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
/**
* Custom class for Tomcat realm authentication.
*
......@@ -98,7 +92,7 @@ public class CadcBasicAuthenticator extends RealmBase
{
private static Logger log = Logger.getLogger(CadcBasicAuthenticator.class);
private static final String AC_URI = "ivo://canfar.net/ums";
private static final String AC_URI = "ivo://cadc.nrc.ca/ums";
static
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment