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


Java ApiRequest.setApiKey方法代码示例

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


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

示例1: readRequest

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
 * Reads a {@link ApiRequest} from information found in the inbound
 * portion of the http request.
 * @param request the undertow http server request
 * @return a valid {@link ApiRequest}
 * @throws IOException
 */
protected ApiRequest readRequest(HttpServletRequest request) throws Exception {
    ApiRequestPathInfo pathInfo = getEngine().getApiRequestPathParser().parseEndpoint(request.getPathInfo(), wrapMultiMap(request));//parseApiRequestPath(request);
    if (pathInfo.orgId == null) {
        throw new Exception(Messages.i18n.format("GatewayServlet.InvalidApiEndpoint")); //$NON-NLS-1$
    }
    QueryMap queryParams = parseApiRequestQueryParams(request.getQueryString());

    String apiKey = getApiKey(request, queryParams);

    ApiRequest srequest = GatewayThreadContext.getApiRequest();
    srequest.setApiKey(apiKey);
    srequest.setApiOrgId(pathInfo.orgId);
    srequest.setApiId(pathInfo.apiId);
    srequest.setApiVersion(pathInfo.apiVersion);
    srequest.setUrl(request.getRequestURL().toString());
    srequest.setDestination(pathInfo.resource);
    srequest.setQueryParams(queryParams);
    readHeaders(srequest, request);
    srequest.setRawRequest(request);
    srequest.setRemoteAddr(request.getRemoteAddr());
    srequest.setTransportSecure(request.isSecure());
    return srequest;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:31,代码来源:GatewayServlet.java

示例2: testApplyJdbcWithRoles

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
public void testApplyJdbcWithRoles(String json) throws Exception {
    // A live LDAP server is required to run this test!
    BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy();
    BasicAuthenticationConfig config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    Mockito.when(context.getComponent(IJdbcComponent.class)).thenReturn(new DefaultJdbcComponent());
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);

    // Success
    request.getHeaders().put("Authorization", createBasicAuthorization(JDBC_USER, JDBC_PASSWORD));
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);
    Set<String> expectedRoles = new HashSet<>();
    expectedRoles.add("admin");
    expectedRoles.add("user");
    Mockito.verify(context).setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, expectedRoles);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:24,代码来源:BasicAuthJDBCTest.java

示例3: buildRequest

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
public static ApiRequest buildRequest(HttpServerRequest req, boolean isTransportSecure) {
    ApiRequest apimanRequest = new ApiRequest();
    apimanRequest.setApiKey(parseApiKey(req));
    apimanRequest.setRemoteAddr(req.remoteAddress().host());
    apimanRequest.setType(req.method().toString());
    apimanRequest.setTransportSecure(isTransportSecure);
    multimapToMap(apimanRequest.getHeaders(), req.headers(), IGNORESET);
    multimapToMap(apimanRequest.getQueryParams(), req.params(), Collections.<String>emptySet());
    parsePath(req, apimanRequest);
    return apimanRequest;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:12,代码来源:HttpApiFactory.java

示例4: requestWithVerb

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
private ApiRequest requestWithVerb(IPolicyChain<ApiRequest> chain, String verb)
        throws IOException, JsonGenerationException, JsonMappingException
{
    IgnoredResourcesPolicy policy = new IgnoredResourcesPolicy();
    IgnoredResourcesConfig configObj = new IgnoredResourcesConfig();
    ArrayList<IgnoredResource> elements = new ArrayList<>(2);

    elements.add(createResource(verb, firstPath));
    elements.add(createResource(verb, secondPath));
    configObj.setRules(elements);
    String json = mapper.writeValueAsString(configObj);
    Object config = policy.parseConfiguration(json);

    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/invoices/1");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    createFailurePolicyObject(context);

    // Success
    policy.apply(request, context, config, chain);

    // Fail
    request.setDestination("/invoices/23/items/43");
    policy.apply(request, context, config, chain);

    // Fail
    request.setDestination("/items/43");
    policy.apply(request, context, config, chain);
    return request;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:34,代码来源:IgnoredResourcesPolicyTest.java

示例5: testApply

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
 * Test method for {@link io.apiman.gateway.engine.policies.IPWhitelistPolicy#parseConfiguration(java.lang.String)}.
 */
@Test
public void testApply() {
    IPWhitelistPolicy policy = new IPWhitelistPolicy();
    String json = "{" +
            "  \"ipList\" : [" +
            "    \"1.2.3.4\"," +
            "    \"3.4.5.6\"," +
            "    \"10.0.0.11\"" +
            "  ]" +
            "}";
    Object config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);

    // Success
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);

    // Failure
    final PolicyFailure failure = new PolicyFailure();
    Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
        @Override
        public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
            return failure;
        }
    });
    chain = Mockito.mock(IPolicyChain.class);
    request.setRemoteAddr("9.8.7.6");
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:40,代码来源:IPWhitelistPolicyTest.java

