【问题标题】:Authenticator and PeerAuthenticator Not working Appengine endpointsAuthenticator 和 PeerAuthenticator 不工作 Appengine 端点
【发布时间】:2018-05-30 16:05:02
【问题描述】:

升级到 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");
        }
    
    }
    
  • 对等验证器

    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


    【解决方案1】:

    您没有在 @Api@ApiMethod 注释中设置您的身份验证器或对等身份验证器。见the Javadoc

    【讨论】:

    • 我在第二个@apiMethod 中设置了身份验证,它使用了一个实现Authenticator 的类。问题是它没有运行我的 Override 方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    相关资源
    最近更新 更多