【发布时间】:2014-01-09 13:43:32
【问题描述】:
我正在开发云端点后端,并希望将某些操作限制为管理员用户。
我当前的代码是这样工作的:
@ApiMethod(httpMethod = "PATCH", name = "item.update", path = "items")
public Item update(Item newObject, User user)
throws UnauthorizedException, OAuthRequestException {
OAuthService oAuthService = OAuthServiceFactory.getOAuthService();
if (!oAuthService.isUserAdmin()) {
throw new UnauthorizedException("Only admin users can modify content.");
}
...
}
我知道应用引擎有用户角色的概念,但我很好奇 Endpoints 做。我试过使用 OAuthService.isUserAdmin() 调用,但没有 似乎工作得很好,文档有一个很大的旧警告说
注意:您不应将 Endpoints auth 与 auth for 非端点在配置设置一文中描述的 App Engine 网络应用 管理员中的https://developers.google.com/appengine/articles/auth 控制台,您还可以在其中指定用户登录要求 web.xmlhttps://developers.google.com/appengine/docs/java/config/webxml#Security_and_Authentication 文件。该方法不与 Endpoints 一起使用。”
我是否必须自己创建某种授权,使用传递给更新方法的用户对象?有什么想法吗?
【问题讨论】:
标签: java google-app-engine google-cloud-endpoints