2017-10-11 4 views
1

작동하지 않는 원래의 페이지로 리디렉션합니다.나는 개찰구 7.8.0 응용 프로그램을 만들려고하고, 그리고 모든 로그인하기 전에 액세스 원래의 페이지로 페이지 리디렉션을 제외하고 제대로 작동

을 나는 확보에 액세스하려고 할 때마다 페이지에 로그인하지 않아도 SignIn 페이지로 올바르게 리디렉션되지만 일단 로그인하면 원래 페이지 대신 홈페이지로 리디렉션됩니다. 여기

내 응용 프로그램 클래스입니다 :

, 나는 매우 단순화 로그인 페이지 사용하고 로그인하기 위해
public class MyApplication extends AuthenticatedWebApplication { 

    ... 

    @Override 
    public void init() { 
     super.init(); 

     MetaDataRoleAuthorizationStrategy.authorize(HomePage.class, "TEST_ROLE"); 
     MetaDataRoleAuthorizationStrategy.authorize(SecuredPage.class, "TEST_ROLE"); 

     this.mountPage("signin", SignInPage.class); 
     this.mountPage("homepage", HomePage.class); 
     this.mountPage("secured/secured", SecuredPage.class); 
     //this page is secured with annotations 
     this.mountPage("secured/another", AnotherSecuredPage.class); 

     this.getRequestCycleSettings().setGatherExtendedBrowserInfo(true); 
    } 
} 

: 적어도 한 번에 최대한 빨리 로그인 한 것처럼

public class SignInPage extends WebPage { 

    private String username; 
    private String password; 

    private static final long serialVersionUID = 8096706227164750788L; 

    public SignInPage() { 
     this.add(new FeedbackPanel("feedback")); 
     final Form<SignInPage> form = new Form<>("form"); 
     form.add(new TextField<>("username", new PropertyModel<String>(this, "username"))); 
     form.add(new PasswordTextField("password", new PropertyModel<String>(this, "password"))); 
     form.add(new SubmitLink("submit") { 

      private static final long serialVersionUID = 6057698894229534492L; 

      @Override 
      public void onSubmit() { 
       final Session session = SignInPage.this.getSession(); 
       if(session.signIn(SignInPage.this.username, SignInPage.this.password)) { 
        this.continueToOriginalDestination(); 
        setResponsePage(getApplication().getHomePage()); 
       } 
       else { 
        SignInPage.this.error("Bad username/password combo!"); 
       } 
      } 

     }); 
     final WebClientInfo clientInfo = (WebClientInfo) this.getSession().getClientInfo(); 
     this.add(new Label("userAgent", clientInfo.getUserAgent())); 
     this.add(form); 
    } 
} 

을 응용 프로그램을 다시 로그 아웃하면 다시 로그인 할 때마다 원래 페이지로 리다이렉트가 작동합니다.

내가 뭘 잘못하고 있니?

+0

wicket-examples을 더 잘 보시고, 이것을 위해 'mother class for pages'가 필요하지 않습니다 : https://github.com/apache/wicket/blob/master/wicket-auth-roles/src /main/java/org/apache/wicket/authroles/authentication/AuthenticatedWebApplication.java – svenmeier

+0

사실, 나는 이것을 알아 채지 못했습니다! 그리고 그것은 확실히 onConfigure() 메소드가 처음에 호출되지 않는 이유입니다. –

답변

1

추가로 디버깅 한 후에 문제가 발견되었습니다.

내 응용 프로그램의 init()this.getRequestCycleSettings().setGatherExtendedBrowserInfo(true);으로 브라우저 정보를 수집하고 있습니다. SignInPage에서 (WebClientInfo) this.getSession().getClientInfo()으로 전화합니다. 이것은 Wicket이 브라우저 정보를 수집하고 세션이 아직 초기화되지 않았을 때 로그인 페이지의 첫 번째 호출에서 세션에 넣는 중간 페이지로 리디렉션합니다.

이 중간 리디렉션의 결과로 원본 페이지 URL이 손실됩니다. 저에게 Wicket의 버그처럼 보입니다.

내가이 문제를 해결하기 위해 찾을 수있는 유일한 방법은 단순히 요청에서 직접 원료 사용자 에이전트 헤더를 검색하여 WebClientInfo 객체를 대체하는 것입니다, 수동 프로세스를 :

  1. 는에서 this.getRequestCycleSettings().setGatherExtendedBrowserInfo(true);를 제거 응용 프로그램 초기화. SignInPage 클래스에서
  2. , 이제

    final WebRequest webRequest = ((WebRequest)this.getRequest()); 
    this.add(new Label("userAgent", webRequest.getHeader("User-Agent"))); 
    

final WebClientInfo clientInfo = (WebClientInfo) this.getSession().getClientInfo(); 
this.add(new Label("userAgent", clientInfo.getUserAgent())); 

교체가 더 이상 직접 intermidiary 리디렉션 없으며, 원래 페이지로 리디렉션 올바르게 작동합니다.