Search in sources :

Example 16 with ApiMethodConfig

use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.

the class ApiConfigAnnotationReaderTest method testDuplicateMethodEndpoint.

@Test
public void testDuplicateMethodEndpoint() throws Exception {
    ApiConfig config = createConfig(DuplicateMethodEndpoint.class);
    annotationReader.loadEndpointMethods(serviceContext, DuplicateMethodEndpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig method1 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(DuplicateMethodEndpoint.class.getMethod("foo", String.class)));
    assertEquals("api.foos.fn1", method1.getName());
    ApiMethodConfig method2 = config.getApiClassConfig().getMethods().get(methodToEndpointMethod(DuplicateMethodEndpoint.class.getMethod("foo", Integer.class)));
    assertEquals("api.foos.fn2", method2.getName());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) Test(org.junit.Test)

Example 17 with ApiMethodConfig

use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.

the class ApiConfigAnnotationReaderTest method testSuperclassWithoutApi.

@Test
public void testSuperclassWithoutApi() throws Exception {
    @Api
    class Foo {

        @SuppressWarnings("unused")
        public void foo() {
        }
    }
    class Bar extends Foo {

        @ApiMethod(name = "overridden")
        @Override
        public void foo() {
        }
    }
    ApiConfig config = createConfig(Bar.class);
    annotationReader.loadEndpointClass(serviceContext, Bar.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Bar.class, config.getApiClassConfig().getMethods());
    // Make sure method comes from Bar even though that class is not annotated with @Api.
    ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
    assertEquals("overridden", methodConfig.getName());
    assertEquals(Bar.class.getName() + ".foo", methodConfig.getFullJavaName());
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) Foo(com.google.api.server.spi.testing.Foo) ApiConfig(com.google.api.server.spi.config.model.ApiConfig) SimpleLevelOverridingApi(com.google.api.server.spi.testing.SimpleLevelOverridingApi) SimpleLevelOverridingInheritedApi(com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi) Api(com.google.api.server.spi.config.Api) Test(org.junit.Test)

Example 18 with ApiMethodConfig

use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.

the class EndpointsMethodHandlerTest method rootMethodHandler.

@Test
public void rootMethodHandler() throws Exception {
    EndpointMethod method = systemService.resolveService("TestEndpoint", "root");
    ApiMethodConfig methodConfig = new ApiMethodConfig(method, typeLoader, apiConfig.getApiClassConfig());
    methodConfig.setPath("/root");
    TestMethodHandler handler = new TestMethodHandler(ServletInitializationParameters.builder().build(), method, apiConfig, methodConfig, systemService, 200);
    assertThat(handler.getRestPath()).isEqualTo("root");
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 19 with ApiMethodConfig

use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.

the class EndpointsMethodHandlerTest method fail_findService.

@Test
public void fail_findService() throws Exception {
    EndpointMethod method = systemService.resolveService("TestEndpoint", "simple");
    ApiMethodConfig methodConfig = new ApiMethodConfig(method, typeLoader, apiConfig.getApiClassConfig());
    systemService = SystemService.builder().withDefaults(classLoader).addService(ArrayEndpoint.class, new ArrayEndpoint()).build();
    TestMethodHandler handler = new TestMethodHandler(ServletInitializationParameters.builder().build(), method, apiConfig, methodConfig, systemService, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, RESOURCE);
    handler.getRestHandler().handle(context);
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) ArrayEndpoint(com.google.api.server.spi.testing.ArrayEndpoint) Test(org.junit.Test)

Example 20 with ApiMethodConfig

use of com.google.api.server.spi.config.model.ApiMethodConfig in project endpoints-java by cloudendpoints.

the class GoogleJwtAuthenticator method authenticate.

@Override
public User authenticate(HttpServletRequest request) {
    Attribute attr = Attribute.from(request);
    if (attr.isEnabled(Attribute.SKIP_TOKEN_AUTH)) {
        return null;
    }
    String token = GoogleAuth.getAuthToken(request);
    if (!GoogleAuth.isJwt(token)) {
        return null;
    }
    GoogleIdToken idToken = verifyToken(token);
    if (idToken == null) {
        return null;
    }
    String clientId = idToken.getPayload().getAuthorizedParty();
    String audience = (String) idToken.getPayload().getAudience();
    ApiMethodConfig config = (ApiMethodConfig) attr.get(Attribute.API_METHOD_CONFIG);
    // Check client id.
    if ((attr.isEnabled(Attribute.ENABLE_CLIENT_ID_WHITELIST) && !GoogleAuth.checkClientId(clientId, config.getClientIds(), false))) {
        logger.warning("ClientId is not allowed: " + clientId);
        return null;
    }
    // Check audience.
    if (!GoogleAuth.checkAudience(audience, config.getAudiences(), clientId)) {
        logger.warning("Audience is not allowed: " + audience);
        return null;
    }
    String userId = idToken.getPayload().getSubject();
    String email = idToken.getPayload().getEmail();
    User user = (userId == null && email == null) ? null : new User(userId, email);
    if (attr.isEnabled(Attribute.REQUIRE_APPENGINE_USER)) {
        com.google.appengine.api.users.User appEngineUser = (email == null) ? null : new com.google.appengine.api.users.User(email, "");
        attr.set(Attribute.AUTHENTICATED_APPENGINE_USER, appEngineUser);
        logger.log(Level.FINE, "appEngineUser = {0}", appEngineUser);
    } else {
        logger.log(Level.FINE, "user = {0}", user);
    }
    return user;
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) User(com.google.api.server.spi.auth.common.User) Attribute(com.google.api.server.spi.request.Attribute) GoogleIdToken(com.google.api.client.googleapis.auth.oauth2.GoogleIdToken)

Aggregations

ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)54 Test (org.junit.Test)37 ApiConfig (com.google.api.server.spi.config.model.ApiConfig)26 EndpointMethod (com.google.api.server.spi.EndpointMethod)16 SimpleLevelOverridingInheritedApi (com.google.api.server.spi.testing.SimpleLevelOverridingInheritedApi)10 Api (com.google.api.server.spi.config.Api)8 SimpleLevelOverridingApi (com.google.api.server.spi.testing.SimpleLevelOverridingApi)8 User (com.google.api.server.spi.auth.common.User)5 PassAuthenticator (com.google.api.server.spi.testing.PassAuthenticator)5 PassPeerAuthenticator (com.google.api.server.spi.testing.PassPeerAuthenticator)5 ApiParameterConfig (com.google.api.server.spi.config.model.ApiParameterConfig)4 ApiAuthConfig (com.google.api.server.spi.config.model.ApiAuthConfig)3 ApiCacheControlConfig (com.google.api.server.spi.config.model.ApiCacheControlConfig)3 ApiFrontendLimitsConfig (com.google.api.server.spi.config.model.ApiFrontendLimitsConfig)3 Attribute (com.google.api.server.spi.request.Attribute)3 Named (com.google.api.server.spi.config.Named)2 ApiSerializationConfig (com.google.api.server.spi.config.model.ApiSerializationConfig)2 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)2 FailAuthenticator (com.google.api.server.spi.testing.FailAuthenticator)2 FailPeerAuthenticator (com.google.api.server.spi.testing.FailPeerAuthenticator)2