Search in sources :

Example 6 with Hcr

use of org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr in project java-chassis by ServiceComb.

the class EdgeSignatureRequestFilter method afterReceiveRequest.

@Override
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
    EncryptContext encryptContext = (EncryptContext) invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT);
    if (encryptContext == null) {
        return null;
    }
    Hcr hcr = encryptContext.getHcr();
    // signature for query and form
    List<String> names = Collections.list(requestEx.getParameterNames());
    names.sort(Comparator.naturalOrder());
    Hasher hasher = Hashing.sha256().newHasher();
    hasher.putString(hcr.getSignatureKey(), StandardCharsets.UTF_8);
    for (String name : names) {
        hasher.putString(name, StandardCharsets.UTF_8);
        hasher.putString(requestEx.getParameter(name), StandardCharsets.UTF_8);
    }
    LOGGER.info("afterReceiveRequest signature: {}", hasher.hash().toString());
    return null;
}
Also used : Hasher(com.google.common.hash.Hasher) Hcr(org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr) EncryptContext(org.apache.servicecomb.demo.edge.service.encrypt.EncryptContext)

Example 7 with Hcr

use of org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr in project incubator-servicecomb-java-chassis by apache.

the class EncryptEdgeDispatcher method onRequest.

protected void onRequest(RoutingContext context) {
    HttpServerRequest httpServerRequest = context.request();
    // queryUserId always success
    CompletableFuture<String> userIdFuture = queryUserId(httpServerRequest);
    queryHcr(httpServerRequest).thenCombine(userIdFuture, (hcr, userId) -> {
        // hcr and userId all success
        routeToBackend(context, hcr, userId);
        return null;
    }).whenComplete((v, e) -> {
        // failed to query hcr
        if (e != null) {
            context.response().end("failed to query hcr: " + e.getMessage());
            return;
        }
    });
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) Logger(org.slf4j.Logger) Map(java.util.Map) CompatiblePathVersionMapper(org.apache.servicecomb.edge.core.CompatiblePathVersionMapper) Invoker(org.apache.servicecomb.provider.pojo.Invoker) LoggerFactory(org.slf4j.LoggerFactory) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) Hcr(org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr) RoutingContext(io.vertx.ext.web.RoutingContext) AbstractEdgeDispatcher(org.apache.servicecomb.edge.core.AbstractEdgeDispatcher) HttpServerRequest(io.vertx.core.http.HttpServerRequest)

Example 8 with Hcr

use of org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr in project incubator-servicecomb-java-chassis by apache.

the class DecodeBodyFilter method afterReceiveRequest.

@Override
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
    EncryptContext encryptContext = (EncryptContext) invocation.getHandlerContext().get(EdgeConst.ENCRYPT_CONTEXT);
    if (encryptContext == null) {
        return null;
    }
    Hcr hcr = encryptContext.getHcr();
    String encodedBody = requestEx.getParameter("body");
    if (encodedBody == null) {
        return null;
    }
    encodedBody = encodedBody.substring(hcr.getBodyKey().length());
    try {
        Map<String, String[]> decodedBody = RestObjectMapperFactory.getRestObjectMapper().readValue(encodedBody, bodyType);
        requestEx.getParameterMap().putAll(decodedBody);
    } catch (Throwable e) {
        // should be a meaning exception response
        return Response.producerFailResp(e);
    }
    return null;
}
Also used : Hcr(org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr) EncryptContext(org.apache.servicecomb.demo.edge.service.encrypt.EncryptContext)

Aggregations

Hcr (org.apache.servicecomb.demo.edge.authentication.encrypt.Hcr)8 EncryptContext (org.apache.servicecomb.demo.edge.service.encrypt.EncryptContext)6 Hasher (com.google.common.hash.Hasher)4 Buffer (io.vertx.core.buffer.Buffer)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AbstractEdgeDispatcher (org.apache.servicecomb.edge.core.AbstractEdgeDispatcher)2 CompatiblePathVersionMapper (org.apache.servicecomb.edge.core.CompatiblePathVersionMapper)2 Invoker (org.apache.servicecomb.provider.pojo.Invoker)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2