Search in sources :

Example 1 with AuthMethod

use of ca.nrc.cadc.auth.AuthMethod in project caom2db by opencadc.

the class InventoryArtifactStore method init.

private void init() {
    Subject subject = AuthenticationUtil.getCurrentSubject();
    AuthMethod authMethod = AuthenticationUtil.getAuthMethodFromCredentials(subject);
    URI securityMethod = Standards.getSecurityMethod(authMethod);
    if (storageInventoryTapURL == null) {
        try {
            TapClient tapClient = new TapClient<>(queryServiceResourceID);
            storageInventoryTapURL = tapClient.getSyncURL(securityMethod);
        } catch (Throwable t) {
            String message = "Failed to initialize Storage-Inventory TAP URL";
            throw new RuntimeException(message, t);
        }
    }
}
Also used : TapClient(org.opencadc.tap.TapClient) URI(java.net.URI) Subject(javax.security.auth.Subject) AuthMethod(ca.nrc.cadc.auth.AuthMethod)

Example 2 with AuthMethod

use of ca.nrc.cadc.auth.AuthMethod in project caom2db by opencadc.

the class ArtifactValidator method getLogicalMetadata.

private TreeSet<ArtifactMetadata> getLogicalMetadata() throws Exception {
    TreeSet<ArtifactMetadata> result = new TreeSet<>(ArtifactMetadata.getComparator());
    if (StringUtil.hasText(source)) {
        // use database <server.database.schema>
        // HarvestSkipURI table is not supported in 'diff' mode, i.e. reportOnly = true
        this.supportSkipURITable = !reportOnly;
        long t1 = System.currentTimeMillis();
        List<ObservationState> states = observationDAO.getObservationList(collection, null, null, null);
        long t2 = System.currentTimeMillis();
        long dt = t2 - t1;
        log.info("get-state-list: size=" + states.size() + " in " + dt + " ms");
        int depth = 3;
        ListIterator<ObservationState> iter = states.listIterator();
        t1 = System.currentTimeMillis();
        while (iter.hasNext()) {
            ObservationState s = iter.next();
            // GC
            iter.remove();
            ObservationResponse resp = observationDAO.getObservationResponse(s, depth);
            if (resp == null) {
                log.error("Null response from Observation DAO, ObservationURI: " + s.getURI().toString() + ", depth: " + depth);
            } else if (resp.observation == null) {
                log.error("Observation is null, ObservationURI: " + s.getURI().toString() + ", depth: " + depth);
            } else {
                for (Plane plane : resp.observation.getPlanes()) {
                    for (Artifact artifact : plane.getArtifacts()) {
                        String observationID = s.getURI().getObservationID();
                        result.add(getMetadata(observationID, artifact, plane.dataRelease, plane.metaRelease));
                    }
                }
            }
        }
        log.info("Finished logical metadata query in " + (System.currentTimeMillis() - t1) + " ms");
    } else {
        this.supportSkipURITable = false;
        if (caomTapResourceID != null) {
            // source is a TAP resource ID
            AuthMethod authMethod = AuthenticationUtil.getAuthMethodFromCredentials(AuthenticationUtil.getCurrentSubject());
            TapClient tapClient = new TapClient(caomTapResourceID);
            try {
                this.caomTapURL = tapClient.getSyncURL(authMethod);
            } catch (ResourceNotFoundException ex) {
                if (ex.getMessage().contains("with password")) {
                    throw new ResourceNotFoundException("TAP service for " + caomTapResourceID + " does not support password authentication.", ex);
                }
            }
        }
        // source is a TAP service URL or a TAP resource ID
        String adql = "select distinct(a.uri), a.contentChecksum, a.contentLength, a.contentType, o.observationID, " + "a.productType, a.releaseType, p.dataRelease, p.metaRelease " + "from caom2.Artifact a " + "join caom2.Plane p on a.planeID = p.planeID " + "join caom2.Observation o on p.obsID = o.obsID " + "where o.collection='" + collection + "'";
        log.debug("logical query: " + adql);
        long start = System.currentTimeMillis();
        result = query(caomTapURL, adql);
        log.info("Finished caom2 query in " + (System.currentTimeMillis() - start) + " ms");
    }
    return result;
}
Also used : Plane(ca.nrc.cadc.caom2.Plane) Artifact(ca.nrc.cadc.caom2.Artifact) AuthMethod(ca.nrc.cadc.auth.AuthMethod) TreeSet(java.util.TreeSet) ObservationResponse(ca.nrc.cadc.caom2.ObservationResponse) TapClient(org.opencadc.tap.TapClient) ObservationState(ca.nrc.cadc.caom2.ObservationState) ResourceNotFoundException(ca.nrc.cadc.net.ResourceNotFoundException) ArtifactMetadata(ca.nrc.cadc.caom2.artifact.ArtifactMetadata)

Example 3 with AuthMethod

use of ca.nrc.cadc.auth.AuthMethod in project caom2db by opencadc.

the class RepoClient method initDel.

private void initDel() {
    Subject s = AuthenticationUtil.getCurrentSubject();
    AuthMethod meth = AuthenticationUtil.getAuthMethodFromCredentials(s);
    if (meth == null) {
        meth = AuthMethod.ANON;
    }
    if (resourceID != null) {
        this.baseDeletionURL = rc.getServiceURL(resourceID, Standards.CAOM2REPO_DEL_23, meth);
    } else if (capabilitiesURL != null) {
        CapabilitiesReader capabilitiesReader = new CapabilitiesReader();
        Capabilities capabilities;
        try {
            capabilities = capabilitiesReader.read(capabilitiesURL.openStream());
        } catch (IOException e) {
            throw new RuntimeException("Imposible to read capabilities: " + capabilitiesURL);
        }
        Capability cap = capabilities.findCapability(Standards.CAOM2REPO_DEL_23);
        if (cap != null) {
            // locate the associated interface, throws RuntimeException if
            // more than
            // one interface match
            Interface intf = cap.findInterface(meth);
            if (intf != null) {
                this.baseDeletionURL = intf.getAccessURL().getURL();
            }
        }
    } else {
        throw new RuntimeException("BUG: no resourceID or capabilitiesURL");
    }
    if (baseDeletionURL == null) {
        isDelAvailable = false;
        return;
    }
    log.debug("deletion list URL: " + baseDeletionURL.toString());
    log.debug("AuthMethod:  " + meth);
    this.isDelAvailable = true;
}
Also used : CapabilitiesReader(ca.nrc.cadc.reg.CapabilitiesReader) Capability(ca.nrc.cadc.reg.Capability) Capabilities(ca.nrc.cadc.reg.Capabilities) IOException(java.io.IOException) Subject(javax.security.auth.Subject) AuthMethod(ca.nrc.cadc.auth.AuthMethod) Interface(ca.nrc.cadc.reg.Interface)

Example 4 with AuthMethod

use of ca.nrc.cadc.auth.AuthMethod in project vos by opencadc.

the class TransferRunner method doTransferRedirect.

