Search in sources :

Example 6 with Request

use of io.openk9.entity.manager.model.payload.Request in project openk9 by smclab.

the class AuthResource method logout.

@PermitAll
@Path("/v1/auth/logout")
@POST
public Uni<byte[]> logout(@Context HttpServerRequest context, RefreshToken request) {
    String host = context.host();
    Tenant tenant = _findTenant(host);
    String realmName = tenant.getRealmName();
    String clientSecret = tenant.getClientSecret();
    String clientId = tenant.getClientId();
    String refreshToken = request.getRefreshToken();
    if (refreshToken == null) {
        return Uni.createFrom().failure(() -> new HttpException(400, "required refreshToken"));
    }
    if (clientSecret != null) {
        return _authClient.logout(realmName, clientId, clientSecret, refreshToken);
    } else {
        return _authClient.logout(realmName, clientId, refreshToken);
    }
}
Also used : Tenant(io.openk9.api.aggregator.model.Tenant) HttpException(io.vertx.ext.web.handler.HttpException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 7 with Request

use of io.openk9.entity.manager.model.payload.Request in project openk9 by smclab.

the class AuthResource method refreshToken.

@PermitAll
@Path("/v1/auth/refresh")
@POST
public Uni<LoginResponseDTO> refreshToken(@Context HttpServerRequest context, RefreshToken request) {
    String host = context.host();
    Tenant tenant = _findTenant(host);
    String realmName = tenant.getRealmName();
    String clientSecret = tenant.getClientSecret();
    String clientId = tenant.getClientId();
    String refreshToken = request.getRefreshToken();
    if (refreshToken == null) {
        return Uni.createFrom().failure(() -> new HttpException(400, "required refreshToken"));
    }
    if (clientSecret != null) {
        return _authClient.refresh(realmName, clientId, clientSecret, refreshToken, "refresh_token");
    } else {
        return _authClient.refresh(realmName, clientId, refreshToken, "refresh_token");
    }
}
Also used : Tenant(io.openk9.api.aggregator.model.Tenant) HttpException(io.vertx.ext.web.handler.HttpException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 8 with Request

use of io.openk9.entity.manager.model.payload.Request in project openk9 by smclab.

the class EntityManagerConsumer method consume.

@Incoming("entity-manager-request")
@Outgoing("entity-manager-response")
@Blocking
public Message<JsonObject> consume(Object obj) throws InterruptedException {
    JsonObject jsonObject = obj instanceof JsonObject ? (JsonObject) obj : new JsonObject(new String((byte[]) obj));
    Payload payload = jsonObject.mapTo(Payload.class);
    _entityManagerQueue.offer(payload, 45, TimeUnit.SECONDS);
    String replyTo = payload.getReplyTo();
    return Message.of(jsonObject, Metadata.of(new OutgoingRabbitMQMetadata.Builder().withRoutingKey(replyTo).withTimestamp(ZonedDateTime.now()).build()));
}
Also used : OutgoingRabbitMQMetadata(io.smallrye.reactive.messaging.rabbitmq.OutgoingRabbitMQMetadata) JsonObject(io.vertx.core.json.JsonObject) Payload(io.openk9.entity.manager.dto.Payload) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) Blocking(io.smallrye.reactive.messaging.annotations.Blocking) Outgoing(org.eclipse.microprofile.reactive.messaging.Outgoing)

Example 9 with Request

use of io.openk9.entity.manager.model.payload.Request in project openk9 by smclab.

the class AuthResource method login.

@PermitAll
@Path("/v1/auth/login")
@POST
public Uni<LoginResponseDTO> login(@Context HttpServerRequest context, LoginRequest request) {
    String host = context.host();
    Tenant tenant = _findTenant(host);
    String realmName = tenant.getRealmName();
    String clientSecret = tenant.getClientSecret();
    String clientId = tenant.getClientId();
    String username = request.getUsername();
    String password = request.getPassword();
    if (username == null) {
        return Uni.createFrom().failure(() -> new HttpException(400, "required username"));
    }
    if (password == null) {
        return Uni.createFrom().failure(() -> new HttpException(400, "required password"));
    }
    if (clientSecret != null) {
        return _authClient.login(realmName, username, password, clientId, clientSecret, "password");
    } else {
        return _authClient.login(realmName, username, password, clientId, "password");
    }
}
Also used : Tenant(io.openk9.api.aggregator.model.Tenant) HttpException(io.vertx.ext.web.handler.HttpException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 10 with Request

use of io.openk9.entity.manager.model.payload.Request in project openk9 by smclab.

the class JsEnrichProcessor method prepareRequestRawContent.

protected ObjectNode prepareRequestRawContent(ObjectNode objectNode, ObjectNode datasourceConfiguration, DatasourceContext context, PluginDriverDTO pluginDriverDTO) {
    JsonNode rawContentNode = objectNode.get(Constants.RAW_CONTENT);
    JsonNode codeNode = datasourceConfiguration.get(Constants.CODE);
    ObjectNode request = _jsonFactory.createObjectNode();
    request.put(Constants.CODE, codeNode);
    request.put(Constants.CONTENT, rawContentNode);
    JsonNode typeNode = objectNode.get(Constants.TYPE);
    ObjectNode datasourcePayload = _jsonFactory.createObjectNode();
    if (typeNode != null && typeNode.isArray()) {
        ArrayNode types = typeNode.toArrayNode();
        for (JsonNode typeJsonNode : types) {
            String type = typeJsonNode.asText();
            datasourcePayload.put(type, objectNode.get(type));
        }
    }
    request.put(Constants.DATASOURCE_PAYLOAD, datasourcePayload);
    request.put(Constants.TENANT_ID, context.getTenant().getTenantId());
    request.put(Constants.DATASOURCE_ID, context.getDatasource().getDatasourceId());
    request.put(Constants.CONTENT_ID, objectNode.get(Constants.CONTENT_ID));
    return request;
}
Also used : ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode) ArrayNode(io.openk9.json.api.ArrayNode)

Aggregations

JsonNode (io.openk9.json.api.JsonNode)6 ObjectNode (io.openk9.json.api.ObjectNode)6 Tenant (io.openk9.api.aggregator.model.Tenant)3 ArrayNode (io.openk9.json.api.ArrayNode)3 JsonFactory (io.openk9.json.api.JsonFactory)3 HttpException (io.vertx.ext.web.handler.HttpException)3 Collectors (java.util.stream.Collectors)3 PermitAll (javax.annotation.security.PermitAll)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Mono (reactor.core.publisher.Mono)3 Payload (io.openk9.entity.manager.dto.Payload)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Activate (org.osgi.service.component.annotations.Activate)2 Component (org.osgi.service.component.annotations.Component)2 Reference (org.osgi.service.component.annotations.Reference)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2