Loading projects/cadcAccessControl/src/ca/nrc/cadc/ac/client/GMSClient.java +75 −7 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.security.AccessControlContext; import java.security.AccessControlException; Loading Loading @@ -113,6 +114,7 @@ import ca.nrc.cadc.net.InputStreamWrapper; import ca.nrc.cadc.net.NetUtil; import ca.nrc.cadc.net.event.TransferEvent; import ca.nrc.cadc.net.event.TransferListener; import ca.nrc.cadc.reg.client.RegistryClient; /** Loading @@ -127,13 +129,36 @@ public class GMSClient implements TransferListener private SSLSocketFactory sslSocketFactory; private SSLSocketFactory mySocketFactory; // client needs to know which servcie it is bound to and lookup // endpoints using RegistryClient private URI serviceURI; private String baseURL; public GMSClient(URI serviceURI) { this.serviceURI = serviceURI; try { RegistryClient reg = new RegistryClient(); URL base = reg.getServiceURL(serviceURI, "https"); if (base == null) throw new IllegalArgumentException("service not found with https access: " + serviceURI); this.baseURL = base.toExternalForm(); } catch(MalformedURLException ex) { throw new RuntimeException("BUG: failed to construct GMS base URL", ex); } finally { } } /** * Constructor. * * @param baseURL The URL of the supporting access control web service * obtained from the registry. * @deprecated */ public GMSClient(String baseURL) throws IllegalArgumentException Loading Loading @@ -827,6 +852,34 @@ public class GMSClient implements TransferListener } } private Principal getCurrentUserID() { Subject cur = AuthenticationUtil.getCurrentSubject(); if (cur == null) throw new IllegalArgumentException("no subject"); Set<HttpPrincipal> ps = cur.getPrincipals(HttpPrincipal.class); // hack if (ps.isEmpty()) throw new IllegalArgumentException("no principals"); Principal p = ps.iterator().next(); log.debug("getCurrentID: " + p.getClass()); return p; } /** * Get memberships for the current user (subject). * * @param role * @return A list of groups for which the current user has the role. * @throws AccessControlException * @throws ca.nrc.cadc.ac.UserNotFoundException * @throws java.io.IOException */ public List<Group> getMemberships(Role role) throws UserNotFoundException, AccessControlException, IOException { return getMemberships(getCurrentUserID(), role); } /** * Get all the memberships of the user of a certain role. * Loading Loading @@ -1026,6 +1079,21 @@ public class GMSClient implements TransferListener } } /** * Check group membership of the current Subject. * * @param groupName * @return * @throws UserNotFoundException * @throws AccessControlException * @throws IOException */ public boolean isMember(String groupName) throws UserNotFoundException, AccessControlException, IOException { return isMember(getCurrentUserID(), groupName, Role.MEMBER); } /** * Check if userID is a member of groupName. * Loading Loading
projects/cadcAccessControl/src/ca/nrc/cadc/ac/client/GMSClient.java +75 −7 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.security.AccessControlContext; import java.security.AccessControlException; Loading Loading @@ -113,6 +114,7 @@ import ca.nrc.cadc.net.InputStreamWrapper; import ca.nrc.cadc.net.NetUtil; import ca.nrc.cadc.net.event.TransferEvent; import ca.nrc.cadc.net.event.TransferListener; import ca.nrc.cadc.reg.client.RegistryClient; /** Loading @@ -127,13 +129,36 @@ public class GMSClient implements TransferListener private SSLSocketFactory sslSocketFactory; private SSLSocketFactory mySocketFactory; // client needs to know which servcie it is bound to and lookup // endpoints using RegistryClient private URI serviceURI; private String baseURL; public GMSClient(URI serviceURI) { this.serviceURI = serviceURI; try { RegistryClient reg = new RegistryClient(); URL base = reg.getServiceURL(serviceURI, "https"); if (base == null) throw new IllegalArgumentException("service not found with https access: " + serviceURI); this.baseURL = base.toExternalForm(); } catch(MalformedURLException ex) { throw new RuntimeException("BUG: failed to construct GMS base URL", ex); } finally { } } /** * Constructor. * * @param baseURL The URL of the supporting access control web service * obtained from the registry. * @deprecated */ public GMSClient(String baseURL) throws IllegalArgumentException Loading Loading @@ -827,6 +852,34 @@ public class GMSClient implements TransferListener } } private Principal getCurrentUserID() { Subject cur = AuthenticationUtil.getCurrentSubject(); if (cur == null) throw new IllegalArgumentException("no subject"); Set<HttpPrincipal> ps = cur.getPrincipals(HttpPrincipal.class); // hack if (ps.isEmpty()) throw new IllegalArgumentException("no principals"); Principal p = ps.iterator().next(); log.debug("getCurrentID: " + p.getClass()); return p; } /** * Get memberships for the current user (subject). * * @param role * @return A list of groups for which the current user has the role. * @throws AccessControlException * @throws ca.nrc.cadc.ac.UserNotFoundException * @throws java.io.IOException */ public List<Group> getMemberships(Role role) throws UserNotFoundException, AccessControlException, IOException { return getMemberships(getCurrentUserID(), role); } /** * Get all the memberships of the user of a certain role. * Loading Loading @@ -1026,6 +1079,21 @@ public class GMSClient implements TransferListener } } /** * Check group membership of the current Subject. * * @param groupName * @return * @throws UserNotFoundException * @throws AccessControlException * @throws IOException */ public boolean isMember(String groupName) throws UserNotFoundException, AccessControlException, IOException { return isMember(getCurrentUserID(), groupName, Role.MEMBER); } /** * Check if userID is a member of groupName. * Loading