Dropwizard 扩展@Auth 接口

Dropwizard extend @Auth interface

有人知道如何扩展 dropwizard 界面吗?现在它只有所需的选项,但我需要为 anooted 方法添加权限。

例如:

我有一个用户管理员和一个普通用户。两者都可以进行身份​​验证并到达我的@auth 注释资源。但我想允许一些(不是全部)http 方法请求仅供管理员使用,而禁止普通用户使用。我怎样才能在资源之外做到这一点?像

@Auth(required = true, right="admin", httpMethod="POST") User user)
@Auth(required = true, right="normalUser", httpMethod="GET") User user)
@Auth(required = true, right="masterOfTheuniverse",  httpMethod="*") User user)

由于 Java 不支持注解继承;你不能。

我有一个类似的案例,所以我最终从 dropwizard 复制了相关的 classes 并根据需要进行修改。我合并了 AuthFilter with OAuthCredentialFilter 因为我不需要抽象,并使用了我自己的 class 而不是 Authenticator<C,P>.

注意:我刚刚意识到,他们有 rewritten the @Auth logic using RequestFilters for the next release which looks more flexible and could meet your needs (I might just migrate to that too). The current version (0.8.x) uses Factorys, which you can find at Java8 implementation. Also the Auth annotation 已经不在 master 分支中了。