0


spring を使用して Web アプリケーションを開発しています。

ここに問題があります。これらの 3 つの URL があるとします。

www.sample.com/login.do

www.sample.com/homePage.do

www.sample.com/about.jsp

私がやりたいことは、ユーザーがログインしているかどうかにかかわらず、about.jsp ページにアクセスできるようにすることです。また、ユーザーがログインせずに homePage.do にアクセスしようとすると、login.do ページにリダイレクトされ、その逆も同様です。

これが機能するにはHTTPSessionが必要だと思いますが、SpringでHTTPSessionを管理する方法がわかりません。

いくつかのフィルターを使用してこれを達成できますか? もしそうなら、それを通して私を案内してもらえますか?

Spring MVC および/または Spring Annotations を使用したいと考えています。

4

1 に答える 1

2

Spring Securityを使用してください!

あなたの春の設定ファイルは少し似ています

<security:http auto-config="true" use-expressions="true">

  <security:intercept-url pattern="login.do" access="permitAll"/>
  <security:intercept-url pattern="about.jsp" access="permitAll"/>
  <security:intercept-url pattern="homePage.do" access="isAuthenticated"/>

  <security:form-login
    login-page="login.jsp"
    authentication-failure-url="login?error=true"
    default-target-url="homePage.do"/>  
 </security:http>

 <security:authentication-manager>
         ...
 </security:authentication-manager>
于 2011-12-11T14:30:49.553 に答える