當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。