Skip to content
Snippets Groups Projects
Commit 9441f331 authored by Jeff Burke's avatar Jeff Burke
Browse files

Merge branch 's1666' of ssh://mach16/srv/cadc/git/wopencadc into s1666

parents 166e816e af9390c7
No related branches found
No related tags found
No related merge requests found
...@@ -88,6 +88,7 @@ import ca.nrc.cadc.ac.Role; ...@@ -88,6 +88,7 @@ import ca.nrc.cadc.ac.Role;
import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.ac.UserNotFoundException;
import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.net.TransientException;
import ca.nrc.cadc.util.StringUtil;
import com.unboundid.ldap.sdk.AddRequest; import com.unboundid.ldap.sdk.AddRequest;
import com.unboundid.ldap.sdk.Attribute; import com.unboundid.ldap.sdk.Attribute;
...@@ -214,7 +215,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO ...@@ -214,7 +215,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
attributes.add(new Attribute("objectClass", "groupofuniquenames")); attributes.add(new Attribute("objectClass", "groupofuniquenames"));
attributes.add(new Attribute("cn", groupID)); attributes.add(new Attribute("cn", groupID));
if (description != null) if (StringUtil.hasText(description))
{ {
attributes.add(new Attribute("description", description)); attributes.add(new Attribute("description", description));
} }
......
...@@ -140,20 +140,21 @@ public class GMSClientTest ...@@ -140,20 +140,21 @@ public class GMSClientTest
try try
{ {
Subject subject = new Subject(); Subject subject = new Subject();
final HttpPrincipal userID = new HttpPrincipal("test"); final HttpPrincipal test1UserID = new HttpPrincipal("test");
subject.getPrincipals().add(userID); subject.getPrincipals().add(test1UserID);
RegistryClient regClient = new RegistryClient();
URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI),
"https");
final GMSClient client = new GMSClient(baseURL.toString());
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() Subject.doAs(subject, new PrivilegedExceptionAction<Object>()
{ {
@Override @Override
public Object run() throws Exception public Object run() throws Exception
{ {
RegistryClient regClient = new RegistryClient();
URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI),
"https");
GMSClient client = new GMSClient(baseURL.toString());
List<Group> initial = client.getCachedGroups(userID, Role.MEMBER); List<Group> initial = client.getCachedGroups(test1UserID, Role.MEMBER);
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>();
...@@ -162,31 +163,65 @@ public class GMSClientTest ...@@ -162,31 +163,65 @@ public class GMSClientTest
expected.add(group1); expected.add(group1);
expected.add(group2); expected.add(group2);
client.setCachedGroups(userID, expected, Role.MEMBER); client.setCachedGroups(test1UserID, expected, Role.MEMBER);
List<Group> actual = client.getCachedGroups(userID, Role.MEMBER); List<Group> actual = client.getCachedGroups(test1UserID, Role.MEMBER);
Assert.assertEquals("Wrong cached groups", expected, actual); Assert.assertEquals("Wrong cached groups", expected, actual);
// check against another role // check against another role
actual = client.getCachedGroups(userID, Role.OWNER); actual = client.getCachedGroups(test1UserID, Role.OWNER);
Assert.assertNull("Cache should be null", actual); Assert.assertNull("Cache should be null", actual);
// check against another userid // check against another userid
final HttpPrincipal userID2 = new HttpPrincipal("test2"); final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser");
actual = client.getCachedGroups(userID2, Role.MEMBER); actual = client.getCachedGroups(anotherUserID, Role.MEMBER);
Assert.assertNull("Cache should be null", actual); Assert.assertNull("Cache should be null", actual);
return null; return null;
} }
}); });
subject = new Subject();
final HttpPrincipal test2UserID = new HttpPrincipal("test2");
subject.getPrincipals().add(test2UserID);
// do the same but as a different user
Subject.doAs(subject, new PrivilegedExceptionAction<Object>()
{
@Override
public Object run() throws Exception
{
List<Group> initial = client.getCachedGroups(test2UserID, Role.MEMBER);
Assert.assertNull("Cache should be null", initial);
List<Group> expected = new ArrayList<Group>();
Group group1 = new Group("1");
Group group2 = new Group("2");
expected.add(group1);
expected.add(group2);
client.setCachedGroups(test2UserID, expected, Role.MEMBER);
List<Group> actual = client.getCachedGroups(test2UserID, Role.MEMBER);
Assert.assertEquals("Wrong cached groups", expected, actual);
// check against another role
actual = client.getCachedGroups(test2UserID, Role.OWNER);
Assert.assertNull("Cache should be null", actual);
// check against another userid
final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser");
actual = client.getCachedGroups(anotherUserID, Role.MEMBER);
Assert.assertNull("Cache should be null", actual);
return null;
}
});
// do the same without a subject // do the same without a subject
RegistryClient regClient = new RegistryClient();
URL baseURL = regClient.getServiceURL(new URI(AC.GMS_SERVICE_URI),
"https");
GMSClient client = new GMSClient(baseURL.toString());
List<Group> initial = client.getCachedGroups(userID, Role.MEMBER); List<Group> initial = client.getCachedGroups(test1UserID, Role.MEMBER);
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>();
...@@ -195,9 +230,9 @@ public class GMSClientTest ...@@ -195,9 +230,9 @@ public class GMSClientTest
newgroups.add(group1); newgroups.add(group1);
newgroups.add(group2); newgroups.add(group2);
client.setCachedGroups(userID, newgroups, Role.MEMBER); client.setCachedGroups(test1UserID, newgroups, Role.MEMBER);
List<Group> actual = client.getCachedGroups(userID, Role.MEMBER); List<Group> actual = client.getCachedGroups(test1UserID, Role.MEMBER);
Assert.assertNull("Cache should still be null", actual); Assert.assertNull("Cache should still be null", actual);
} }
catch (Throwable t) catch (Throwable t)
......
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