user3761498
user3761498

Reputation: 25

Wicket ignores 302 redirect from Spring

I have an Angular + spring REST and Wicket hybrid application. Wicket serves a UserPage class. This UserPage contains my javascript page.

public class UserPage extends WebPage {

public UserPage() {
    super();
}

@Override
public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    response.render(JavaScriptHeaderItem.forUrl("https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"));
    response.render(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(UserPage.class, "user.js")));
    response.render(CssHeaderItem.forReference(new CssResourceReference(UserPage.class, "user.css")));
}

I have implemented a Filter to check if a session is active, if this is not the case, the page should redirect.

WicketSession s = WicketSession.get();

if (s == null) {
    response.sendRedirect("/");
} else if (s.getUser() == null) {
    response.sendRedirect("/");
} else {
    filterChain.doFilter(request, response);
}

However, when i run this page without logging in, the browser receives 302 but does not redirect. This only happens when the page is served through wicket. If i manually go to UserPage.html, it does redirect.

Anyone know anyway why this is happening? It surely is wicket speficic, and im not that familiar with wicket yet.

When trying to reach /user, the page stays, and the html body is send as response data, which my script tries to parse and fails (hence all the empty checkboxes)

When manually going to UserPage.html, it does redirect. enter image description here

Does anyone know why wicket does not redirect when its being sent a 302? Any clues on a possible fix?

Upvotes: 0

Views: 291

Answers (1)

martin-g
martin-g

Reputation: 17533

1) If you keep the session data in WicketSession then it should be before Spring's Filter/Servlet in web.xml.

I would suggest to keep the user in Spring Security Authentication if you use it.

2) WicketSession.get() never returns null. It acts as "get or create". You need if (WicketSession.exists()) {...} instead.

Upvotes: 1

Related Questions