Search in sources :

Example 1 with HttpException

use of io.openk9.http.exception.HttpException in project openk9 by smclab.

the class PluginDriverEndPoints method _findPluginDriverByName.

private Publisher<Void> _findPluginDriverByName(HttpServerRequest httpRequest, HttpServerResponse httpResponse) {
    return Mono.defer(() -> {
        String serviceDriverName = httpRequest.param("serviceDriverName");
        PluginDriverDTO response = _pluginDriverDTOService.findPluginDriverDTOByName(serviceDriverName).orElseThrow(() -> new HttpException(404, "No Content. PluginDriver not found for serviceDriverName: " + serviceDriverName));
        return Mono.from(_httpResponseWriter.write(httpResponse, response));
    });
}
Also used : HttpException(io.openk9.http.exception.HttpException) PluginDriverDTO(io.openk9.plugin.driver.manager.model.PluginDriverDTO)

Example 2 with HttpException

use of io.openk9.http.exception.HttpException 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 3 with HttpException

use of io.openk9.http.exception.HttpException 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 4 with HttpException

use of io.openk9.http.exception.HttpException 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 5 with HttpException

use of io.openk9.http.exception.HttpException in project openk9 by smclab.

the class PluginDriverEndPoints method _invokeDataParser.

private Publisher<Void> _invokeDataParser(HttpServerRequest httpRequest, HttpServerResponse httpResponse) {
    return Mono.defer(() -> Mono.from(ReactorNettyUtils.aggregateBodyAsString(httpRequest)).map(json -> _jsonFactory.fromJson(json, InvokeDataParserDTO.class)).flatMap((invokeDataParserDTO) -> {
        String serviceDriverName = invokeDataParserDTO.getServiceDriverName();
        Optional<PluginDriver> optional = _pluginDriverRegistry.getPluginDriver(serviceDriverName);
        if (optional.isEmpty()) {
            throw new HttpException(404, "No Content. PluginDriver not found for serviceDriverName: " + serviceDriverName);
        } else {
            PluginDriver pluginDriver = optional.get();
            if (pluginDriver.schedulerEnabled()) {
                return Mono.from(pluginDriver.invokeDataParser(invokeDataParserDTO.getDatasource(), invokeDataParserDTO.getFromDate(), invokeDataParserDTO.getToDate()));
            } else {
                throw new HttpException(412, " Precondition Failed. PluginDriver scheduler is disabled for serviceDriverName: " + serviceDriverName);
            }
        }
    }).then());
}
Also used : HttpException(io.openk9.http.exception.HttpException) InvokeDataParserDTO(io.openk9.plugin.driver.manager.model.InvokeDataParserDTO) HttpServerResponse(reactor.netty.http.server.HttpServerResponse) PluginDriverDTO(io.openk9.plugin.driver.manager.model.PluginDriverDTO) SchedulerEnabledDTO(io.openk9.plugin.driver.manager.model.SchedulerEnabledDTO) PluginDriverDTOList(io.openk9.plugin.driver.manager.model.PluginDriverDTOList) Publisher(org.reactivestreams.Publisher) PluginDriverDTOService(io.openk9.plugin.driver.manager.api.PluginDriverDTOService) PluginDriverRegistry(io.openk9.plugin.driver.manager.api.PluginDriverRegistry) Mono(reactor.core.publisher.Mono) HttpResponseWriter(io.openk9.http.util.HttpResponseWriter) JsonFactory(io.openk9.json.api.JsonFactory) HttpServerRequest(reactor.netty.http.server.HttpServerRequest) ReactorNettyUtils(io.openk9.reactor.netty.util.ReactorNettyUtils) Component(org.osgi.service.component.annotations.Component) Optional(java.util.Optional) PluginDriver(io.openk9.plugin.driver.manager.api.PluginDriver) Reference(org.osgi.service.component.annotations.Reference) HttpServerRoutes(reactor.netty.http.server.HttpServerRoutes) RouterHandler(io.openk9.http.web.RouterHandler) PluginDriver(io.openk9.plugin.driver.manager.api.PluginDriver) HttpException(io.openk9.http.exception.HttpException)

Aggregations

Tenant (io.openk9.api.aggregator.model.Tenant)3 HttpException (io.vertx.ext.web.handler.HttpException)3 PermitAll (javax.annotation.security.PermitAll)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 HttpException (io.openk9.http.exception.HttpException)2 PluginDriverDTO (io.openk9.plugin.driver.manager.model.PluginDriverDTO)2 HttpResponseWriter (io.openk9.http.util.HttpResponseWriter)1 RouterHandler (io.openk9.http.web.RouterHandler)1 JsonFactory (io.openk9.json.api.JsonFactory)1 PluginDriver (io.openk9.plugin.driver.manager.api.PluginDriver)1 PluginDriverDTOService (io.openk9.plugin.driver.manager.api.PluginDriverDTOService)1 PluginDriverRegistry (io.openk9.plugin.driver.manager.api.PluginDriverRegistry)1 InvokeDataParserDTO (io.openk9.plugin.driver.manager.model.InvokeDataParserDTO)1 PluginDriverDTOList (io.openk9.plugin.driver.manager.model.PluginDriverDTOList)1 SchedulerEnabledDTO (io.openk9.plugin.driver.manager.model.SchedulerEnabledDTO)1 ReactorNettyUtils (io.openk9.reactor.netty.util.ReactorNettyUtils)1 Optional (java.util.Optional)1 Component (org.osgi.service.component.annotations.Component)1 Reference (org.osgi.service.component.annotations.Reference)1