2011-07-20 48 views
0

我有一個應用程序,我想檢查remoteUser是否可用。我如何需要配置tomcat以在本地副本中獲取remoteUser。我正在執行的代碼行如下。對於我的本地代碼庫副本,request.getRemoteUser()總是返回null。任何幫助讚賞。如何獲取request.getRemoteUser()值

if (request.getRemoteUser()!= null){ 
     myBean.setName(nameFromUser); 
} 
+1

你有配置爲您的應用[登錄](http://tomcat.apache.org/tomcat-7.0-doc/realm-howto.html)?如果您未登錄,則遠程用戶將始終爲空。 –

+0

您能否介紹一下如何爲我的應用程序配置登錄名? – mona

回答

0

您需要在容器端編寫一個Valve或Realm,將UserPrincipal設置爲請求。

爲完成here

157 principal = context. getRealm(). authenticate (username, password);
158 if (principal != null) {
159 register (request, response, principal, Constants.BASIC_METHOD,
160 username, password);
161 return (true);
162 }