示例6: testApplyWithWildcards

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
 * Test method for {@link io.apiman.gateway.engine.policies.IPWhitelistPolicy#parseConfiguration(java.lang.String)}.
 */
@Test
public void testApplyWithWildcards() {
    IPWhitelistPolicy policy = new IPWhitelistPolicy();
    String json = "{" +
            "  \"ipList\" : [" +
            "    \"10.0.*.*\"" +
            "  ]" +
            "}";
    Object config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);

    // Success
    request.setRemoteAddr("10.0.87.33");
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);

    request.setRemoteAddr("10.0.12.19");
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);

    // Failure
    final PolicyFailure failure = new PolicyFailure();
    Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
        @Override
        public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
            return failure;
        }
    });
    chain = Mockito.mock(IPolicyChain.class);
    request.setRemoteAddr("9.8.7.6");
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:43,代码来源:IPWhitelistPolicyTest.java

示例7: testApply

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
 * Test method for {@link io.apiman.gateway.engine.policies.RateLimitingPolicy#parseConfiguration(java.lang.String)}.
 */
@Test
public void testApply() {
    RateLimitingPolicy policy = new RateLimitingPolicy();
    String json = "{\r\n" +
            "  \"limit\" : 10,\r\n" +
            "  \"granularity\" : \"User\",\r\n" +
            "  \"period\" : \"Minute\",\r\n" +
            "  \"userHeader\" : \"X-Identity\"\r\n" +
            "}";
    Object config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setContract(createTestContract());
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/");
    request.getHeaders().put("X-Identity", "sclause"); //$NON-NLS-2$
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    final PolicyFailure failure = new PolicyFailure();
    Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
        @Override
        public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
            return failure;
        }
    });
    Mockito.when(context.getComponent(IRateLimiterComponent.class)).thenReturn(new InMemoryRateLimiterComponent());
    IPolicyChain<ApiRequest> chain;

    for (int count = 0; count < 10; count++) {
        chain = Mockito.mock(IPolicyChain.class);
        policy.apply(request, context, config, chain);
        Mockito.verify(chain).doApply(request);
    }

    // Failure - only allow 10 per minute!
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:43,代码来源:RateLimitingPolicyTest.java

示例8: testApply

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
 * Test method for {@link io.apiman.gateway.engine.policies.IPBlacklistPolicy#parseConfiguration(java.lang.String)}.
 */
@Test
public void testApply() {
    IPBlacklistPolicy policy = new IPBlacklistPolicy();
    String json = "{" + 
            "  \"ipList\" : [" + 
            "    \"1.2.3.4\"," + 
            "    \"3.4.5.6\"," + 
            "    \"10.0.0.11\"" + 
            "  ]" + 
            "}";
    IPListConfig config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    final PolicyFailure failure = new PolicyFailure();
    Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
        @Override
        public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
            return failure;
        }
    });
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
    
    // Failure
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);
    
    // Success
    request.setRemoteAddr("9.8.7.6");
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:40,代码来源:IPBlacklistPolicyTest.java

示例9: testApplyJdbcNoRoles

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
 * @param json
 * @throws Exception
 */
public void testApplyJdbcNoRoles(String json) throws Exception {
    // A live LDAP server is required to run this test!
    BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy();
    BasicAuthenticationConfig config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    final PolicyFailure failure = new PolicyFailure();
    Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
        @Override
        public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
            return failure;
        }
    });
    Mockito.when(context.getComponent(IJdbcComponent.class)).thenReturn(new DefaultJdbcComponent());
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);

    // Failure
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);

    // Failure
    request.getHeaders().put("Authorization", createBasicAuthorization(JDBC_USER, "invalid_password"));
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);

    // Success
    request.getHeaders().put("Authorization", createBasicAuthorization(JDBC_USER, JDBC_PASSWORD));
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:41,代码来源:BasicAuthJDBCTest.java

示例10: testApply

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
@Test
public void testApply() throws Exception {
    IgnoredResourcesPolicy policy = new IgnoredResourcesPolicy();
    IgnoredResourcesConfig configObj = new IgnoredResourcesConfig();
    ArrayList<IgnoredResource> elements = new ArrayList<>(2);
    elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, firstPath));
    elements.add(createResource(IgnoredResource.VERB_MATCH_ALL, secondPath));
    configObj.setRules(elements);
    String json = mapper.writeValueAsString(configObj);
    Object config = policy.parseConfiguration(json);

    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/invoices/1");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);

    // Success
    policy.apply(request, context, config, chain);

    // Success
    request.setDestination("/invoices");
    policy.apply(request, context, config, chain);

    // Success
    request.setDestination("/invoices/items");
    policy.apply(request, context, config, chain);

    // Success
    request.setDestination("/invoices/items/13");
    policy.apply(request, context, config, chain);
    Mockito.verify(chain, Mockito.times(4)).doApply(request);
    Mockito.verify(chain, Mockito.never()).doFailure(Mockito.<PolicyFailure> any());

    final PolicyFailure failure = createFailurePolicyObject(context);
    chain = Mockito.mock(IPolicyChain.class);
    request.setDestination("/invoices/23/items/43");
    policy.apply(request, context, config, chain);

    // Failure
    request.setDestination("/items/43");
    policy.apply(request, context, config, chain);
    Mockito.verify(chain, Mockito.times(2)).doFailure(failure);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:47,代码来源:IgnoredResourcesPolicyTest.java

