Commit fa0f6c76 authored by Brian Major's avatar Brian Major
Browse files

Merge branch 's1890' into s1885

parents 92fe98a0 110a1a5b
......@@ -815,7 +815,7 @@ public class LdapUserDAO extends LdapDAO
logger.debug("search filter: " + filter);
final String[] attributes = new String[]
{ LDAP_UID, LDAP_FIRST_NAME, LDAP_LAST_NAME };
{ LDAP_USER_NAME, LDAP_FIRST_NAME, LDAP_LAST_NAME };
final SearchRequest searchRequest =
new SearchRequest(usersDN, SearchScope.ONE, filter, attributes);
......@@ -831,10 +831,10 @@ public class LdapUserDAO extends LdapDAO
next.getAttributeValue(LDAP_FIRST_NAME);
final String lastName =
next.getAttributeValue(LDAP_LAST_NAME).trim();
final String uid = next.getAttributeValue(LDAP_UID);
final String username = next.getAttributeValue(LDAP_USER_NAME);
User user = new User();
user.getIdentities().add(new HttpPrincipal(uid));
user.getIdentities().add(new HttpPrincipal(username));
// Only add Personal Details if it is relevant.
if (StringUtil.hasLength(firstName) &&
......
......@@ -107,7 +107,7 @@ public class CreateGroupAction extends AbstractGroupAction
}
for (User usr : group.getUserMembers())
{
addedMembers.add(usr.getHttpPrincipal().getName());
addedMembers.add(usr.getX500Principal().getName());
}
}
logGroupInfo(group.getID(), null, addedMembers);
......
......@@ -78,6 +78,7 @@ import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.server.PluginFactory;
import ca.nrc.cadc.ac.server.UserPersistence;
import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.util.ObjectUtil;
public class RemoveUserMemberAction extends AbstractGroupAction
{
......@@ -99,7 +100,12 @@ public class RemoveUserMemberAction extends AbstractGroupAction
Group group = groupPersistence.getGroup(this.groupName);
Principal userPrincipal = AuthenticationUtil.createPrincipal(this.userID, this.userIDType);
User toRemove = getUserPersistence().getUser(userPrincipal);
User user = getUserPersistence().getAugmentedUser(userPrincipal);
User toRemove = new User();
ObjectUtil.setField(toRemove, user.getID(), "id");
toRemove.getIdentities().addAll(user.getIdentities());
if (!group.getUserMembers().remove(toRemove))
{
throw new MemberNotFoundException();
......
......@@ -71,11 +71,16 @@ package ca.nrc.cadc.ac.server.web.groups;
import static org.easymock.EasyMock.createMock;
import static org.junit.Assert.fail;
import java.net.URI;
import java.security.Principal;
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;
......@@ -111,11 +116,14 @@ public class RemoveUserMemberActionTest
{
try
{
User user = new User();
InternalID internalID = new InternalID(new URI(AC.USER_URI + "?" + UUID.randomUUID()));
ObjectUtil.setField(user, internalID, "id");
String userID = "cn=foo,c=ca";
String userIDType = IdentityType.X500.getValue();
Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType);
User user = new User();
user.getIdentities().add(userPrincipal);
Principal x500Principal = AuthenticationUtil.createPrincipal(userID, userIDType);
user.getIdentities().add(x500Principal);
Group group = new Group("group");
User member = new User();
......@@ -126,7 +134,7 @@ public class RemoveUserMemberActionTest
EasyMock.expect(mockGroupPersistence.getGroup("group")).andReturn(group);
final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class);
EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user);
EasyMock.expect(mockUserPersistence.getAugmentedUser(x500Principal)).andReturn(user);
EasyMock.replay(mockGroupPersistence, mockUserPersistence);
......@@ -160,10 +168,13 @@ public class RemoveUserMemberActionTest
{
try
{
User user = new User();
InternalID internalID = new InternalID(new URI(AC.USER_URI + "?" + UUID.randomUUID()));
ObjectUtil.setField(user, internalID, "id");
String userID = "cn=foo,c=ca";
String userIDType = IdentityType.X500.getValue();
Principal userPrincipal = AuthenticationUtil.createPrincipal(userID, userIDType);
User user = new User();
user.getIdentities().add(new X500Principal(userID));
user.getIdentities().add(new HttpPrincipal("foo"));
......@@ -176,7 +187,7 @@ public class RemoveUserMemberActionTest
EasyMock.expectLastCall();
final UserPersistence mockUserPersistence = EasyMock.createMock(UserPersistence.class);
EasyMock.expect(mockUserPersistence.getUser(userPrincipal)).andReturn(user);
EasyMock.expect(mockUserPersistence.getAugmentedUser(userPrincipal)).andReturn(user);
EasyMock.replay(mockGroupPersistence, mockUserPersistence);
......
......@@ -68,6 +68,7 @@
*/
package ca.nrc.cadc.ac;
import java.io.PrintWriter;
import java.security.Principal;
import java.util.Comparator;
import java.util.Date;
......@@ -77,8 +78,12 @@ import java.util.TreeSet;
import ca.nrc.cadc.auth.HttpPrincipal;
import javax.security.auth.x500.X500Principal;
public class User
{
// How on God's green earth is this used? Where is it set?
// jenkinsd 2016.03.24
private InternalID id;
private Set<Principal> identities = new TreeSet<Principal>(new PrincipalComparator());
......@@ -141,6 +146,14 @@ public class User
return null;
}
public X500Principal getX500Principal()
{
final Set<X500Principal> identities =
getIdentities(X500Principal.class);
return identities.isEmpty() ? null : identities.iterator().next();
}
/**
* A User is considered consistent if the User's set of identities are a superset
* of this Users set of identities.
......
......@@ -124,8 +124,8 @@ public class UserClient
/**
* Constructor.
*
* @param baseURL The URL of the supporting access control web service
* obtained from the registry.
* @param serviceURI The URI of the supporting access control web service
* obtained from the registry.
*/
public UserClient(URI serviceURI)
throws IllegalArgumentException
......@@ -136,7 +136,7 @@ public class UserClient
public UserClient(URI serviceURI, RegistryClient registryClient)
{
if (serviceURI == null)
throw new IllegalArgumentException("invalid serviceURI: " + serviceURI);
throw new IllegalArgumentException("Service URI cannot be null.");
if (serviceURI.getFragment() != null)
throw new IllegalArgumentException("invalid serviceURI (fragment not allowed): " + serviceURI);
......@@ -211,7 +211,9 @@ public class UserClient
{
URL usersURL = registryClient.getServiceURL(usersURI, "https");
final List<User> webUsers = new ArrayList<User>();
HttpDownload httpDownload = new HttpDownload(usersURL, new JsonUserListInputStreamWrapper(webUsers));
HttpDownload httpDownload =
new HttpDownload(usersURL,
new JsonUserListInputStreamWrapper(webUsers));
httpDownload.setRequestProperty("Accept", "application/json");
httpDownload.run();
......
......@@ -108,16 +108,32 @@ public class UserClientTest
try
{
new UserClient(null);
Assert.fail("Null base URL should throw an illegalArgumentException.");
Assert.fail("Null service URI should throw an illegalArgumentException.");
}
catch (IllegalArgumentException iae)
{
Assert.assertTrue(iae.getMessage().contains("invalid serviceURI"));
Assert.assertTrue(iae.getMessage().contains("cannot be null"));
}
catch (Throwable t)
{
Assert.fail("Unexpected exception: " + t.getMessage());
}
// case 2: serviceURI with a fragment
try
{
URI uri = new URI("http://foo.com/bar?test#fragment");
new UserClient(uri);
Assert.fail("Service URI containing a fragment should throw an illegalArgumentException.");
}
catch (IllegalArgumentException iae)
{
Assert.assertTrue(iae.getMessage().contains("fragment not allowed"));
}
catch (Throwable t)
{
Assert.fail("Unexpected exception: " + t.getMessage());
}
}
@Test
......
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