我做了自定義驗證的dropwizard Maven項目。我跟着文檔https://github.com/remmelt/dropwizard-oauth2-provider/blob/master/src/main/java/com/remmelt/examples/auth/SimpleAuthenticator.java。但是我得到「憑證需要訪問此資源。」當我運行該項目並從瀏覽器訪問URL時出現此消息。任何幫助將不勝感激。我的代碼是這樣的..得到錯誤「憑據需要」訪問dropwizard OAuth網絡服務
public class ExampleAuthenticator implements Authenticator<String, User>
{
@Override
public Optional<User> authenticate(String arg0)throws AuthenticationException {
// TODO Auto-generated method stub
User u = new User(arg0);
System.out.println("\n\n\nString arg0"+arg0);
return Optional.of(new User(u.getName()));
}
}
和代碼中的資源類
@GET
public String Token(@Auth User user)
{
System.out.println("In UserResource Class in Token Method");
return "Hello...";
}
在應用程序類初始化認證
environment.jersey().register(AuthFactory.binder(new OAuthFactory<User>(new ExampleAuthenticator(),"SUPER SECRET STUFF",User.class)));