Java Code Examples for org.springframework.cloud.netflix.zuul.filters.Route#getId()

The following examples show how to use org.springframework.cloud.netflix.zuul.filters.Route#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessControlFilter.java    From flair-registry with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();

    log.debug(requestUri);

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 2
Source File: AccessControlFilter.java    From java-microservices-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();
    String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = contextPath + route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 3
Source File: AccessControlFilter.java    From cubeai with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();

    // 使用ng2-file-upload上传文件时,如果通过zuul路由,URL前面需要加'zuul'前缀
    if (requestUri.startsWith("/zuul")) {
        requestUri = requestUri.substring(5);
    }

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 4
Source File: AccessControlFilter.java    From okta-jhipster-microservices-oauth-example with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();
    String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = contextPath + route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 5
Source File: AccessControlFilter.java    From e-commerce-microservice with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();
    String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = contextPath + route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 6
Source File: AccessControlFilter.java    From jhipster-microservices-example with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 7
Source File: AccessControlFilter.java    From jhipster-microservices-example with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();

    log.debug(requestUri);

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 8
Source File: AccessControlFilter.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
            if (isAuthorizedRequest(serviceUrl, serviceName, requestUri)) {
                return false;
            }
        }
    }
    return true;
}
 
Example 9
Source File: _AccessControlFilter.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
            if (isAuthorizedRequest(serviceUrl, serviceName, requestUri)) {
                return false;
            }
        }
    }
    return true;
}
 
Example 10
Source File: AbstractRateLimitFilter.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected List<Policy> policy(Route route, HttpServletRequest request) {
    List<Policy> policies = (List<Policy>) RequestContext.getCurrentContext().get(CURRENT_REQUEST_POLICY);
    if (policies != null) {
        return policies;
    }

    String routeId = route != null ? route.getId() : null;

    RequestContext.getCurrentContext().put(ALREADY_LIMITED, false);

    policies = properties.getPolicies(routeId).stream()
            .filter(policy -> applyPolicy(request, route, policy))
            .collect(Collectors.toList());

    addObjectToCurrentRequestContext(CURRENT_REQUEST_POLICY, policies);

    return policies;
}
 
Example 11
Source File: AccessControlFilter.java    From jhipster-registry with Apache License 2.0 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();
    String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = contextPath + route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
            return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 12
Source File: AccessControlFilter.java    From tutorials with MIT License 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 13
Source File: AccessControlFilter.java    From tutorials with MIT License 6 votes vote down vote up
/**
 * Filter requests on endpoints that are not in the list of authorized microservices endpoints.
 */
@Override
public boolean shouldFilter() {
    String requestUri = RequestContext.getCurrentContext().getRequest().getRequestURI();
    String contextPath = RequestContext.getCurrentContext().getRequest().getContextPath();

    // If the request Uri does not start with the path of the authorized endpoints, we block the request
    for (Route route : routeLocator.getRoutes()) {
        String serviceUrl = contextPath + route.getFullPath();
        String serviceName = route.getId();

        // If this route correspond to the current request URI
        // We do a substring to remove the "**" at the end of the route URL
        if (requestUri.startsWith(serviceUrl.substring(0, serviceUrl.length() - 2))) {
return !isAuthorizedRequest(serviceUrl, serviceName, requestUri);
        }
    }
    return true;
}
 
Example 14
Source File: SwaggerResourcesProcessor.java    From swagger-butler with Apache License 2.0 4 votes vote down vote up
@Override
public List<SwaggerResource> get() {
    List<SwaggerResource> resources = new ArrayList<>();

    List<Route> routes = routeLocator.getRoutes();
    for (Route route : routes) {
        String routeName = route.getId();

        SwaggerResourceProperties resourceProperties = swaggerButlerConfig.getResources().get(routeName);

        // 不用根据zuul的路由自动生成,并且当前route信息没有配置resource则不生成文档
        if (swaggerButlerConfig.getAutoGenerateFromZuulRoutes() == false && resourceProperties == null) {
            continue;
        }

        // 需要根据zuul的路由自动生成,但是当前路由名在忽略清单中(ignoreRoutes)或者不在生成清单中(generateRoutes)则不生成文档
        if (swaggerButlerConfig.getAutoGenerateFromZuulRoutes() == true && swaggerButlerConfig.needIgnore(routeName)) {
            continue;
        }

        // 处理swagger文档的名称
        String name = routeName;
        if (resourceProperties != null && resourceProperties.getName() != null) {
            name = resourceProperties.getName();
        }

        // 处理获取swagger文档的路径
        String swaggerPath = swaggerButlerConfig.getApiDocsPath();
        if (resourceProperties != null && resourceProperties.getApiDocsPath() != null) {
            swaggerPath = resourceProperties.getApiDocsPath();
        }
        String location = route.getFullPath().replace("**", swaggerPath);

        // 处理swagger的版本设置
        String swaggerVersion = swaggerButlerConfig.getSwaggerVersion();
        if (resourceProperties != null && resourceProperties.getSwaggerVersion() != null) {
            swaggerVersion = resourceProperties.getSwaggerVersion();
        }

        resources.add(swaggerResource(name, location, swaggerVersion));

    }

    return resources;
}