Commit 6b3dc505 authored by Dustin Jenkins's avatar Dustin Jenkins
Browse files

Story 1890: Fix for removing users.

parent cbe3df3b
...@@ -815,7 +815,7 @@ public class LdapUserDAO extends LdapDAO ...@@ -815,7 +815,7 @@ public class LdapUserDAO extends LdapDAO
logger.debug("search filter: " + filter); logger.debug("search filter: " + filter);
final String[] attributes = new String[] 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 = final SearchRequest searchRequest =
new SearchRequest(usersDN, SearchScope.ONE, filter, attributes); new SearchRequest(usersDN, SearchScope.ONE, filter, attributes);
...@@ -831,10 +831,10 @@ public class LdapUserDAO extends LdapDAO ...@@ -831,10 +831,10 @@ public class LdapUserDAO extends LdapDAO
next.getAttributeValue(LDAP_FIRST_NAME); next.getAttributeValue(LDAP_FIRST_NAME);
final String lastName = final String lastName =
next.getAttributeValue(LDAP_LAST_NAME).trim(); 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 user = new User();
user.getIdentities().add(new HttpPrincipal(uid)); user.getIdentities().add(new HttpPrincipal(username));
// Only add Personal Details if it is relevant. // Only add Personal Details if it is relevant.
if (StringUtil.hasLength(firstName) && if (StringUtil.hasLength(firstName) &&
......
...@@ -107,7 +107,7 @@ public class CreateGroupAction extends AbstractGroupAction ...@@ -107,7 +107,7 @@ public class CreateGroupAction extends AbstractGroupAction
} }
for (User usr : group.getUserMembers()) for (User usr : group.getUserMembers())
{ {
addedMembers.add(usr.getHttpPrincipal().getName()); addedMembers.add(usr.getX500Principal().getName());
} }
} }
logGroupInfo(group.getID(), null, addedMembers); logGroupInfo(group.getID(), null, addedMembers);
......
...@@ -78,6 +78,7 @@ import ca.nrc.cadc.ac.User; ...@@ -78,6 +78,7 @@ import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.server.PluginFactory; import ca.nrc.cadc.ac.server.PluginFactory;
import ca.nrc.cadc.ac.server.UserPersistence; import ca.nrc.cadc.ac.server.UserPersistence;
import ca.nrc.cadc.auth.AuthenticationUtil; import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.util.ObjectUtil;
public class RemoveUserMemberAction extends AbstractGroupAction public class RemoveUserMemberAction extends AbstractGroupAction
{ {
...@@ -102,6 +103,7 @@ public class RemoveUserMemberAction extends AbstractGroupAction ...@@ -102,6 +103,7 @@ public class RemoveUserMemberAction extends AbstractGroupAction
User user = getUserPersistence().getAugmentedUser(userPrincipal); User user = getUserPersistence().getAugmentedUser(userPrincipal);
User toRemove = new User(); User toRemove = new User();
ObjectUtil.setField(toRemove, user.getID(), "id");
toRemove.getIdentities().addAll(user.getIdentities()); toRemove.getIdentities().addAll(user.getIdentities());
if (!group.getUserMembers().remove(toRemove)) if (!group.getUserMembers().remove(toRemove))
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
*/ */
package ca.nrc.cadc.ac; package ca.nrc.cadc.ac;
import java.io.PrintWriter;
import java.security.Principal; import java.security.Principal;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
...@@ -77,8 +78,12 @@ import java.util.TreeSet; ...@@ -77,8 +78,12 @@ import java.util.TreeSet;
import ca.nrc.cadc.auth.HttpPrincipal; import ca.nrc.cadc.auth.HttpPrincipal;
import javax.security.auth.x500.X500Principal;
public class User public class User
{ {
// How on God's green earth is this used? Where is it set?
// jenkinsd 2016.03.24
private InternalID id; private InternalID id;
private Set<Principal> identities = new TreeSet<Principal>(new PrincipalComparator()); private Set<Principal> identities = new TreeSet<Principal>(new PrincipalComparator());
...@@ -141,6 +146,14 @@ public class User ...@@ -141,6 +146,14 @@ public class User
return null; 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 * A User is considered consistent if the User's set of identities are a superset
* of this Users set of identities. * of this Users set of identities.
......
...@@ -117,8 +117,8 @@ public class UserClient ...@@ -117,8 +117,8 @@ public class UserClient
/** /**
* Constructor. * Constructor.
* *
* @param baseURL The URL of the supporting access control web service * @param serviceURI The URI of the supporting access control web service
* obtained from the registry. * obtained from the registry.
*/ */
public UserClient(URI serviceURI) public UserClient(URI serviceURI)
throws IllegalArgumentException throws IllegalArgumentException
...@@ -129,7 +129,7 @@ public class UserClient ...@@ -129,7 +129,7 @@ public class UserClient
public UserClient(URI serviceURI, RegistryClient registryClient) public UserClient(URI serviceURI, RegistryClient registryClient)
{ {
if (serviceURI == null) if (serviceURI == null)
throw new IllegalArgumentException("invalid serviceURI: " + serviceURI); throw new IllegalArgumentException("Service URI cannot be null.");
if (serviceURI.getFragment() != null) if (serviceURI.getFragment() != null)
throw new IllegalArgumentException("invalid serviceURI (fragment not allowed): " + serviceURI); throw new IllegalArgumentException("invalid serviceURI (fragment not allowed): " + serviceURI);
...@@ -204,7 +204,9 @@ public class UserClient ...@@ -204,7 +204,9 @@ public class UserClient
{ {
URL usersURL = registryClient.getServiceURL(usersURI, "https"); URL usersURL = registryClient.getServiceURL(usersURI, "https");
final List<User> webUsers = new ArrayList<User>(); 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.setRequestProperty("Accept", "application/json");
httpDownload.run(); httpDownload.run();
......
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