use of com.jeesuite.gateway.model.BizSystemModule 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.gateway.model.BizSystemModule 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.gateway.model.BizSystemModule in project jeesuite-libs by vakinge.
the class CustomDiscoveryClientRouteLocator method buildRemoteRoutes.
private Map<String, ZuulProperties.ZuulRoute> buildRemoteRoutes() {
if (currentRouteModules == null) {
currentRouteModules = CurrentSystemHolder.getRouteModuleMappings();
}
Collection<BizSystemModule> modules = currentRouteModules.values();
Map<String, ZuulProperties.ZuulRoute> routes = new HashMap<>();
String path = null;
ZuulProperties.ZuulRoute zuulRoute = null;
for (BizSystemModule module : modules) {
if (GlobalRuntimeContext.APPID.equalsIgnoreCase(module.getServiceId()))
continue;
if (StringUtils.isBlank(module.getServiceId()) && StringUtils.isBlank(module.getProxyUrl())) {
continue;
}
path = String.format("/%s/**", module.getRouteName());
zuulRoute = new ZuulProperties.ZuulRoute();
zuulRoute.setPath(path);
zuulRoute.setId(module.getRouteName());
if (StringUtils.isNotBlank(module.getProxyUrl())) {
zuulRoute.setUrl(module.getProxyUrl());
} else {
zuulRoute.setServiceId(module.getServiceId());
}
//
routes.put(path, zuulRoute);
}
return routes;
}
use of com.jeesuite.gateway.model.BizSystemModule in project jeesuite-libs by vakinge.
the class CurrentSystemHolder method load.
public static synchronized void load() {
if (localModules == null) {
loadLocalRouteModules();
}
List<BizSystemModule> modules;
try {
modules = InstanceFactory.getInstance(SystemMgtApi.class).getSystemModules();
if (!localModules.isEmpty()) {
modules.addAll(localModules);
}
} catch (Exception e) {
modules = localModules;
}
if (!modules.stream().anyMatch(o -> GlobalRuntimeContext.APPID.equalsIgnoreCase(o.getServiceId()))) {
BizSystemModule module = new BizSystemModule();
module.setServiceId(GlobalRuntimeContext.APPID);
modules.add(module);
localModules.add(module);
}
Map<String, BizSystemModule> _modules = new HashMap<>(modules.size());
routeNames = new ArrayList<>(modules.size());
for (BizSystemModule module : modules) {
boolean isGateway = GlobalRuntimeContext.APPID.equalsIgnoreCase(module.getServiceId());
if (!isGateway && StringUtils.isBlank(module.getRouteName())) {
continue;
}
// 网关特殊处理
if (isGateway) {
module.setRouteName(GlobalRuntimeContext.APPID);
if (module.getAnonymousUris() == null) {
module.setAnonymousUris(ResourceUtils.getProperty("jeesuite.request.anonymous-uris"));
}
} else {
routeNames.add(module.getRouteName());
}
module.buildAnonUriMatcher();
//
if (moduleApiInfos.containsKey(module.getServiceId())) {
module.setApiInfos(moduleApiInfos.get(module.getServiceId()));
} else {
new Thread(() -> initModuleApiInfos(module)).start();
}
_modules.put(module.getRouteName(), module);
}
routeModuleMappings.set(_modules);
}
use of com.jeesuite.gateway.model.BizSystemModule in project jeesuite-libs by vakinge.
the class AbstractZuulFilter method run.
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
if (!ctx.sendZuulResponse())
return null;
HttpServletRequest request = ctx.getRequest();
BizSystemModule module = (BizSystemModule) ctx.get(FilterConstants.CONTEXT_ROUTE_SERVICE);
try {
for (FilterHandler handler : handlers) {
handler.process(ctx, request, module);
}
} catch (Exception e) {
int code = (e instanceof JeesuiteBaseException) ? ((JeesuiteBaseException) e).getCode() : 500;
ctx.setResponseBody(WrapperResponse.buildErrorJSON(code, e.getMessage()));
ctx.setResponseStatusCode(503);
return null;
}
return null;
}
Aggregations