use of com.jeesuite.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class GatewaySecurityDecisionProvider method getAllApiPermissions.
@Override
public List<ApiPermission> getAllApiPermissions() {
List<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;
}
use of com.jeesuite.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class GlobalAdditionHandler method afterAuthorization.
@Override
public void afterAuthorization(UserSession userSession) {
if (!actionLogEnabled)
return;
HttpServletRequest request = CurrentRuntimeContext.getRequest();
BizSystemModule module = CurrentSystemHolder.getModule(currentRouteName(request.getRequestURI()));
ApiInfo apiInfo = module.getApiInfo(request.getRequestURI());
boolean logging = apiInfo != null ? apiInfo.isActionLog() : true;
if (logging) {
logging = !ignoreReadMethodLog || !request.getMethod().equals(RequestMethod.GET.name());
}
if (logging) {
ActionLogCollector.onRequestStart(request).apiMeta(apiInfo);
}
}
use of com.jeesuite.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class ResponseLogHandler method process.
@Override
public Object process(RequestContext ctx, HttpServletRequest request, BizSystemModule module) {
int statusCode = ctx.getResponseStatusCode();
if (statusCode != 200)
return null;
ActionLog actionLog = ActionLogCollector.currentActionLog();
if (actionLog == null)
return null;
List<Pair<String, String>> headers = ctx.getOriginResponseHeaders();
for (Pair<String, String> pair : headers) {
if (CustomRequestHeaders.HEADER_EXCEPTION_CODE.equals(pair.first())) {
actionLog.setResponseCode(Integer.parseInt(pair.second()));
break;
}
}
if (ignoreBody)
return null;
ApiInfo apiInfo = module.getApiInfo(request.getRequestURI());
if (apiInfo != null && !apiInfo.isResponseLog()) {
return null;
}
ResponseCompose responseCompose = new ResponseCompose(ctx);
ctx.set(ResponseCompose.class.getName(), responseCompose);
actionLog.setResponseData(responseCompose.getBodyString());
return null;
}
use of com.jeesuite.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class RequestLogHandler method process.
@Override
public Object process(RequestContext ctx, HttpServletRequest request, BizSystemModule module) {
ActionLog actionLog = ActionLogCollector.currentActionLog();
if (actionLog == null)
return null;
actionLog.setModuleId(module.getServiceId());
ApiInfo apiInfo = module.getApiInfo(request.getRequestURI());
if (apiInfo != null && !apiInfo.isRequestLog()) {
return null;
}
actionLog.setQueryParameters(request.getQueryString());
if (!ignoreBody && HttpMethod.POST.name().equals(request.getMethod()) && !WebUtils.isMultipartContent(request)) {
try {
String data = CharStreams.toString(new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8));
actionLog.setRequestData(data);
} catch (Exception e) {
}
}
return null;
}
use of com.jeesuite.common.model.ApiInfo in project jeesuite-libs by vakinge.
the class AppMetadataHolder method scanApiInfos.
private static synchronized void scanApiInfos(AppMetadata metadata, List<String> classNameList) {
if (!metadata.getApis().isEmpty())
return;
Method[] methods;
String baseUri;
ApiInfo apiInfo;
ApiMetadata classMetadata;
ApiMetadata methodMetadata;
for (String className : classNameList) {
if (!className.contains(GlobalRuntimeContext.MODULE_NAME))
continue;
try {
Class<?> clazz = Class.forName(className);
if (!clazz.isAnnotationPresent(Controller.class) && !clazz.isAnnotationPresent(RestController.class)) {
continue;
}
RequestMapping requestMapping = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);
if (requestMapping != null) {
baseUri = requestMapping.value()[0];
if (!baseUri.startsWith("/"))
baseUri = "/" + baseUri;
if (baseUri.endsWith("/"))
baseUri = baseUri.substring(0, baseUri.length() - 1);
} else {
baseUri = "";
}
//
classMetadata = clazz.getAnnotation(ApiMetadata.class);
methods = clazz.getDeclaredMethods();
Map<String, Method> interfaceMethods = getInterfaceMethods(clazz);
methodLoop: for (Method method : methods) {
methodMetadata = method.isAnnotationPresent(ApiMetadata.class) ? method.getAnnotation(ApiMetadata.class) : classMetadata;
String apiUri = null;
String apiHttpMethod = null;
requestMapping = getAnnotation(method, interfaceMethods.get(method.getName()), RequestMapping.class);
if (requestMapping != null) {
apiUri = requestMapping.value()[0];
if (requestMapping.method() != null && requestMapping.method().length > 0) {
apiHttpMethod = requestMapping.method()[0].name();
}
} else {
PostMapping postMapping = getAnnotation(method, interfaceMethods.get(method.getName()), PostMapping.class);
if (postMapping != null) {
apiUri = postMapping.value()[0];
apiHttpMethod = RequestMethod.POST.name();
}
GetMapping getMapping = getAnnotation(method, interfaceMethods.get(method.getName()), GetMapping.class);
if (getMapping != null) {
apiUri = getMapping.value()[0];
apiHttpMethod = RequestMethod.GET.name();
}
}
if (StringUtils.isBlank(apiUri)) {
continue methodLoop;
}
apiInfo = new ApiInfo();
if (apiUri == null) {
apiUri = baseUri;
} else {
if (!apiUri.startsWith("/")) {
apiUri = "/" + apiUri;
}
apiUri = baseUri + apiUri;
}
apiInfo.setUrl(apiUri);
apiInfo.setMethod(apiHttpMethod);
if (method.isAnnotationPresent(ApiOperation.class)) {
apiInfo.setName(method.getAnnotation(ApiOperation.class).value());
} else {
apiInfo.setName(apiInfo.getUrl());
}
if (methodMetadata != null) {
apiInfo.setActionLog(methodMetadata.actionLog());
apiInfo.setRequestLog(methodMetadata.requestLog());
apiInfo.setResponseLog(methodMetadata.responseLog());
}
if (methodMetadata != null && StringUtils.isNotBlank(methodMetadata.actionName())) {
apiInfo.setName(methodMetadata.actionName());
} else if (method.isAnnotationPresent(ApiOperation.class)) {
apiInfo.setName(method.getAnnotation(ApiOperation.class).value());
}
if (methodMetadata == null) {
apiInfo.setPermissionType(PermissionLevel.LoginRequired);
} else {
apiInfo.setPermissionType(methodMetadata.permissionLevel());
}
metadata.addApi(apiInfo);
}
} catch (Exception e) {
System.err.println("error className:" + className);
}
}
}
Aggregations