示例11: testApply

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
public void testApply() throws Exception {
    TimeRestrictedAccessPolicy policy = new TimeRestrictedAccessPolicy();

    ApiRequest request = new ApiRequest();
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination(path);
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
    final PolicyFailure failure = createFailurePolicyObject(context);

    TimeRestrictedAccess rule = new TimeRestrictedAccess();
    ArrayList<TimeRestrictedAccess> elements = new ArrayList<>(2);
    TimeRestrictedAccessConfig configObj = new TimeRestrictedAccessConfig();
    elements.add(rule);
    configObj.setRules(elements);

    int dayOfWeek = new DateTime().getDayOfWeek();
    rule.setDayEnd(7);
    rule.setDayStart(dayOfWeek);
    rule.setTimeEnd(new DateTime().plusHours(2).toDate());
    rule.setTimeStart(new DateTime().minusHours(2).toDate());
    rule.setPathPattern("PathNotListed");
    configObj.setRules(elements);
    Object config = updateConfig(policy, configObj);

    // Successful requests
    policy.apply(request, context, config, chain);
    rule.setPathPattern(path);
    config = updateConfig(policy, configObj);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain, Mockito.times(2)).doApply(request);
    Mockito.verify(chain, Mockito.never()).doFailure(Mockito.<PolicyFailure> any());

    chain = Mockito.mock(IPolicyChain.class);

    // Failed requests
    rule.setDayEnd(dayOfWeek + 1);
    rule.setDayStart(dayOfWeek - 1);
    rule.setPathPattern(path);
    rule.setTimeEnd(new DateTime().plusHours(1).toDate());
    rule.setTimeStart(new Date());
    request.setDestination(path);
    config = updateConfig(policy, configObj);

    policy.apply(request, context, config, chain);

    rule.setDayEnd(1);
    rule.setDayStart(7);
    rule.setTimeEnd(new DateTime().plusHours(2).toDate());
    rule.setTimeStart(new DateTime().plusHours(1).toDate());
    config = updateConfig(policy, configObj);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain, Mockito.times(2)).doFailure(failure);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:56,代码来源:TimeRestrictedAccessPolicyTest.java

示例12: testApplyWithWildcards

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
/**
 * Test method for {@link io.apiman.gateway.engine.policies.IPBlacklistPolicy#parseConfiguration(java.lang.String)}.
 */
@Test
public void testApplyWithWildcards() {
    IPBlacklistPolicy policy = new IPBlacklistPolicy();
    String json = "{" + 
            "  \"ipList\" : [" + 
            "    \"10.0.*.*\"" + 
            "  ]" + 
            "}";
    IPListConfig config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    final PolicyFailure failure = new PolicyFailure();
    Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
        @Override
        public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
            return failure;
        }
    });
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);
    
    // Failures
    request.setRemoteAddr("10.0.123.87");
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);

    request.setRemoteAddr("10.0.97.1");
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doFailure(failure);

    // Successes
    request.setRemoteAddr("9.8.7.6");
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);

    request.setRemoteAddr("10.10.15.123");
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);

}
 
开发者ID:apiman,项目名称:apiman,代码行数:49,代码来源:IPBlacklistPolicyTest.java

示例13: doTest

import io.apiman.gateway.engine.beans.ApiRequest; //导入方法依赖的package包/类
private void doTest(String json, String username, String password, Integer expectedFailureCode,
        Set<String> expectedRoles) throws Exception {
    BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy();
    BasicAuthenticationConfig config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    final PolicyFailure failure = new PolicyFailure();
    Mockito.when(context.getComponent(IPolicyFailureFactoryComponent.class)).thenReturn(new IPolicyFailureFactoryComponent() {
        @Override
        public PolicyFailure createFailure(PolicyFailureType type, int failureCode, String message) {
            failure.setType(type);
            failure.setFailureCode(failureCode);
            failure.setMessage(message);
            return failure;
        }
    });

    // The LDAP stuff we're testing!
    Mockito.when(context.getComponent(ILdapComponent.class)).thenReturn(new DefaultLdapComponent());

    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);

    if (username != null) {
        request.getHeaders().put("Authorization", createBasicAuthorization(username, password));
    }

    if (expectedFailureCode == null) {
        policy.apply(request, context, config, chain);
        Mockito.verify(chain).doApply(request);
    } else {
        policy.apply(request, context, config, chain);
        Mockito.verify(chain).doFailure(failure);
        Assert.assertEquals(expectedFailureCode.intValue(), failure.getFailureCode());
    }

    if (expectedRoles != null && expectedFailureCode == null) {
        Mockito.verify(context).setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, expectedRoles);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:44,代码来源:BasicAuthLDAPTest.java


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