Loading projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapGroupDAO.java +2 −1 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ import ca.nrc.cadc.ac.Role; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.util.StringUtil; import com.unboundid.ldap.sdk.AddRequest; import com.unboundid.ldap.sdk.Attribute; Loading Loading @@ -214,7 +215,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO attributes.add(new Attribute("objectClass", "groupofuniquenames")); attributes.add(new Attribute("cn", groupID)); if (description != null) if (StringUtil.hasText(description)) { attributes.add(new Attribute("description", description)); } Loading projects/cadcAccessControl/test/src/ca/nrc/cadc/ac/client/GMSClientTest.java +54 −19 Original line number Diff line number Diff line Loading @@ -140,20 +140,21 @@ public class GMSClientTest try { Subject subject = new Subject(); final HttpPrincipal userID = new HttpPrincipal("test"); subject.getPrincipals().add(userID); final HttpPrincipal test1UserID = new HttpPrincipal("test"); 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>() { @Override 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); List<Group> expected = new ArrayList<Group>(); Loading @@ -162,18 +163,56 @@ public class GMSClientTest expected.add(group1); 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); // check against another role actual = client.getCachedGroups(userID, Role.OWNER); actual = client.getCachedGroups(test1UserID, Role.OWNER); Assert.assertNull("Cache should be null", actual); // check against another userid final HttpPrincipal userID2 = new HttpPrincipal("test2"); actual = client.getCachedGroups(userID2, Role.MEMBER); final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser"); actual = client.getCachedGroups(anotherUserID, Role.MEMBER); Assert.assertNull("Cache should be null", actual); 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; Loading @@ -181,12 +220,8 @@ public class GMSClientTest }); // 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); List<Group> newgroups = new ArrayList<Group>(); Loading @@ -195,9 +230,9 @@ public class GMSClientTest newgroups.add(group1); 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); } catch (Throwable t) Loading Loading
projects/cadcAccessControl-Server/src/ca/nrc/cadc/ac/server/ldap/LdapGroupDAO.java +2 −1 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ import ca.nrc.cadc.ac.Role; import ca.nrc.cadc.ac.User; import ca.nrc.cadc.ac.UserNotFoundException; import ca.nrc.cadc.net.TransientException; import ca.nrc.cadc.util.StringUtil; import com.unboundid.ldap.sdk.AddRequest; import com.unboundid.ldap.sdk.Attribute; Loading Loading @@ -214,7 +215,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO attributes.add(new Attribute("objectClass", "groupofuniquenames")); attributes.add(new Attribute("cn", groupID)); if (description != null) if (StringUtil.hasText(description)) { attributes.add(new Attribute("description", description)); } Loading
projects/cadcAccessControl/test/src/ca/nrc/cadc/ac/client/GMSClientTest.java +54 −19 Original line number Diff line number Diff line Loading @@ -140,20 +140,21 @@ public class GMSClientTest try { Subject subject = new Subject(); final HttpPrincipal userID = new HttpPrincipal("test"); subject.getPrincipals().add(userID); final HttpPrincipal test1UserID = new HttpPrincipal("test"); 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>() { @Override 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); List<Group> expected = new ArrayList<Group>(); Loading @@ -162,18 +163,56 @@ public class GMSClientTest expected.add(group1); 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); // check against another role actual = client.getCachedGroups(userID, Role.OWNER); actual = client.getCachedGroups(test1UserID, Role.OWNER); Assert.assertNull("Cache should be null", actual); // check against another userid final HttpPrincipal userID2 = new HttpPrincipal("test2"); actual = client.getCachedGroups(userID2, Role.MEMBER); final HttpPrincipal anotherUserID = new HttpPrincipal("anotheruser"); actual = client.getCachedGroups(anotherUserID, Role.MEMBER); Assert.assertNull("Cache should be null", actual); 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; Loading @@ -181,12 +220,8 @@ public class GMSClientTest }); // 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); List<Group> newgroups = new ArrayList<Group>(); Loading @@ -195,9 +230,9 @@ public class GMSClientTest newgroups.add(group1); 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); } catch (Throwable t) Loading