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