Search in sources :

Example 16 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class AuthorizationManager method securityCheck.

private void securityCheck(String identity) {
    logger.debug("*** Security check ***");
    // Add identity
    addAuthorizedIdentity(identity);
    // Register
    logger.debug("Register: " + identity);
    Response response = register(identity);
    if (response.getClass().equals(RegistrationResponse.class)) {
        RegistrationResponse ret = (RegistrationResponse) response;
        String auth = ret.getClientId() + ":" + ret.getClientSecret();
        logger.debug("ID:SECRET=" + auth);
        // Get token
        String encodedCredentials = Base64.getEncoder().encodeToString(auth.getBytes());
        logger.debug("Authorization Basic " + encodedCredentials);
        response = getToken(encodedCredentials);
        if (response.getClass().equals(JWTResponse.class)) {
            logger.debug("Access token: " + ((JWTResponse) response).getAccessToken());
            // Validate token
            Response valid = validateToken(((JWTResponse) response).getAccessToken());
            if (!valid.getClass().equals(ErrorResponse.class))
                logger.debug("PASSED");
            else {
                ErrorResponse error = (ErrorResponse) valid;
                logger.debug("FAILED Code: " + error.getErrorCode() + "Message: " + error.getErrorMessage());
            }
        } else
            logger.debug("FAILED");
    } else
        logger.debug("FAILED");
    logger.debug("**********************");
    System.out.println("");
    // Add identity
    removeAuthorizedIdentity(identity);
}
Also used : ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) JWTResponse(it.unibo.arces.wot.sepa.commons.response.JWTResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) RegistrationResponse(it.unibo.arces.wot.sepa.commons.response.RegistrationResponse) RegistrationResponse(it.unibo.arces.wot.sepa.commons.response.RegistrationResponse) JWTResponse(it.unibo.arces.wot.sepa.commons.response.JWTResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 17 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class MessageReceiver method joinChat.

public boolean joinChat() {
    if (joined)
        return true;
    Response ret = subscribe(message);
    joined = !ret.isError();
    if (joined) {
        for (Bindings bindings : ((SubscribeResponse) ret).getBindingsResults().getBindings()) {
            listener.onMessageReceived(new Message(bindings.getBindingValue("sender"), message.getBindingValue("receiver"), bindings.getBindingValue("text"), bindings.getBindingValue("time")));
        }
    }
    return joined;
}
Also used : SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 18 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class MessageReceiver method leaveChat.

public boolean leaveChat() {
    if (!joined)
        return true;
    Response ret = unsubscribe();
    joined = !ret.isUnsubscribeResponse();
    return !joined;
}
Also used : SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 19 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class MessageSender method joinChat.

public boolean joinChat() {
    if (joined)
        return true;
    Response ret = subscribe(message);
    joined = !ret.isError();
    if (joined) {
        for (Bindings bindings : ((SubscribeResponse) ret).getBindingsResults().getBindings()) {
            listener.onMessageSent(new Message(message.getBindingValue("sender"), bindings.getBindingValue("receiver"), bindings.getBindingValue("text"), bindings.getBindingValue("time")));
        }
    }
    return joined;
}
Also used : SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings)

Example 20 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class MessageSender method leaveChat.

public boolean leaveChat() {
    if (!joined)
        return true;
    Response ret = unsubscribe();
    joined = !ret.isUnsubscribeResponse();
    return !joined;
}
Also used : SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Aggregations

Response (it.unibo.arces.wot.sepa.commons.response.Response)40 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)31 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)19 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)15 Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)12 Test (org.junit.Test)8 RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)7 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)6 RDFTermURI (it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI)5 JsonObject (com.google.gson.JsonObject)3 SubscribeRequest (it.unibo.arces.wot.sepa.commons.request.SubscribeRequest)3 ARBindingsResults (it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults)3 BindingsResults (it.unibo.arces.wot.sepa.commons.sparql.BindingsResults)3 IOException (java.io.IOException)3 Header (org.apache.http.Header)3 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 QueryRequest (it.unibo.arces.wot.sepa.commons.request.QueryRequest)2 UnsubscribeRequest (it.unibo.arces.wot.sepa.commons.request.UnsubscribeRequest)2 UpdateRequest (it.unibo.arces.wot.sepa.commons.request.UpdateRequest)2