【发布时间】:2018-05-30 16:05:02
【问题描述】:
升级到 V2 端点后,我使用 @peerAuthenticator 的 API 无法验证对等方。我使用@Authenticator 进行了测试,遇到了同样的问题,忽略了执行。
我创建了一个repository on GitHub 来测试一个空的应用程序。
仓库是通过google documentation的步骤创建的。
-
运行应用程序
mvn appengine:run后,您可以请求 3 个端点:- http://localhost:8080/_ah/api/myapi/v1/firstApiMethod(没有任何身份验证)
-
http://localhost:8080/_ah/api/myapi/v1/b(与
@authenticator) -
http://localhost:8080/_ah/api/myapi/v1/c(与
@peerAuthenticator)
-
API
@Api(name = "myapi", version = "v1") public class YourFirstAPI { @ApiMethod(name = "firstApiMethod", path = "firstApiMethod", httpMethod = HttpMethod.GET) public TestObject a() { return new TestObject(); } @ApiMethod(name = "b", path = "b", httpMethod = HttpMethod.GET, authenticators = {Authenticator.class}) public TestObject b() { return new TestObject(); } @ApiMethod(name = "c", path = "c", httpMethod = HttpMethod.GET, peerAuthenticators = PeerAuthenticator.class) public TestObject c() { return new TestObject(); } } -
验证器
public class Authenticator implements com.google.api.server.spi.config.Authenticator { @Override public User authenticate(HttpServletRequest arg0) throws ServiceException { throw new ServiceException(401, "unauthorized"); } } -
对等验证器
public class PeerAuthenticator implements com.google.api.server.spi.config.PeerAuthenticator{ @Override public boolean authenticate(HttpServletRequest arg0) { // TODO Auto-generated method stub return true; } }
有人遇到过同样的问题吗?有什么解决方案吗?
【问题讨论】:
标签: java google-app-engine authentication google-cloud-endpoints-v2