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());
}
}
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
}
}
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;
}
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);
}
}
}
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);
}
Aggregations