use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class SPUNaive method postUpdateInternalProcessing.
@Override
public Notification postUpdateInternalProcessing(UpdateResponse res) throws SEPAProcessingException {
logger.log(Level.getLevel("spu"), "@postUpdateInternalProcessing");
Response ret = null;
// Query the SPARQL processing service
try {
logger.log(Level.getLevel("spu"), "Query endpoint");
ret = manager.processQuery(subscribe);
} catch (SEPASecurityException | IOException e) {
if (logger.isTraceEnabled())
e.printStackTrace();
logger.log(Level.getLevel("spu"), "SEPASecurityException " + e.getMessage());
throw new SEPAProcessingException("postUpdateInternalProcessing exception " + e.getMessage());
}
if (ret.isError()) {
logger.log(Level.getLevel("spu"), "SEPAProcessingException " + ret);
throw new SEPAProcessingException("postUpdateInternalProcessing exception " + ret.toString());
}
// Current and previous bindings
BindingsResults results = ((QueryResponse) ret).getBindingsResults();
BindingsResults currentBindings = new BindingsResults(results);
// Initialize the results with the current bindings
BindingsResults added = new BindingsResults(results.getVariables(), null);
BindingsResults removed = new BindingsResults(results.getVariables(), null);
// Create empty bindings if null
if (lastBindings == null)
lastBindings = new BindingsResults(null, null);
logger.trace("Current bindings: " + currentBindings);
logger.trace("Last bindings: " + lastBindings);
// Find removed bindings
long start = System.nanoTime();
for (Bindings solution : lastBindings.getBindings()) {
if (!results.contains(solution) && !solution.isEmpty())
removed.add(solution);
else
results.remove(solution);
}
long stop = System.nanoTime();
logger.trace("Removed bindings: " + removed + " found in " + (stop - start) + " ns");
// Find added bindings
start = System.nanoTime();
for (Bindings solution : results.getBindings()) {
if (!lastBindings.contains(solution) && !solution.isEmpty())
added.add(solution);
}
stop = System.nanoTime();
logger.trace("Added bindings: " + added + " found in " + (stop - start) + " ns");
// Update the last bindings with the current ones
lastBindings = currentBindings;
// Send notification (or end processing indication)
if (!added.isEmpty() || !removed.isEmpty()) {
logger.log(Level.getLevel("spu"), "Send notification");
return new Notification(getSPUID(), new ARBindingsResults(added, removed));
}
logger.log(Level.getLevel("spu"), "Nothing to be notified");
return null;
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class SPARQL11Handler method handle.
@Override
public void handle(HttpRequest request, HttpAsyncExchange httpExchange, HttpContext context) throws HttpException, IOException {
logger.log(Level.getLevel("http"), "@handle " + request + " " + context);
// CORS
if (!corsHandling(httpExchange))
return;
// Authorize
ClientAuthorization oauth = null;
try {
oauth = authorize(httpExchange.getRequest());
} catch (SEPASecurityException e1) {
HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, "oauth_exception", e1.getMessage()));
jmx.authorizingFailed();
return;
}
if (!oauth.isAuthorized()) {
logger.log(Level.getLevel("oauth"), "*** NOT AUTHORIZED *** " + oauth.getDescription());
HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, oauth.getError(), oauth.getDescription()));
jmx.authorizingFailed();
return;
}
InternalUQRequest sepaRequest = null;
try {
// Parsing SPARQL 1.1 request and attach a token
sepaRequest = parse(httpExchange, oauth);
} catch (SPARQL11ProtocolException e) {
logger.log(Level.getLevel("http"), "Parsing failed: " + httpExchange.getRequest());
HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(e.getCode(), "SPARQL11ProtocolException", "Parsing failed: " + e.getMessage()));
jmx.parsingFailed();
return;
}
// Schedule request
Timings.log(sepaRequest);
ScheduledRequest req = scheduler.schedule(sepaRequest, new SPARQL11ResponseHandler(httpExchange, jmx));
if (req == null) {
logger.error("Out of tokens");
HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(429, "too_many_requests", "Too many pending requests"));
jmx.outOfTokens();
}
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class SSLManager method getSSLHttpClient.
public CloseableHttpClient getSSLHttpClient(String jksName, String jksPassword) throws SEPASecurityException {
// Trust own CA and all self-signed certificates and allow the specified
// protocols
LayeredConnectionSocketFactory sslsf = null;
try {
SSLContext ctx = SSLContexts.custom().loadTrustMaterial(new File(jksName), jksPassword.toCharArray(), new TrustSelfSignedStrategy()).build();
sslsf = new SSLConnectionSocketFactory(ctx, protocols, null, this);
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e) {
logger.error(e.getMessage());
if (logger.isTraceEnabled())
e.printStackTrace();
throw new SEPASecurityException(e.getMessage());
}
HttpClientBuilder clientFactory = HttpClients.custom().setSSLSocketFactory(sslsf);
return clientFactory.build();
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class Consumer method onBrokenConnection.
@Override
public void onBrokenConnection(ErrorResponse errorResponse) {
logger.warn("onBrokenConnection");
subscribed = false;
// Auto reconnection mechanism
if (appProfile.reconnect()) {
try {
protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(subID), appProfile.getSubscribePort(subID), appProfile.getSubscribePath(subID), this, sm);
client = new SPARQL11SEProtocol(protocol, sm);
} catch (SEPASecurityException | SEPAProtocolException e1) {
logger.error(e1.getMessage());
return;
}
while (!subscribed) {
try {
subscribe(TIMEOUT, NRETRY);
} catch (SEPASecurityException | SEPAPropertiesException | SEPAProtocolException | SEPABindingsException e) {
logger.error(e.getMessage());
if (logger.isTraceEnabled())
e.printStackTrace();
}
try {
synchronized (client) {
client.wait(TIMEOUT);
}
} catch (InterruptedException e) {
logger.error(e.getMessage());
if (logger.isTraceEnabled())
e.printStackTrace();
}
}
}
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException in project SEPA by arces-wot.
the class JKSUtil method getRSAKey.
public static RSAKey getRSAKey(String keystore, String storepass, String keyalias, String keypass) throws SEPASecurityException {
KeyStore jks;
try {
jks = KeyStore.getInstance("JKS");
jks.load(new FileInputStream(keystore), storepass.toCharArray());
logger.debug(jks);
return RSAKey.load(jks, keyalias, keypass.toCharArray());
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | JOSEException e) {
throw new SEPASecurityException(e.getMessage());
}
}
Aggregations