私はSpringが初めてで、SpringとTomcatで動的Webアプリケーションを開発していますが、何らかの理由でSpring Security
を使用していません。
ユーザーが既にセッションに参加している ログインページにアクセスできないようにしたい.ここに私のコードがあります:
@Controller
@RequestMapping("/login")
@SessionAttributes("userAuthenticator")
public class LoginController {
@RequestMapping(method = RequestMethod.GET)
public String showLogin(ModelMap model, HttpServletRequest request) {
System.out.println("Current Session: " + request.getSession(false));
if (request.getSession(false) == null) {
System.out.println("This means a new user wants to access the login page");
return "login";
}
else{
//means the user is already in session.So move him to another page say display.jsp
//actually I have done here with some other checking like getUserName() from
the model "UserAuthenticator" and if its again null redirect to login page.
}
今のところ、 elseの部分は忘れてください。最初にブラウザに URL を入力した
とき: ..../AccountCreation/login.htm
コンソール出力:
Current Session: null
This means a new user wants to access the login page
新しいユーザーがページにアクセスしているため、まったく正常に見えます (ログイン ページも表示されます)。
しかし、URLを再入力してもページを更新すると、コンソール出力は次の ようになります。
Current Session: org.apache.catalina.session.StandardSessionFacade@511e0a
そのセッションはどこから来たのですか?
(そのため、他の部分で、ブラウザで「Webページにリダイレクトされたループがあります」と表示されました)
Spring Securityを使用せずに私の目標を達成する方法を誰かに提案できますか?
これは今の私にとって非常に必要です.....
ありがとう...