→詳細設計・アルゴリズムなど

→DI(依存性注入)

→Java関連

#contents

*SAStrutsのアクション全実行メソッドでログイン済みチェックをする [#v35137c6]
 public class LoginCheckInterceptor extends AbstractInterceptor {
 
   private static final long serialVersionUID = 7073242636557446465L;
 
   @Override
   public Object invoke(MethodInvocation arg0) throws Throwable {
     Log.debug("LoginCheckInterceptor.invoke");
     
     if(isExecuteMethod(arg0)){
       if (isLoggedIn()){
         Log.debug("ログインチェック OK.");
         return arg0.proceed();
       }else{
         Log.error("正しくログイン認証されていません。");
         return "/?redirect=true";
       }
     } else 
       return arg0.proceed();
   }
 
   /**
    * @Executeアノテーションがついているか
    * @param invocation
    * @return Executeがついていたらtrue
    */
   boolean isExecuteMethod(MethodInvocation invocation) {
         return invocation.getMethod().
               isAnnotationPresent(Execute.class);
     }
   
   /**
    * ログイン済みかチェック
    * @return ログイン認証されていて、タイムアウトしてなければ true
    */
   private boolean isLoggedIn() {
         HttpSession session =
             (HttpSession) SingletonS2ContainerFactory
                 .getContainer()
                 .getExternalContext()
                 .getSession();
         
         SessionDto dto = (SessionDto) session.getAttribute("sessionDto");
 
         //セッションタイムアウトしてたらnullになるはず
         if(dto==null)
           return false;
         else{
           return dto.isLoggedIn();
         }
 
     }
 }

-customizer.diconの設定
 <component name="actionCustomizer" 
     class="org.seasar.framework.container.customizer.CustomizerChain">
 
   <!-- ログインしているかチェックするインターセプタ -->
   <initMethod name="addCustomizer">
       <arg>
         <component class="org.seasar.framework.container.customizer.AspectCustomizer">
           <!-- プロパティネームの先頭は小文字になる点に注意 -->
           <property name="interceptorName">"loginCheckInterceptor"</property>
           <initMethod name="addIgnoreClassPattern">
             <arg>"approot.action"</arg>
             <arg>"IndexAction"</arg>
           </initMethod>
         </component>
       </arg>
     </initMethod>
 
 </component>

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS