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));
});
}
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);
}
}
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");
}
}
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");
}
}
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());
}
Aggregations