Skip to content
Snippets Groups Projects
Commit b3eb73e4 authored by Brian Major's avatar Brian Major
Browse files

issue-10 - reverted API changes in GMSClient

parent 7bd03087
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ repositories { ...@@ -13,7 +13,7 @@ repositories {
sourceCompatibility = 1.7 sourceCompatibility = 1.7
group = 'org.opencadc' group = 'org.opencadc'
version = '1.1.0' version = '1.1.1'
dependencies { dependencies {
compile 'log4j:log4j:1.2.+' compile 'log4j:log4j:1.2.+'
...@@ -22,7 +22,7 @@ dependencies { ...@@ -22,7 +22,7 @@ dependencies {
compile 'xerces:xercesImpl:2.+' compile 'xerces:xercesImpl:2.+'
compile 'com.unboundid:unboundid-ldapsdk:2.3.+' compile 'com.unboundid:unboundid-ldapsdk:2.3.+'
compile 'org.opencadc:cadc-access-control:1.1.+' compile 'org.opencadc:cadc-access-control:[1.1.1,)'
compile 'org.opencadc:cadc-util:1.+' compile 'org.opencadc:cadc-util:1.+'
compile 'org.opencadc:cadc-log:1.+' compile 'org.opencadc:cadc-log:1.+'
compile 'org.opencadc:cadc-registry:1.+' compile 'org.opencadc:cadc-registry:1.+'
......
...@@ -15,7 +15,7 @@ sourceCompatibility = 1.7 ...@@ -15,7 +15,7 @@ sourceCompatibility = 1.7
group = 'org.opencadc' group = 'org.opencadc'
version = '1.1.0' version = '1.1.1'
mainClassName = 'ca.nrc.cadc.ac.client.GMSClientMain' mainClassName = 'ca.nrc.cadc.ac.client.GMSClientMain'
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
package ca.nrc.cadc.ac.client; package ca.nrc.cadc.ac.client;
import java.net.URI;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.AccessController; import java.security.AccessController;
import java.security.Principal; import java.security.Principal;
...@@ -95,10 +96,10 @@ import ca.nrc.cadc.util.Log4jInit; ...@@ -95,10 +96,10 @@ import ca.nrc.cadc.util.Log4jInit;
* only used for testing. Should not be used for production * only used for testing. Should not be used for production
* work. * work.
*/ */
public class GMSClientMain implements PrivilegedAction<Object> public class Main implements PrivilegedAction<Object>
{ {
private static Logger log = Logger.getLogger(GMSClientMain.class); private static Logger log = Logger.getLogger(Main.class);
public static final String ARG_ADD_MEMBER = "add-member"; public static final String ARG_ADD_MEMBER = "add-member";
public static final String ARG_DEL_MEMBER = "remove-member"; public static final String ARG_DEL_MEMBER = "remove-member";
...@@ -118,12 +119,11 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -118,12 +119,11 @@ public class GMSClientMain implements PrivilegedAction<Object>
public static final String ARG_V = "v"; public static final String ARG_V = "v";
public static final String ARG_D = "d"; public static final String ARG_D = "d";
private GMSClient client;
private ArgumentMap argMap; private ArgumentMap argMap;
private GMSClientMain() private Main(ArgumentMap args)
{ {
client = new GMSClient(); this.argMap = args;
} }
public static void main(String[] args) public static void main(String[] args)
...@@ -149,8 +149,7 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -149,8 +149,7 @@ public class GMSClientMain implements PrivilegedAction<Object>
else else
Log4jInit.setLevel("ca", Level.WARN); Log4jInit.setLevel("ca", Level.WARN);
GMSClientMain main = new GMSClientMain(); Main main = new Main(argMap);
main.argMap = argMap;
Subject subject = CertCmdArgUtil.initSubject(argMap, true); Subject subject = CertCmdArgUtil.initSubject(argMap, true);
...@@ -192,15 +191,15 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -192,15 +191,15 @@ public class GMSClientMain implements PrivilegedAction<Object>
private static void usage() private static void usage()
{ {
System.out.println("--create --group=<g>"); System.out.println("--create --group=<uri>");
System.out.println("--get --group=<g>"); System.out.println("--get --group=<uri>");
System.out.println("--delete --group=<g>"); System.out.println("--delete --group=<uri>");
System.out.println(); System.out.println();
System.out.println("--add-member --group=<g> --userid=<u>"); System.out.println("--add-member --group=<uri> --userid=<u>");
System.out.println("--remove-member --group=<g> --userid=<u>"); System.out.println("--remove-member --group=<uri> --userid=<u>");
System.out.println(); System.out.println();
System.out.println("--add-admin --group=<g> --userid=<u>"); System.out.println("--add-admin --group=<uri> --userid=<u>");
System.out.println("--remove-admin --group=<g> --userid=<u>"); System.out.println("--remove-admin --group=<uri> --userid=<u>");
} }
@Override @Override
...@@ -209,12 +208,14 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -209,12 +208,14 @@ public class GMSClientMain implements PrivilegedAction<Object>
try try
{ {
String command = getCommand(); String command = getCommand();
String suri = argMap.getValue(ARG_GROUP);
GroupURI groupID = null; GroupURI guri = new GroupURI(new URI(suri));
GMSClient client = new GMSClient(guri.getServiceID());
String group = guri.getName();
if (command.equals(ARG_ADD_MEMBER)) if (command.equals(ARG_ADD_MEMBER))
{ {
String group = argMap.getValue(ARG_GROUP);
String userID = argMap.getValue(ARG_USERID); String userID = argMap.getValue(ARG_USERID);
if (group == null) if (group == null)
...@@ -223,11 +224,10 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -223,11 +224,10 @@ public class GMSClientMain implements PrivilegedAction<Object>
if (userID == null) if (userID == null)
throw new IllegalArgumentException("No userid specified"); throw new IllegalArgumentException("No userid specified");
client.addUserMember(new GroupURI(group), new HttpPrincipal(userID)); client.addUserMember(group, new HttpPrincipal(userID));
} }
else if (command.equals(ARG_DEL_MEMBER)) else if (command.equals(ARG_DEL_MEMBER))
{ {
String group = argMap.getValue(ARG_GROUP);
if (group == null) if (group == null)
throw new IllegalArgumentException("No group specified"); throw new IllegalArgumentException("No group specified");
...@@ -235,11 +235,10 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -235,11 +235,10 @@ public class GMSClientMain implements PrivilegedAction<Object>
if (member == null) if (member == null)
throw new IllegalArgumentException("No user specified"); throw new IllegalArgumentException("No user specified");
client.removeUserMember(new GroupURI(group), new HttpPrincipal(member)); client.removeUserMember(group, new HttpPrincipal(member));
} }
else if (command.equals(ARG_ADD_ADMIN)) else if (command.equals(ARG_ADD_ADMIN))
{ {
String group = argMap.getValue(ARG_GROUP);
String userID = argMap.getValue(ARG_USERID); String userID = argMap.getValue(ARG_USERID);
if (group == null) if (group == null)
...@@ -249,7 +248,7 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -249,7 +248,7 @@ public class GMSClientMain implements PrivilegedAction<Object>
throw new IllegalArgumentException("No userid specified"); throw new IllegalArgumentException("No userid specified");
HttpPrincipal hp = new HttpPrincipal(userID); HttpPrincipal hp = new HttpPrincipal(userID);
Group cur = client.getGroup(new GroupURI(group)); Group cur = client.getGroup(group);
boolean update = true; boolean update = true;
for (User admin : cur.getUserAdmins()) for (User admin : cur.getUserAdmins())
{ {
...@@ -280,7 +279,6 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -280,7 +279,6 @@ public class GMSClientMain implements PrivilegedAction<Object>
} }
else if (command.equals(ARG_DEL_ADMIN)) else if (command.equals(ARG_DEL_ADMIN))
{ {
String group = argMap.getValue(ARG_GROUP);
if (group == null) if (group == null)
throw new IllegalArgumentException("No group specified"); throw new IllegalArgumentException("No group specified");
...@@ -289,7 +287,7 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -289,7 +287,7 @@ public class GMSClientMain implements PrivilegedAction<Object>
throw new IllegalArgumentException("No user specified"); throw new IllegalArgumentException("No user specified");
HttpPrincipal hp = new HttpPrincipal(userID); HttpPrincipal hp = new HttpPrincipal(userID);
Group cur = client.getGroup(new GroupURI(group)); Group cur = client.getGroup(group);
boolean update = false; boolean update = false;
Iterator<User> iter = cur.getUserAdmins().iterator(); Iterator<User> iter = cur.getUserAdmins().iterator();
while (iter.hasNext()) while (iter.hasNext())
...@@ -319,29 +317,15 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -319,29 +317,15 @@ public class GMSClientMain implements PrivilegedAction<Object>
} }
else if (command.equals(ARG_CREATE_GROUP)) else if (command.equals(ARG_CREATE_GROUP))
{ {
String group = argMap.getValue(ARG_GROUP);
if (group == null) if (group == null)
throw new IllegalArgumentException("No group specified"); throw new IllegalArgumentException("No group specified");
GroupURI groupURI = null;
try
{
groupURI = new GroupURI(group);
}
catch (Exception e)
{
String message = "Invalid group URI format '" +
group + "': " + e.getMessage();
log.debug(message, e);
throw new IllegalArgumentException(message);
}
AccessControlContext accessControlContext = AccessController.getContext(); AccessControlContext accessControlContext = AccessController.getContext();
Subject subject = Subject.getSubject(accessControlContext); Subject subject = Subject.getSubject(accessControlContext);
Set<X500Principal> principals = subject.getPrincipals(X500Principal.class); Set<X500Principal> principals = subject.getPrincipals(X500Principal.class);
X500Principal p = principals.iterator().next(); X500Principal p = principals.iterator().next();
Group g = new Group(groupURI); Group g = new Group(guri);
User member = new User(); User member = new User();
member.getIdentities().add(p); member.getIdentities().add(p);
...@@ -350,11 +334,10 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -350,11 +334,10 @@ public class GMSClientMain implements PrivilegedAction<Object>
} }
else if (command.equals(ARG_GET_GROUP)) else if (command.equals(ARG_GET_GROUP))
{ {
String group = argMap.getValue(ARG_GROUP);
if (group == null) if (group == null)
throw new IllegalArgumentException("No group specified"); throw new IllegalArgumentException("No group specified");
Group g = client.getGroup(new GroupURI(group)); Group g = client.getGroup(group);
System.out.println("found: " + g.getID()); System.out.println("found: " + g.getID());
System.out.println("\t" + g.description); System.out.println("\t" + g.description);
System.out.println("owner: " + g.getOwner()); System.out.println("owner: " + g.getOwner());
...@@ -374,11 +357,10 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -374,11 +357,10 @@ public class GMSClientMain implements PrivilegedAction<Object>
} }
else if (command.equals(ARG_DELETE_GROUP)) else if (command.equals(ARG_DELETE_GROUP))
{ {
String group = argMap.getValue(ARG_GROUP);
if (group == null) if (group == null)
throw new IllegalArgumentException("No group specified"); throw new IllegalArgumentException("No group specified");
client.deleteGroup(new GroupURI(group)); client.deleteGroup(group);
} }
return null; return null;
...@@ -389,4 +371,4 @@ public class GMSClientMain implements PrivilegedAction<Object> ...@@ -389,4 +371,4 @@ public class GMSClientMain implements PrivilegedAction<Object>
return t; return t;
} }
} }
} }
\ No newline at end of file
...@@ -115,11 +115,13 @@ public class GMSClientTest ...@@ -115,11 +115,13 @@ public class GMSClientTest
final RegistryClient mockRegistryClient = final RegistryClient mockRegistryClient =
createMock(RegistryClient.class); createMock(RegistryClient.class);
// expect(mockRegistryClient.getServiceURL(serviceID, Standards.UMS_USERS_01, AuthMethod.CERT)) final URI serviceID = URI.create("ivo://mysite.com/users");
// .andReturn(new URL("http://mysite.com/users"));
expect(mockRegistryClient.getServiceURL(serviceID, Standards.UMS_USERS_01, AuthMethod.CERT))
.andReturn(new URL("http://mysite.com/users"));
replay(mockRegistryClient); replay(mockRegistryClient);
GMSClient client = new GMSClient() GMSClient client = new GMSClient(serviceID)
{ {
@Override @Override
protected RegistryClient getRegistryClient() protected RegistryClient getRegistryClient()
...@@ -149,15 +151,15 @@ public class GMSClientTest ...@@ -149,15 +151,15 @@ public class GMSClientTest
final HttpPrincipal test1UserID = new HttpPrincipal("test"); final HttpPrincipal test1UserID = new HttpPrincipal("test");
subject.getPrincipals().add(test1UserID); subject.getPrincipals().add(test1UserID);
final URI serviceID = URI.create("ivo://example.org/gms"); final URI serviceID = URI.create("ivo://mysite.com/users");
final RegistryClient mockRegistryClient = final RegistryClient mockRegistryClient =
createMock(RegistryClient.class); createMock(RegistryClient.class);
expect(mockRegistryClient.getServiceURL(serviceID, Standards.GMS_GROUPS_01, AuthMethod.CERT )) expect(mockRegistryClient.getServiceURL(serviceID, Standards.GMS_GROUPS_01, AuthMethod.CERT ))
.andReturn(new URL("http://example.org/gms")); .andReturn(new URL("http://mysite.com/users"));
replay(mockRegistryClient); replay(mockRegistryClient);
final GMSClient client = new GMSClient() final GMSClient client = new GMSClient(serviceID)
{ {
@Override @Override
protected RegistryClient getRegistryClient() protected RegistryClient getRegistryClient()
...@@ -173,42 +175,46 @@ public class GMSClientTest ...@@ -173,42 +175,46 @@ public class GMSClientTest
{ {
List<Group> initial = client List<Group> initial = client
.getCachedGroups(serviceID, test1UserID, Role.MEMBER, true); .getCachedGroups(test1UserID, Role.MEMBER, true);
Assert.assertNull("Cache should be null", initial); Assert.assertNull("Cache should be null", initial);
// add single group as isMember might do // add single group as isMember might do
GroupURI group0uri = new GroupURI("ivo://example.org/gms?0"); GroupURI group0uri = new GroupURI("ivo://example.org/gms?0");
Group group0 = new Group(group0uri); Group group0 = new Group(group0uri);
client.addCachedGroup(test1UserID, group0, Role.MEMBER); client.addCachedGroup(test1UserID, group0, Role.MEMBER);
List<Group> actual = client.getCachedGroups(serviceID, test1UserID, Role.MEMBER, true); List<Group> actual = client
.getCachedGroups(test1UserID, Role.MEMBER, true);
Assert.assertNull("Cache should be null", actual); Assert.assertNull("Cache should be null", actual);
Group g = client.getCachedGroup(test1UserID, group0uri, Role.MEMBER); Group g = client
.getCachedGroup(test1UserID, "0", Role.MEMBER);
Assert.assertNotNull("cached group from incomplete cache", g); Assert.assertNotNull("cached group from incomplete cache", g);
// add all groups like getMemberships might do // add all groups like getMemberships might do
List<Group> expected = new ArrayList<Group>(); List<Group> expected = new ArrayList<Group>();
Group group1 = new Group(new GroupURI("ivo://example.org/gms?1")); GroupURI group1uri = new GroupURI("ivo://example.org/gms?1");
Group group2 = new Group(new GroupURI("ivo://example.org/gms?2")); GroupURI group2uri = new GroupURI("ivo://example.org/gms?2");
Group group1 = new Group(group1uri);
Group group2 = new Group(group2uri);
expected.add(group0); expected.add(group0);
expected.add(group1); expected.add(group1);
expected.add(group2); expected.add(group2);
client.setCachedGroups(serviceID, test1UserID, expected, Role.MEMBER); client.setCachedGroups(test1UserID, expected, Role.MEMBER);
actual = client actual = client
.getCachedGroups(serviceID, test1UserID, Role.MEMBER, true); .getCachedGroups(test1UserID, Role.MEMBER, true);
Assert.assertEquals("Wrong cached groups", expected, actual); Assert.assertEquals("Wrong cached groups", expected, actual);
// check against another role // check against another role
actual = client actual = client
.getCachedGroups(serviceID, test1UserID, Role.OWNER, true); .getCachedGroups(test1UserID, Role.OWNER, true);
Assert.assertNull("Cache should be null", actual); Assert.assertNull("Cache should be null", actual);
// check against another userid // check against another userid
final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser"); final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser");
actual = client actual = client
.getCachedGroups(serviceID, anotherUserID, Role.MEMBER, true); .getCachedGroups(anotherUserID, Role.MEMBER, true);
Assert.assertNull("Cache should be null", actual); Assert.assertNull("Cache should be null", actual);
return null; return null;
...@@ -228,7 +234,7 @@ public class GMSClientTest ...@@ -228,7 +234,7 @@ public class GMSClientTest
{ {
List<Group> initial = client List<Group> initial = client
.getCachedGroups(serviceID, test2UserID, Role.MEMBER, true); .getCachedGroups(test2UserID, Role.MEMBER, true);
Assert.assertNull("Cache should be null", initial); Assert.assertNull("Cache should be null", initial);
List<Group> expected = new ArrayList<Group>(); List<Group> expected = new ArrayList<Group>();
...@@ -237,21 +243,21 @@ public class GMSClientTest ...@@ -237,21 +243,21 @@ public class GMSClientTest
expected.add(group1); expected.add(group1);
expected.add(group2); expected.add(group2);
client.setCachedGroups(serviceID, test2UserID, expected, Role.MEMBER); client.setCachedGroups(test2UserID, expected, Role.MEMBER);
List<Group> actual = client List<Group> actual = client
.getCachedGroups(serviceID, test2UserID, Role.MEMBER, true); .getCachedGroups(test2UserID, Role.MEMBER, true);
Assert.assertEquals("Wrong cached groups", expected, actual); Assert.assertEquals("Wrong cached groups", expected, actual);
// check against another role // check against another role
actual = client actual = client
.getCachedGroups(serviceID, test2UserID, Role.OWNER, true); .getCachedGroups(test2UserID, Role.OWNER, true);
Assert.assertNull("Cache should be null", actual); Assert.assertNull("Cache should be null", actual);
// check against another userid // check against another userid
final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser"); final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser");
actual = client actual = client
.getCachedGroups(serviceID, anotherUserID, Role.MEMBER, true); .getCachedGroups(anotherUserID, Role.MEMBER, true);
Assert.assertNull("Cache should be null", actual); Assert.assertNull("Cache should be null", actual);
return null; return null;
...@@ -261,7 +267,7 @@ public class GMSClientTest ...@@ -261,7 +267,7 @@ public class GMSClientTest
// do the same without a subject // do the same without a subject
List<Group> initial = client List<Group> initial = client
.getCachedGroups(serviceID, test1UserID, Role.MEMBER, true); .getCachedGroups(test1UserID, Role.MEMBER, true);
Assert.assertNull("Cache should be null", initial); Assert.assertNull("Cache should be null", initial);
List<Group> newgroups = new ArrayList<Group>(); List<Group> newgroups = new ArrayList<Group>();
...@@ -270,10 +276,10 @@ public class GMSClientTest ...@@ -270,10 +276,10 @@ public class GMSClientTest
newgroups.add(group1); newgroups.add(group1);
newgroups.add(group2); newgroups.add(group2);
client.setCachedGroups(serviceID, test1UserID, newgroups, Role.MEMBER); client.setCachedGroups(test1UserID, newgroups, Role.MEMBER);
List<Group> actual = client List<Group> actual = client
.getCachedGroups(serviceID, test1UserID, Role.MEMBER, true); .getCachedGroups(test1UserID, Role.MEMBER, true);
Assert.assertNull("Cache should still be null", actual); Assert.assertNull("Cache should still be null", actual);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment