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);
}
}
}
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;
}
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;
}
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);
}
}
}
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);
}
}
Aggregations