Search in sources :

Example 1 with BizSystemModule

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;
}
Also used : ApiInfo(com.jeesuite.common.model.ApiInfo) BizSystemModule(com.jeesuite.gateway.model.BizSystemModule) ApiPermission(com.jeesuite.security.model.ApiPermission) ArrayList(java.util.ArrayList)

Example 2 with BizSystemModule

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApiInfo(com.jeesuite.common.model.ApiInfo) BizSystemModule(com.jeesuite.gateway.model.BizSystemModule)

Example 3 with BizSystemModule

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;
}
Also used : ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) ZuulProperties(org.springframework.cloud.netflix.zuul.filters.ZuulProperties) ZuulRoute(org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BizSystemModule(com.jeesuite.gateway.model.BizSystemModule)

Example 4 with BizSystemModule

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);
}
Also used : Properties(java.util.Properties) Logger(org.slf4j.Logger) ApiInfo(com.jeesuite.common.model.ApiInfo) GenericApiRequest(com.jeesuite.springweb.client.GenericApiRequest) ResourceUtils(com.jeesuite.common.util.ResourceUtils) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) HashMap(java.util.HashMap) GlobalRuntimeContext(com.jeesuite.common.GlobalRuntimeContext) AppMetadataHolder(com.jeesuite.springweb.exporter.AppMetadataHolder) AppMetadata(com.jeesuite.springweb.model.AppMetadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) InstanceFactory(com.jeesuite.spring.InstanceFactory) List(java.util.List) Map(java.util.Map) SystemMgtApi(com.jeesuite.gateway.api.SystemMgtApi) Entry(java.util.Map.Entry) BizSystemPortal(com.jeesuite.gateway.model.BizSystemPortal) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) BizSystemModule(com.jeesuite.gateway.model.BizSystemModule) HashMap(java.util.HashMap) BizSystemModule(com.jeesuite.gateway.model.BizSystemModule) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Example 5 with BizSystemModule

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) BizSystemModule(com.jeesuite.gateway.model.BizSystemModule) RequestContext(com.netflix.zuul.context.RequestContext) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Aggregations

BizSystemModule (com.jeesuite.gateway.model.BizSystemModule)6 ApiInfo (com.jeesuite.common.model.ApiInfo)3 JeesuiteBaseException (com.jeesuite.common.JeesuiteBaseException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Properties (java.util.Properties)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 GlobalRuntimeContext (com.jeesuite.common.GlobalRuntimeContext)1 ResourceUtils (com.jeesuite.common.util.ResourceUtils)1 SystemMgtApi (com.jeesuite.gateway.api.SystemMgtApi)1 BizSystemPortal (com.jeesuite.gateway.model.BizSystemPortal)1 ApiPermission (com.jeesuite.security.model.ApiPermission)1 InstanceFactory (com.jeesuite.spring.InstanceFactory)1 GenericApiRequest (com.jeesuite.springweb.client.GenericApiRequest)1 AppMetadataHolder (com.jeesuite.springweb.exporter.AppMetadataHolder)1 AppMetadata (com.jeesuite.springweb.model.AppMetadata)1 RequestContext (com.netflix.zuul.context.RequestContext)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1