まず、this Dropwizard Feature exampleとDropwizard Authorizationを確認します。それから、あなたが何をしているのか、あなたが使っているDropwizardのバージョンについてもっと詳しく説明してください。あなたはすでにやっていることを私は推測しているすべての後
、...あなたは、カスタム認可プロバイダを作成する必要があり
?
public class YourCustomAuthorizer implements Authorizer<User> {
@Override
public boolean authorize(User user, String role) {
return user.getName().equals("good-guy") && role.equals("ADMIN");
}
}
あなたのリソースに注釈を付けましたか?
@RolesAllowed("ADMIN")
@GET
public SecretPlan getSecretPlan() {
return dao.findPlanForUser(user);
}
アプリケーションの実行方法に認証クラスと認可クラスを登録しましたか?あなたの認証が前に行われ、okですされている場合は、それが動作するはずです、これを行っている場合は
@Override
public void run(ExampleConfiguration configuration,
Environment environment) {
environment.jersey().register(new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<User>()
.setAuthenticator(new YourCustomAuthenticator())
.setAuthorizer(new YourCustomAuthorizer())
.setRealm("SUPER SECRET STUFF")
.buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
//If you want to use @Auth to inject a custom Principal type into your resource
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class));
}
。あなたはすべての認証/ autorizationなしGETS認可および認証されたユーザのみ投稿を許可したい場合は、あなたがこれを行うことができます:私は、過去に持っていた
// do not add any annotations here and all users without authentication can do this GET @RolesAllowed("ADMIN")
// do not use '@Auth User user' in method params and do not annotate this method with '@Auth' if you want non authenticated users to do the GET
@GET
public SecretPlan getSecretPlan() {
return dao.findPlanForUser(user);
}
//here just authorized useras can do HTTP POSTs
@RolesAllowed("ADMIN")
@GET
public SecretPlan postSecretPlan() {
return dao.findPlanForUser(user);
}
別の問題を、私はANTとIVYと私のアプリケーションを構築していないということでしたMavenと一緒に。それが間違っている場合、これはいくつかの問題を引き起こす可能性があります。あなたの問題が解決されない場合は
は、「それは、助けてください動作しない」よりも多くの情報を提供してください。*
、それ以外の場合は、時代遅れの下に主の答えをレンダリングし、新しい質問してください。ありがとう! – halfer