Search in sources :

Example 31 with ApiMethodConfig

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

the class ApiConfigValidator method validateBackendMethodNameUnique.

private void validateBackendMethodNameUnique(ApiMethodConfig methodConfig, Map<String, ApiMethodConfig> javaMethodNames) throws OverloadedMethodException {
    String javaName = methodConfig.getFullJavaName();
    ApiMethodConfig seenMethod = javaMethodNames.get(javaName);
    if (seenMethod == null) {
        javaMethodNames.put(javaName, methodConfig);
    } else {
        throw new OverloadedMethodException(methodConfig.getApiClassConfig(), javaName, methodConfig.getName(), seenMethod.getName());
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig)

Example 32 with ApiMethodConfig

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

the class ServletRequestParamReaderTest method testAppEngineUserInjectionThrowsExceptionIfRequired.

@Test
public void testAppEngineUserInjectionThrowsExceptionIfRequired() throws Exception {
    @SuppressWarnings("unused")
    class TestUser {

        @SuppressWarnings("unused")
        public void getUser(com.google.appengine.api.users.User user) {
        }
    }
    ApiMethodConfig methodConfig = Mockito.mock(ApiMethodConfig.class);
    when(methodConfig.getAuthLevel()).thenReturn(AuthLevel.REQUIRED);
    methodConfig.setAuthLevel(AuthLevel.REQUIRED);
    try {
        Method method = TestUser.class.getDeclaredMethod("getUser", com.google.appengine.api.users.User.class);
        readParameters("{}", EndpointMethod.create(method.getDeclaringClass(), method), methodConfig, null, null);
        fail("expected unauthorized method exception");
    } catch (UnauthorizedException ex) {
    // expected
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) User(com.google.api.server.spi.auth.common.User) UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) Method(java.lang.reflect.Method) EndpointMethod(com.google.api.server.spi.EndpointMethod) Test(org.junit.Test)

Example 33 with ApiMethodConfig

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

the class GoogleAppEngineAuthenticator method authenticate.

@Override
public User authenticate(HttpServletRequest request) {
    Attribute attr = Attribute.from(request);
    if (!EnvUtil.isRunningOnAppEngine()) {
        return null;
    }
    com.google.appengine.api.users.User appEngineUser = null;
    ApiMethodConfig config = (ApiMethodConfig) attr.get(Attribute.API_METHOD_CONFIG);
    if (!attr.isEnabled(Attribute.SKIP_TOKEN_AUTH)) {
        appEngineUser = getOAuth2User(request, config);
    }
    if (appEngineUser == null && shouldTryCookieAuth(config)) {
        appEngineUser = userService.getCurrentUser();
    }
    if (appEngineUser == null) {
        return null;
    }
    User user = new User(appEngineUser.getEmail());
    if (attr.isEnabled(Attribute.REQUIRE_APPENGINE_USER)) {
        logger.log(Level.INFO, "appEngineUser = {0}", appEngineUser);
        attr.set(Attribute.AUTHENTICATED_APPENGINE_USER, appEngineUser);
    } else {
        logger.log(Level.INFO, "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)

Example 34 with ApiMethodConfig

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

the class SwaggerGenerator method writeApiClass.

private void writeApiClass(ApiConfig apiConfig, Swagger swagger, GenerationContext genCtx) throws ApiConfigException {
    Map<EndpointMethod, ApiMethodConfig> methodConfigs = apiConfig.getApiClassConfig().getMethods();
    for (Map.Entry<EndpointMethod, ApiMethodConfig> methodConfig : methodConfigs.entrySet()) {
        if (!methodConfig.getValue().isIgnored()) {
            ApiMethodConfig config = methodConfig.getValue();
            writeApiMethod(config, apiConfig, swagger, genCtx);
        }
    }
}
Also used : ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) EndpointMethod(com.google.api.server.spi.EndpointMethod) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 35 with ApiMethodConfig

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

the class ApiConfigAnnotationReaderTest method testParameterAnnotations_none.

@Test
public void testParameterAnnotations_none() throws Exception {
    @Api
    class Endpoint {

        @SuppressWarnings("unused")
        public void method(int foo) {
        }
    }
    ApiConfig config = createConfig(Endpoint.class);
    annotationReader.loadEndpointClass(serviceContext, Endpoint.class, config);
    annotationReader.loadEndpointMethods(serviceContext, Endpoint.class, config.getApiClassConfig().getMethods());
    ApiMethodConfig methodConfig = Iterables.getOnlyElement(config.getApiClassConfig().getMethods().values());
    ApiParameterConfig parameterConfig = Iterables.getOnlyElement(methodConfig.getParameterConfigs());
    validateParameter(parameterConfig, null, false, null, int.class, null, int.class);
}
Also used : ApiParameterConfig(com.google.api.server.spi.config.model.ApiParameterConfig) ApiMethodConfig(com.google.api.server.spi.config.model.ApiMethodConfig) 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)

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