2011-01-07 33 views
2

私はStripesフレームワークの質問をしています。ストライプ - リダイレクト、期限切れセッション

前の注釈方法のリダイレクトページですか?以下のような

何か:

public class MyPageActionBean implements ActionBean { 
    private ActionBeanContext context; 

    public ActionBeanContext getContext() { 
    return context; 
    } 

    public void setContext(ActionBeanContext context) { 
    this.context = context; 
    } 

    @DefaultHandler 
    public Resolution view() { 
    String login = 
     (String)context.getRequest().getSession().getAttribute("login"); 
    if (login==null) { 
     return new RedirectResolution(LoginActionBean.class); 
    } else { 
     // do you're normal stuff here 
    } 
    } 
} 

しかし、より完全なセキュリティソリューションを Stripes Security Interceptorを実装するために、次のようになります。

@Before 
public void test() 
{ 
    String login=(String)context.getRequest().getSession().getAttribute("login"); 
    if (login==null) 
    { 
    Redirect...(LoginActionBean.class); // ?????? 
    exit....();         // ?????? 
    } 
} 

答えて

1

は、私はあなたがこのような何かをしようと思います。

0

hm。これは素晴らしいことではありません。

すべての方法で重複コード。


public Resolution view1() 
{ 
    String login=.... 
    if() {...} 
    else {...} 
} 

public Resolution view2() 
{ 
    String login=.... 
    if() {...} 
    else {...} 
} 
public Resolution view3() 
{ 
    String login=.... 
    if() {...} 
    else {...} 
} 

私はStripes Security Interceptorを読んでいます。

ありがとうございました。

+0

もちろん、独自のインターセプタを作成することもできます。http://www.stripesframework.org/display/stripes/Intercept+Execution(非常に簡単です) – Kdeveloper

0

あなたの問題は、ログインページにログインしていないユーザーをリダイレクトすることです。@beforeを各actionBeanに使用することはお勧めできません。これを実現するには、SpringInterceptorSupportを拡張して独自のインターセプタを作成できます。

@Intercepts(LifecycleStage.ActionBeanResolution) 
public class MyInterceptor extends SpringInterceptorSupport { 
private static final List<Class<? extends ActionBean>> ALLOW = Arrays.asList(LoginActionBean.class, anyOtherActionBeanAllowedWithoutLogin.class); 

@Override 
    @SuppressWarnings({ "rawtypes" }) 
    public Resolution intercept(ExecutionContext execContext) throws Exception { 
    Resolution resolution = execContext.proceed(); 
    ActionBean actionBean = execContext.getActionBean(); 
    Class<? extends ActionBean> destinationclass = actionBean.getClass(); 
    if (!ALLOW.contains(destinationclass) && !isSessionExist()) { 
     resolution = new RedirectResolution(LoginActionBean.class); 
    } 
    return resolution; 

    } 

    private boolean isSessionExist() { 
    String login = (String)context.getRequest().getSession().getAttribute("login"); 
    return login != null; 
    } 

} 
関連する問題