Restlet:检索ServerResource中Digest经过身份验证的用户的用户名

时间:2014-02-02 10:42:55

标签: restlet

在我的REST服务器中,用户使用DigestAuthentication进行身份验证。例如,当用户登录时,他应该看到一些与其用户名相关的条目。

我的问题是,虽然用户成功登录,但当他们访问ServerResource实现时,我不知道访问此类的用户的用户名是什么。

这是我的主要

public class Main extends Application{

    @Override
    public synchronized Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attach("/profile", UserResource.class);
        return router;
    }

    public static void main(String[] args) throws Exception {
        Component component = new Component();
        component.getServers().add(Protocol.HTTP, 8182);

        DigestAuthenticator guard = new DigestAuthenticator(null, testRealm, secretServerKey);

        guard.setWrappedVerifier(new LocalVerifier() {
            @Override
            public char[] getLocalSecret(String arg0) {

                .. return the user's password if it exists.

            }
        });

        guard.setNext(new Main());
        component.getDefaultHost().attach("/protected",guard);

        Engine.getInstance().getRegisteredConverters()
            .add(new JacksonConverter());
        component.start();
    }
}

然后,在Main.createInboundRoot()中提到的ServerResource类中,如何检索已登录用户的用户名?

0 个答案:

没有答案
相关问题