use of com.mendmix.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class ResponseLogHandler method process.
@Override
public String process(ServerWebExchange exchange, BizSystemModule module, String respBodyAsString) {
if (!exchange.getResponse().getStatusCode().is2xxSuccessful()) {
return respBodyAsString;
}
ActionLog actionLog = exchange.getAttribute(ActionLogCollector.CURRENT_LOG_CONTEXT_NAME);
if (actionLog == null)
return respBodyAsString;
HttpHeaders headers = exchange.getResponse().getHeaders();
if (headers.containsKey(CustomRequestHeaders.HEADER_EXCEPTION_CODE)) {
actionLog.setResponseCode(Integer.parseInt(headers.getFirst(CustomRequestHeaders.HEADER_EXCEPTION_CODE)));
}
if (actionLog.getResponseCode() != 200) {
actionLog.setResponseCode(200);
}
if (bodyIgnore)
return respBodyAsString;
ApiInfo apiInfo = RuequestHelper.getCurrentApi(exchange);
if (apiInfo != null && !apiInfo.isResponseLog()) {
return respBodyAsString;
}
//
actionLog.setResponseData(respBodyAsString);
return respBodyAsString;
}
use of com.mendmix.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class CurrentSystemHolder method initModuleApiInfos.
private static void initModuleApiInfos(BizSystemModule module) {
try {
String url;
AppMetadata appMetadata;
if (GlobalRuntimeContext.APPID.equals(module.getRouteName())) {
appMetadata = AppMetadataHolder.getMetadata();
} else {
url = module.getMetadataUri();
appMetadata = HttpRequestEntity.get(url).backendInternalCall().execute().toObject(AppMetadata.class);
}
for (ApiInfo api : appMetadata.getApis()) {
module.addApiInfo(api);
}
moduleApiInfos.put(module.getServiceId(), module.getApiInfos());
log.info(">>initModuleApiInfos success -> serviceId:{},nums:{}", module.getServiceId(), module.getApiInfos().size());
} catch (Exception e) {
boolean ignore = e instanceof ClassCastException;
if (!ignore && e instanceof JeesuiteBaseException) {
JeesuiteBaseException ex = (JeesuiteBaseException) e;
ignore = ex.getCode() == 404 || ex.getCode() == 401 || ex.getCode() == 403;
}
if (ignore) {
module.setApiInfos(new HashMap<>(0));
moduleApiInfos.put(module.getServiceId(), module.getApiInfos());
} else if (fetchApiMetaRound <= 1) {
log.error(">>initModuleApiInfos error -> serviceId:[" + module.getServiceId() + "]", e);
}
}
}
use of com.mendmix.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class BizSystemModule method getApiInfo.
public ApiInfo getApiInfo(String method, String uri) {
String uniqueKey = buildUniqueKey(method, uri);
ApiInfo apiInfo = getApiInfos().get(uniqueKey);
if (apiInfo != null) {
return apiInfo;
}
for (Pattern pattern : wildcardUris.keySet()) {
if (pattern.matcher(uniqueKey).matches()) {
return wildcardUris.get(pattern);
}
}
return null;
}
use of com.mendmix.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class GatewayReactiveCustomAuthnHandler method afterAuthentication.
@Override
public void afterAuthentication(ServerWebExchange exchange, UserSession userSession) {
if (!GatewayConfigs.actionLogEnabled)
return;
ServerHttpRequest request = exchange.getRequest();
BizSystemModule module = CurrentSystemHolder.getModule(RuequestHelper.resolveRouteName(request.getPath().value()));
ApiInfo apiInfo = module.getApiInfo(request.getMethodValue(), request.getPath().value());
boolean logging = apiInfo != null ? apiInfo.isActionLog() : true;
if (logging) {
logging = !GatewayConfigs.actionLogGetMethodIngore || !request.getMethod().equals(HttpMethod.GET);
}
if (logging) {
String clientIp = RuequestHelper.getIpAddr(request);
ActionLog actionLog = ActionLogCollector.onRequestStart(request.getMethodValue(), request.getPath().value(), clientIp).apiMeta(apiInfo);
exchange.getAttributes().put(ActionLogCollector.CURRENT_LOG_CONTEXT_NAME, actionLog);
}
}
use of com.mendmix.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class GatewaySecurityDecisionProvider method getAllApiPermissions.
@Override
public List<ApiPermission> getAllApiPermissions() {
Collection<BizSystemModule> modules = CurrentSystemHolder.getModules();
List<ApiPermission> result = new ArrayList<>();
Collection<ApiInfo> apis;
ApiPermission apiPermission;
for (BizSystemModule module : modules) {
if (module.getApiInfos() == null)
continue;
apis = module.getApiInfos().values();
for (ApiInfo apiInfo : apis) {
apiPermission = new ApiPermission();
apiPermission.setGrantType(apiInfo.getPermissionType().name());
apiPermission.setHttpMethod(apiInfo.getMethod());
apiPermission.setUri(apiInfo.getUrl());
result.add(apiPermission);
}
}
return result;
}
Aggregations