Authenticator和PeerAuthenticator不工作的Appengine端点

时间:2018-05-30 16:05:03

标签: java google-app-engine authentication google-cloud-endpoints-v2

升级到V2端点后,使用@peerAuthenticator的API无法验证对等端。我使用@Authenticator进行了测试并遇到了同样的问题,忽略了执行。

我创建了一个repository on GitHub来测试一个空的应用程序。

存储库是通过google documentation

的步骤创建的
  • 运行应用mvn appengine:run后,您可以请求3个端点:

  • 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");
        }
    
    }
    
  • PeerAuthenticator

    public class PeerAuthenticator implements com.google.api.server.spi.config.PeerAuthenticator{
    
        @Override
        public boolean authenticate(HttpServletRequest arg0) {
            // TODO Auto-generated method stub
            return true;
        }
    
    }   
    

有没有人有同样的问题?任何解决方案?

1 个答案:

答案 0 :(得分:0)

您未在@Api@ApiMethod注释中设置身份验证器或对等身份验证器。请参阅the Javadoc