Search in sources :

Example 6 with ClientAuthorization

use of it.unibo.arces.wot.sepa.commons.security.ClientAuthorization in project SEPA by arces-wot.

the class Gate method onMessage.

public final void onMessage(String message) throws SEPAProtocolException, SEPASecurityException, SEPASparqlParsingException {
    // Authorize the request
    ClientAuthorization auth = authorize(message);
    if (!auth.isAuthorized()) {
        ErrorResponse error = new ErrorResponse(401, auth.getError(), auth.getDescription());
        setAliasIfPresent(error, message);
        sendResponse(error);
        return;
    }
    // Parse the request
    InternalRequest req = parseRequest(message, auth);
    if (req instanceof InternalDiscardRequest) {
        logger.error("@onMessage " + getGID() + " failed to parse message: " + message);
        setAliasIfPresent(((InternalDiscardRequest) req).getError(), message);
        sendResponse(((InternalDiscardRequest) req).getError());
        return;
    }
    // Schedule the request
    logger.trace("@onMessage: " + getGID() + " schedule request: " + req);
    ScheduledRequest request = scheduler.schedule(req, this);
    // Request not scheduled
    if (request == null) {
        logger.error("@onMessage: " + getGID() + " out of tokens");
        ErrorResponse response = new ErrorResponse(500, "too_many_requests", "Too many pending requests");
        setAliasIfPresent(response, message);
        sendResponse(response);
    }
}
Also used : ClientAuthorization(it.unibo.arces.wot.sepa.commons.security.ClientAuthorization) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Aggregations

ClientAuthorization (it.unibo.arces.wot.sepa.commons.security.ClientAuthorization)6 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)4 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)3 JOSEException (com.nimbusds.jose.JOSEException)2 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 Credentials (it.unibo.arces.wot.sepa.commons.security.Credentials)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 JsonParser (com.google.gson.JsonParser)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 BadJOSEException (com.nimbusds.jose.proc.BadJOSEException)1 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)1 SEPASparqlParsingException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASparqlParsingException)1 JWTResponse (it.unibo.arces.wot.sepa.commons.response.JWTResponse)1 RegistrationResponse (it.unibo.arces.wot.sepa.commons.response.RegistrationResponse)1 Response (it.unibo.arces.wot.sepa.commons.response.Response)1