private void doTransferRedirect(Transfer trans, List<Parameter> additionalParameters) {
    if (syncOutput != null && !syncOutputCommit) {
        if (!job.getParameterList().isEmpty() && trans != null) {
            try {
                List<Protocol> plist = TransferUtil.getTransferEndpoints(trans, job, additionalParameters);
                if (plist.isEmpty()) {
                    sendError(ExecutionPhase.EXECUTING, ErrorType.FATAL, "requested transfer specs not supported", HttpURLConnection.HTTP_BAD_REQUEST, true);
                    return;
                }
                Protocol proto = plist.get(0);
                String loc = proto.getEndpoint();
                log.debug("Location: " + loc);
                syncOutput.setHeader("Location", loc);
                syncOutput.setResponseCode(HttpURLConnection.HTTP_SEE_OTHER);
                return;
            } catch (Exception e) {
                throw new RuntimeException("Failed to create protocol list: " + e.getMessage(), e);
            }
        }
        // standard redirect
        StringBuilder sb = new StringBuilder();
        sb.append("/").append(job.getID()).append("/results/transferDetails");
        try {
            AuthMethod authMethod = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject());
            URL serviceURL = regClient.getServiceURL(serviceURI, Standards.VOSPACE_TRANSFERS_20, authMethod);
            URL location = new URL(serviceURL.toExternalForm() + sb.toString());
            String loc = location.toExternalForm();
            log.debug("Location: " + loc);
            syncOutput.setHeader("Location", loc);
            syncOutput.setResponseCode(HttpURLConnection.HTTP_SEE_OTHER);
            return;
        } catch (MalformedURLException bug) {
            throw new RuntimeException("BUG: failed to create valid transferDetails URL", bug);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Protocol(ca.nrc.cadc.vos.Protocol) URISyntaxException(java.net.URISyntaxException) ByteLimitExceededException(ca.nrc.cadc.io.ByteLimitExceededException) NotAuthenticatedException(ca.nrc.cadc.auth.NotAuthenticatedException) LinkingException(ca.nrc.cadc.vos.LinkingException) JobNotFoundException(ca.nrc.cadc.uws.server.JobNotFoundException) NodeLockedException(ca.nrc.cadc.vos.NodeLockedException) NodeBusyException(ca.nrc.cadc.vos.NodeBusyException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) TransientException(ca.nrc.cadc.net.TransientException) JobPersistenceException(ca.nrc.cadc.uws.server.JobPersistenceException) AccessControlException(java.security.AccessControlException) NodeNotFoundException(ca.nrc.cadc.vos.NodeNotFoundException) AuthMethod(ca.nrc.cadc.auth.AuthMethod) URL(java.net.URL)

Example 5 with AuthMethod

use of ca.nrc.cadc.auth.AuthMethod in project vos by opencadc.

the class TransferUtil method getSynctransParamURL.

public static URL getSynctransParamURL(String scheme, VOSURI uri, AuthMethod forceAuthMethod, RegistryClient reg) {
    if (reg == null)
        reg = new RegistryClient();
    try {
        AccessControlContext acContext = AccessController.getContext();
        Subject subject = Subject.getSubject(acContext);
        AuthMethod am = forceAuthMethod;
        if (am == null)
            // default: perserve
            am = AuthenticationUtil.getAuthMethod(subject);
        if (am == null)
            am = AuthMethod.ANON;
        log.debug("getSynctransParamURL: " + scheme + " " + am + " " + uri);
        StringBuilder sb = new StringBuilder();
        Protocol protocol = null;
        if ("http".equalsIgnoreCase(scheme)) {
            protocol = new Protocol(VOS.PROTOCOL_HTTP_GET);
        } else if ("https".equalsIgnoreCase(scheme)) {
            protocol = new Protocol(VOS.PROTOCOL_HTTPS_GET);
        } else {
            throw new IllegalArgumentException("Unknown protocol: " + scheme);
        }
        sb.append("?");
        // add parameters for synctrans
        sb.append("TARGET=").append(NetUtil.encode(uri.toString()));
        sb.append("&DIRECTION=").append(NetUtil.encode(Direction.pullFromVoSpaceValue));
        sb.append("&PROTOCOL=").append(NetUtil.encode(protocol.getUri()));
        URL serviceURL = reg.getServiceURL(VOSPACE_RESOURCE_ID, Standards.VOSPACE_SYNC_21, am);
        URL url = new URL(serviceURL.toExternalForm() + sb.toString());
        log.debug("DataView URL: " + am + " : " + url);
        return url;
    } catch (MalformedURLException e) {
        String message = "BUG: misconfigured service URL";
        log.error(message, e);
        throw new IllegalStateException(message, e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) AccessControlContext(java.security.AccessControlContext) RegistryClient(ca.nrc.cadc.reg.client.RegistryClient) Protocol(ca.nrc.cadc.vos.Protocol) Subject(javax.security.auth.Subject) AuthMethod(ca.nrc.cadc.auth.AuthMethod) URL(java.net.URL)

Aggregations

AuthMethod (ca.nrc.cadc.auth.AuthMethod)17 Subject (javax.security.auth.Subject)9 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)6 Protocol (ca.nrc.cadc.vos.Protocol)5 IOException (java.io.IOException)5 URL (java.net.URL)5 NetrcAuthenticator (ca.nrc.cadc.net.NetrcAuthenticator)4 Capabilities (ca.nrc.cadc.reg.Capabilities)4 Capability (ca.nrc.cadc.reg.Capability)4 Interface (ca.nrc.cadc.reg.Interface)4 VOSURI (ca.nrc.cadc.vos.VOSURI)4 Date (java.util.Date)4 RegistryClient (ca.nrc.cadc.reg.client.RegistryClient)3 NodeNotFoundException (ca.nrc.cadc.vos.NodeNotFoundException)3 LocalServiceURI (ca.nrc.cadc.vos.server.LocalServiceURI)3 MalformedURLException (java.net.MalformedURLException)3 DateFormat (java.text.DateFormat)3 ArrayList (java.util.ArrayList)3 RunnableAction (ca.nrc.cadc.auth.RunnableAction)2