private Principal getCurrentUserID() { Subject cur = AuthenticationUtil.getCurrentSubject(); if (cur == null) return null; // throw new IllegalArgumentException("no subject"); Set<HttpPrincipal> ps = cur.getPrincipals(HttpPrincipal.class); // hack if (ps.isEmpty()) return null; // throw new IllegalArgumentException("no principals"); Principal p = ps.iterator().next(); log.debug("getCurrentID: " + p.getClass()); return p; }
/** * Check if the current subject has usable credentials (a valid X509 proxy * certificate) and call the local CDP service if necessary. * * @throws AccessControlException * @return true if subject has valid credentials, false if subject is anonymous * @throws java.security.cert.CertificateExpiredException * @throws java.security.cert.CertificateNotYetValidException */ public static boolean checkCredentials() throws AccessControlException, CertificateExpiredException, CertificateNotYetValidException { return checkCredentials(AuthenticationUtil.getCurrentSubject()); }
/** * Group together Subject principal types with their Principal values. * * @param <T> The type of Principal. * @return Map of class to collection of string values. */ public static <T extends Principal> Map<Class<T>, Collection<String>> groupPrincipalsByType() { final Map<Class<T>, Collection<String>> groupedPrincipals = new HashMap<Class<T>, Collection<String>>(); for (final Principal p : getCurrentSubject().getPrincipals()) { final Class<T> nextPrincipalClass = (Class<T>) p.getClass(); if (!groupedPrincipals.containsKey(p.getClass())) { groupedPrincipals .put(nextPrincipalClass, new HashSet<String>()); } groupedPrincipals.get(nextPrincipalClass).add(p.getName()); } return groupedPrincipals; }
public AdSchemeHandler() { try { RegistryClient rc = new RegistryClient(); AuthMethod am = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject()); if (am == null) { am = AuthMethod.ANON; } URL serviceURL = rc.getServiceURL(URI.create(DATA_URI), Standards.DATA_10, am); this.baseURL = serviceURL.toExternalForm(); } catch (Throwable t) { log.error("failed to find CADC data service URL", t); throw new RuntimeException("BUG: failed to find CADC data service URL", t); } log.debug("CADC data service URL: " + baseURL); }
private URL lookupServiceURL(final URI standard) throws AccessControlException { Subject subject = AuthenticationUtil.getCurrentSubject(); AuthMethod am = AuthenticationUtil.getAuthMethodFromCredentials(subject); URL serviceURL = getRegistryClient().getServiceURL(this.serviceID, standard, am); if (serviceURL == null) { throw new RuntimeException( String.format("Unable to get Service URL for '%s', '%s', '%s'", serviceID.toString(), standard, am)); } return serviceURL; }
@Override public URL toURL(URI uri) { if (!SCHEME.equals(uri.getScheme())) { throw new IllegalArgumentException("invalid scheme in " + uri); } try { String path = getPath(uri); // check if authMethod has been set AuthMethod am = this.authMethod; if (am == null) { am = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject()); } if (am == null) { am = AuthMethod.ANON; } RegistryClient rc = new RegistryClient(); URL serviceURL = rc.getServiceURL(new URI(DATA_URI), Standards.DATA_10, am); URL url = this.toURL(serviceURL, path); log.debug(uri + " --> " + url); return url; } catch (MalformedURLException ex) { throw new RuntimeException("BUG", ex); } catch (URISyntaxException bug) { throw new RuntimeException("BUG - failed to create data web service URI", bug); } }
private AuthMethod getAuthMethod() throws AccessControlException { Subject subject = AuthenticationUtil.getCurrentSubject(); AuthMethod am = AuthenticationUtil.getAuthMethodFromCredentials(subject); if (am == null || am.equals(AuthMethod.ANON)) { throw new AccessControlException("Anonymous access not supported."); } return am; }
am = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject());
NumericPrincipal p = new NumericPrincipal(uuid); Subject s = AuthenticationUtil.getCurrentSubject(); if (s != null) { for (Principal cp : s.getPrincipals()) {
@Override public URL toURL(URI uri) { if (!SCHEME.equals(uri.getScheme())) { throw new IllegalArgumentException("invalid scheme in " + uri); } try { Subject subject = AuthenticationUtil.getCurrentSubject(); AuthMethod authMethod = AuthenticationUtil.getAuthMethodFromCredentials(subject); if (authMethod == null) { authMethod = AuthMethod.ANON; } RegistryClient rc = new RegistryClient(); Capabilities caps = rc.getCapabilities(DATA_RESOURCE_ID); Capability dataCap = caps.findCapability(Standards.DATA_10); Interface ifc = dataCap.findInterface(authMethod); if (ifc == null) { throw new IllegalArgumentException("No interface for auth method " + authMethod); } String baseDataURL = ifc.getAccessURL().getURL().toString(); URL url = new URL(baseDataURL + "/MAST/" + uri.getSchemeSpecificPart()); log.debug(uri + " --> " + url); return url; } catch (MalformedURLException ex) { throw new RuntimeException("BUG", ex); } catch (Throwable t) { String message = "Failed to convert to data URL"; throw new RuntimeException(message, t); } }
/** * Lookup the Service URL for the given standard. The current AuthMethod * will be taken into account. * * @param standard The URI standard to look up. * @return URL for the service. * @throws AccessControlException If the URL cannot be found for the * provided AuthMethod. */ private URL lookupServiceURL(final URI standard) throws AccessControlException { Subject subject = AuthenticationUtil.getCurrentSubject(); AuthMethod am = AuthenticationUtil.getAuthMethodFromCredentials(subject); if (am == null || am.equals(AuthMethod.ANON)) { throw new AccessControlException("Anonymous access not supported."); } URL serviceURL = getRegistryClient().getServiceURL(this.serviceID, standard, am); if (serviceURL == null) { throw new RuntimeException( String.format("Unable to get Service URL for '%s', '%s', '%s'", serviceID.toString(), standard, am)); } return serviceURL; }
AuthMethod am = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject()); if (am == null) { am = AuthMethod.ANON;
Subject s = AuthenticationUtil.getCurrentSubject(); AuthMethod cur = AuthenticationUtil.getAuthMethod(s); if (cur == null)
Subject cur = AuthenticationUtil.getCurrentSubject(); for (Principal cp : cur.getPrincipals()) { for (Principal op : owner.getPrincipals()) {
private void writeJobListing() throws IOException, JobPersistenceException, TransientException { Subject caller = AuthenticationUtil.getCurrentSubject(); AuthMethod am = AuthenticationUtil.getAuthMethod(caller); if (am == null || AuthMethod.ANON.equals(am)) {
setTableOwner(tableName, AuthenticationUtil.getCurrentSubject());
protocols.add(new Protocol(VOS.PROTOCOL_HTTP_PUT)); if (AuthenticationUtil.getAuthMethodFromCredentials(AuthenticationUtil.getCurrentSubject()) == AuthMethod.CERT)
Subject cur = AuthenticationUtil.getCurrentSubject(); for (Principal cp : cur.getPrincipals()) { for (Principal op : owner.getPrincipals()) {