0
我的任務是繼續處理java restlet服務器。Restlet - 如何在創建新用戶後更新驗證者驗證者映射?
我能夠根據需要設置我的路由,特別是有一個用戶資源可以在URL上通過POST調用創建。發生這種情況時,會在數據庫上創建一個新用戶。
從這一點上我希望新用戶能夠進行身份驗證。問題是入站根中的驗證器在開始時加載一次用戶名和密碼。因此,如果創建了新用戶,除非重新啓動服務器,否則他無法進行身份驗證。
必須有一個簡單的方法來處理這個!
這是應用程序:
public class APIServerApplication extends Application {
@Override
public Restlet createInboundRoot(){
//some routers and filter..
//here the verifier is initialized with the current users and passwords:
MapVerifier verifier = new MapVerifier();
//get users and pwd from DB
HashMap<String,String> usrPwdMap = SomeDBClass.getVerifierMap();
for(String uname : usrPwdMap.keySet()){
verifier.getLocalSecrets().put(uname, (usrPwdMap.get(uname)).toCharArray());
}
//..verifier is used to build the authenticator... etc
}
用戶資源看起來像:
public class UserResource extends ServerResource{
@Post
public Representation acceptItem(Representation entity) {
//get the data from the form
//insert the new user in the db
/* TODO: I think i should add something here
to refresh the verifier map!
*/
}
}
我怎麼能刷新驗證地圖?
我同意,爲了生產目的,你應該建立自定義的Restlet Verifier(查看子類以及)查找結果對於來自用戶目錄(數據庫或其他)的每個呼叫。 –
謝謝!我正在研究這個 –