当前位置: 首页>>代码示例>>Java>>正文


Java IPolicyContext.setAttribute方法代码示例

本文整理汇总了Java中io.apiman.gateway.engine.policy.IPolicyContext.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java IPolicyContext.setAttribute方法的具体用法?Java IPolicyContext.setAttribute怎么用?Java IPolicyContext.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.apiman.gateway.engine.policy.IPolicyContext的用法示例。


在下文中一共展示了IPolicyContext.setAttribute方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forwardAuthRoles

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
private void forwardAuthRoles(IPolicyContext context, KeycloakOauthConfigBean config,
        AccessToken parsedToken) {

    if (config.getForwardRoles().getActive()) {
        Access access = null;

        if (config.getForwardRoles().getApplicationName() != null) {
            access = parsedToken.getResourceAccess(config.getForwardRoles().getApplicationName());
        } else {
            access = parsedToken.getRealmAccess();
        }

        if (access == null || access.getRoles() == null) {
            context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, Collections.<String>emptySet());
        } else {
            context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, access.getRoles());
        }
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:20,代码来源:KeycloakOauthPolicy.java

示例2: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
@Override
protected void doApply(ApiRequest request, IPolicyContext context, TransformationConfigBean config,
        IPolicyChain<ApiRequest> chain) {
    DataFormat clientFormat = config.getClientFormat();
    DataFormat serverFormat = config.getServerFormat();

    if (isValidTransformation(clientFormat, serverFormat)) {
        context.setAttribute(CLIENT_FORMAT, clientFormat);
        context.setAttribute(SERVER_FORMAT, serverFormat);

        request.getHeaders().put(CONTENT_TYPE, serverFormat.getContentType());
        request.getHeaders().remove(CONTENT_LENGTH);
        
        request.getHeaders().put(ACCEPT, serverFormat.getContentType());
    }

    super.doApply(request, context, config, chain);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:19,代码来源:TransformationPolicy.java

示例3: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * See {@link AbstractMappedPolicy#doApply(ApiRequest, IPolicyContext, Object, IPolicyChain)}
 */
@Override
protected void doApply(ApiRequest request, IPolicyContext context, CookieIssueConfigBean config,
                       IPolicyChain<ApiRequest> chain) {

    // skip if path matcher is not use, or request URL doesn't match
    if (null == pathMatcher || !pathMatcher.matcher(request.getDestination()).matches()) {
        context.setAttribute(ATTRIBUTE_SKIP, true);
    }

    chain.doApply(request);
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:15,代码来源:CookieIssuePolicy.java

示例4: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
protected void doApply(ApiRequest request, IPolicyContext context, CircuitBreakerConfigBean config,
        IPolicyChain<ApiRequest> chain) {
    CircuitKey ckey = new CircuitKey(request.getApiOrgId(), request.getApiId(), request.getApiVersion());
    Circuit circuit = circuits.get(ckey);
    if (circuit == null) {
        circuit = new Circuit(config.getLimit(), config.getWindow(), config.getReset());
        circuits.put(ckey, circuit);
    }
    
    context.setAttribute(CircuitBreakerPolicy.class.getName() + ".circuit", circuit); //$NON-NLS-1$

    // Is the circuit broken?  If so, either immediately send a failure, or else
    // if the circuit is ready to be reset (the reset time has elapsed) then try
    // to reset the circuit by letting through the request and seeing what happens.
    if (circuit.isBroken()) {
        // Can the circuit possibly be reset?  If so, try...otherwise fail.
        if (circuit.isResettable()) {
            circuit.startReset();
            super.doApply(request, context, config, chain);
        } else {
            IPolicyFailureFactoryComponent failureFactory = context.getComponent(IPolicyFailureFactoryComponent.class);
            PolicyFailure failure = failureFactory.createFailure(PolicyFailureType.Other, BROKEN_CIRCUIT_FAILURE_CODE, "Circuit broken."); //$NON-NLS-1$
            failure.setResponseCode(config.getFailureCode());
            chain.doFailure(failure);
        }
    } else {
        super.doApply(request, context, config, chain);
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:34,代码来源:CircuitBreakerPolicy.java

示例5: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
protected void doApply(ApiRequest request, IPolicyContext context, LogHeadersConfigBean config,
        IPolicyChain<ApiRequest> chain) {
    IApimanLogger logger = context.getLogger(getClass());
    String endpoint = request.getApi().getEndpoint();
    context.setAttribute(ENDPOINT_ATTRIBUTE, endpoint);
    if (config.isLogHeaders() && config.getDirection() != LogHeadersDirectionType.response) {
        logHeaders(logger, request.getHeaders(), HttpDirection.REQUEST, endpoint);
    }
    chain.doApply(request);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:15,代码来源:LogHeadersPolicy.java

示例6: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
@Override
protected void doApply(ApiRequest request, IPolicyContext context, JsonpConfigBean config,
        IPolicyChain<ApiRequest> chain) {
    String callbackParamName = config.getCallbackParamName();
    String callbackFunctionName = request.getQueryParams().get(callbackParamName);
    request.getQueryParams().remove(callbackParamName);
    if (callbackFunctionName != null) {
        context.setAttribute(CALLBACK_FUNCTION_NAME, callbackFunctionName);
    }
    super.doApply(request, context, config, chain);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:12,代码来源:JsonpPolicy.java

示例7: extractRoles

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @param connection
 * @param username
 * @param context
 * @param config
 * @param handler
 */
protected void extractRoles(final IJdbcConnection connection, final String username,
        final IPolicyContext context, final JDBCIdentitySource config,
        final IAsyncResultHandler<Boolean> handler) {
    
    String roleQuery = config.getRoleQuery();
    IAsyncResultHandler<IJdbcResultSet> roleHandler = new IAsyncResultHandler<IJdbcResultSet>() {
        @Override
        public void handle(IAsyncResult<IJdbcResultSet> result) {
            if (result.isError()) {
                closeQuietly(connection);
                handler.handle(AsyncResultImpl.create(result.getError(), Boolean.class));
            } else {
                Set<String> extractedRoles = new HashSet<>();
                IJdbcResultSet resultSet = result.getResult();
                while (resultSet.next()) {
                    String roleName = resultSet.getString(1);
                    extractedRoles.add(roleName);
                }
                context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, extractedRoles);
                closeQuietly(connection);
                handler.handle(AsyncResultImpl.create(true));
            }
        }
    };
    connection.query(roleHandler, roleQuery, username);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:34,代码来源:JDBCIdentityValidator.java

示例8: requestDataHandler

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policies.AbstractMappedDataPolicy#requestDataHandler(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
protected IReadWriteStream<ApiRequest> requestDataHandler(final ApiRequest request,
        final IPolicyContext context, final TransferQuotaConfig config) {
    // *************************************************************
    // Step 2:  if upload quotas are enabled, then count all bytes
    //          uploaded to the back-end API
    // *************************************************************
    if (config.getDirection() == TransferDirectionType.upload || config.getDirection() == TransferDirectionType.both) {
        return new AbstractStream<ApiRequest>() {
            private long total = 0;
            @Override
            public ApiRequest getHead() {
                return request;
            }
            @Override
            protected void handleHead(ApiRequest head) {
            }
            @Override
            public void write(IApimanBuffer chunk) {
                total += chunk.length();
                super.write(chunk);
            }
            @Override
            public void end() {
                context.setAttribute(BYTES_UPLOADED_ATTR, total);
                super.end();
            }
        };
    } else {
        return null;
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:36,代码来源:TransferQuotaPolicy.java

示例9: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * If the request is cached an {@link IConnectorInterceptor} is set in order to prevent the back-end connection to be established.
 * Otherwise an empty {@link CachedResponse} will be added to the context, this will be used to cache the response once it has been
 * received from the back-end API
 *
 * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
protected void doApply(final ApiRequest request, final IPolicyContext context, final CachingConfig config,
        final IPolicyChain<ApiRequest> chain) {
    if (config.getTtl() > 0) {
        // Check to see if there is a cache entry for this request.  If so, we need to
        // short-circuit the connector factory by providing a connector interceptor
        String cacheId = buildCacheID(request);
        context.setAttribute(CACHE_ID_ATTR, cacheId);
        ICacheStoreComponent cache = context.getComponent(ICacheStoreComponent.class);
        cache.getBinary(cacheId, ApiResponse.class,
                new IAsyncResultHandler<ISignalReadStream<ApiResponse>>() {
                    @Override
                    public void handle(IAsyncResult<ISignalReadStream<ApiResponse>> result) {
                        if (result.isError()) {
                            chain.throwError(result.getError());
                        } else {
                            ISignalReadStream<ApiResponse> cacheEntry = result.getResult();
                            if (cacheEntry != null) {
                                context.setConnectorInterceptor(new CacheConnectorInterceptor(cacheEntry));
                                context.setAttribute(SHOULD_CACHE_ATTR, Boolean.FALSE);
                                context.setAttribute(CACHED_RESPONSE, cacheEntry.getHead());
                            }
                            chain.doApply(request);
                        }
                    }
                });
    } else {
        context.setAttribute(SHOULD_CACHE_ATTR, Boolean.FALSE);
        chain.doApply(request);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:39,代码来源:CachingPolicy.java

示例10: apply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
 */
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config,
        final IPolicyChain<ApiRequest> chain) {
    context.setAttribute("X-Conversation-Success", "true");
    chain.doApply(request);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:10,代码来源:SimpleConversationPolicy.java

示例11: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * See {@link AbstractMappedPolicy#doApply(ApiResponse, IPolicyContext, Object, IPolicyChain)}
 */
@Override
protected void doApply(ApiRequest request, IPolicyContext context, CookieValidateConfigBean config,
                       IPolicyChain<ApiRequest> chain) {

    // skip if path matcher is not use, or request URL doesn't match
    if (null == pathMatcher || !pathMatcher.matcher(request.getDestination()).matches()) {
        LOGGER.debug(MESSAGES.format("PathMatchFalse"));

        context.setAttribute(ATTRIBUTE_SKIP, true);
        chain.doApply(request);
        return;
    }

    // check validation
    final ValidationType validationType = config.getValidationType();
    if (ValidationType.NoValidation.equals(validationType)) {
        // no validation - continue request to back-end
        LOGGER.debug(MESSAGES.format("NoValidation"));
        chain.doApply(request);

    } else if (ValidationType.ValidationRequired.equals(validationType) || ValidationType.ValidationOptional.equals(validationType)) {
        // validate the session
        LOGGER.debug(MESSAGES.format("AttemptingValidation"));

        final Cookie cookie = CookieUtil.getCookie(request, config.getCookieName());
        if (null != cookie && !StringUtils.isEmpty(cookie.getValue())) {
            // the cookie value is the session ID
            validateSession(request, context, config, chain, cookie.getValue(), validationType);

        } else {
            if (ValidationType.ValidationOptional.equals(validationType)) {
                // permit absent cookie - continue request to back-end
                LOGGER.info(MESSAGES.format("ValidationOptional.CookieAbsent", config.getCookieName()));
                chain.doApply(request);

            } else {
                // policy failure - cookie is absent or empty
                LOGGER.warn(MESSAGES.format("ValidationRequired.CookieAbsent", config.getCookieName()));
                chain.doFailure(new PolicyFailure(PolicyFailureType.Authentication,
                        HttpURLConnection.HTTP_UNAUTHORIZED, Constants.GENERIC_AUTH_FAILURE));
            }
        }

    } else {
        chain.throwError(new UnsupportedOperationException(
                MESSAGES.format("UnsupportedValidationType", validationType)));
    }
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:52,代码来源:CookieValidatePolicy.java

示例12: doApply

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
/**
 * See {@link AbstractMappedPolicy#doApply(ApiResponse, IPolicyContext, Object, IPolicyChain)}
 */
@Override
protected void doApply(ApiRequest request, IPolicyContext context, final CookieRemoveConfigBean config,
                       IPolicyChain<ApiRequest> chain) {

    // skip if path matcher is not use, or request URL doesn't match
    if (null == pathMatcher || !pathMatcher.matcher(request.getDestination()).matches()) {
        LOGGER.debug(MESSAGES.format("PathMatchFalse"));

        context.setAttribute(ATTRIBUTE_SKIP, true);
        chain.doApply(request);
        return;
    }

    Cookie cookie = CookieUtil.getCookie(request, config.getCookieName());

    // cookie is absent - force removal anyway?
    if (null == cookie && config.getForceCookieRemoval()) {
        LOGGER.warn(MESSAGES.format("CookieAbsentForceRemoval", config.getCookieName()));
        cookie = new Cookie(config.getCookieName(), "");
    }

    if (null == cookie) {
        // cookie is absent - continue
        LOGGER.warn(MESSAGES.format("CookieAbsentSkipRemoval", config.getCookieName()));
        doContinue(request, context, config, chain);

    } else {
        // mark cookie for removal
        context.setAttribute(ATTRIBUTE_REMOVE_COOKIE, cookie);

        final String sessionId = cookie.getValue();
        if (StringUtils.isEmpty(sessionId)) {
            // cookie is empty - continue
            LOGGER.warn(MESSAGES.format("CookieEmpty", config.getCookieName()));
            doContinue(request, context, config, chain);

        } else {
            if (config.getInvalidateSession()) {
                LOGGER.debug(MESSAGES.format("AttemptingInvalidation", sessionId));
                invalidateSession(sessionId, request, context, chain, config);

            } else {
                LOGGER.debug(MESSAGES.format("InvalidationDisabled", sessionId));

                // continue
                doContinue(request, context, config, chain);
            }
        }
    }
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:54,代码来源:CookieRemovePolicy.java

示例13: setResponseHeaders

import io.apiman.gateway.engine.policy.IPolicyContext; //导入方法依赖的package包/类
private void setResponseHeaders(IPolicyContext context, CaseInsensitiveStringMultiMap response) {
    context.setAttribute(CORS_SIMPLE_RESPONSE_HEADERS, response);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:4,代码来源:CorsPolicy.java


注:本文中的io.apiman.gateway.engine.policy.IPolicyContext.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。