2011-01-07 8 views
2

줄무늬 프레임 워크 질문이 있습니다.줄무늬 - 리디렉션, 만료 세션

이전의 주석 방법에있는 리디렉션 페이지입니까? 같은

뭔가 :

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

답변

1

난 당신이 이런 식으로 뭔가를 시도 할 생각은 :

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을 구현하는 것입니다.

0

흠. 이것은 좋지 않다.

모든 방법의 중복 코드.


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을 각 액션 빈에 사용하는 것은 좋은 생각이 아닙니다. 이를 위해 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; 
    } 

}