j_security_checkログインプロセスを実行するには十分ではないようです。そのため、フォームを j_security_check に送信する代わりに、独自のサーブレットを作成し、プログラムでログインしようとしています。これは機能しますが、制限されたリソースにリダイレクトできません。何が問題なのか誰にも教えてもらえますか? これはprocessRequest私のサーブレットの方法です:-
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String strUsername = request.getParameter("txtusername");
String strPassword = request.getParameter("txtpassword");
if(strUsername == null || strPassword == null || strUsername.equals("") || strPassword.equals(""))
throw new Exception("Username and/or password missing.");
request.login(strUsername, strPassword);
System.out.println("Login succeeded!!");
if(request.isUserInRole(ROLES.ADMIN.getValue())){//enum
System.out.println("Found in Admin Role");
response.sendRedirect("/app/Admin/home.jsf");
}
else if (request.isUserInRole(ROLES.GENERAL.getValue()))
response.sendRedirect("/app/Common/index.jsf");
else //guard
throw new Exception("No role for user " + request.getRemoteUser());
}catch(Exception ex){
//patch work why there needs to be blogger here?
System.out.println("Invalid username and/or password!!");
response.sendRedirect("/app/Common/index.jsf");
}finally {
out.close();
}
}
すべて正常に動作し、「Found in Admin Role」というメッセージも表示されますが、認証後も問題があり、リクエストを他のページにリダイレクトできません。