简体   繁体   中英

How to forward to a wicket page from a spring filter?

I'm doing a framework (using Java, Spring Boot and Apache Wicket) to quick start a website. I want to force the user to change the administrator password at the first start even if the developer is overwriting the default homepage from the framework.

I think the best way to display a form to change the default password is to use a server filter. I created a filter with the @Component annotation and if the password is not changed yet, I'm doing a forward like that:

request.getRequestDispatcher("/changePassword").forward(request, response);

The problem I think is Spring doesn't know this resource and finally, do a 404 error page. Here the log:

2021-08-17 09:30:01.583 DEBUG 23688 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : "FORWARD" dispatch for GET "/changePassword", parameters={}
2021-08-17 09:30:01.590 DEBUG 23688 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [Classpath [META-INF/resources/], Classpath [resources/], Classpath [static/], Classpath [public/], ServletContext [/]]
2021-08-17 09:30:01.593 DEBUG 23688 --- [nio-8080-exec-2] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2021-08-17 09:30:01.593 DEBUG 23688 --- [nio-8080-exec-2] w.c.HttpSessionSecurityContextRepository : Did not store anonymous SecurityContext
2021-08-17 09:30:01.594 DEBUG 23688 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Exiting from "FORWARD" dispatch, status 404

How can I fix this problem?

Thank you.

EDIT

Here the filter:

@Component
@Order(1)
public class ChangeAdminPasswordFilter implements Filter {

    @Autowired
    private SettingService settingService;

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
            throws IOException, ServletException {

        if (!settingService.isAdminPasswordChanged()) {
request.getRequestDispatcher("/changePassword").forward(request, response);
        }

        chain.doFilter(request, response);
    }
}

EDIT 2

Here the code of the Wicket page:

@MountPath("changePassword")
public class ChangeAdminPasswordPage extends WebPage {

    private static final long serialVersionUID = 1L;

    public ChangeAdminPasswordPage() {
    }
}

When you use Wicket along with Spring Boot - the Spring DispatcherServlet handles mappings defined on the controller to route the request to appropriate controller method. However Wicket generated responses are handled by WicketServlet/ WicketFilter ( WicketServlet delegates all of work to WicketFilter). To process a certain url using Wicket it should match the path to which WicketFilter is listening to. You will need to change the WicketFilter to listen to different path than Spring Boot DispatcherServlet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM