Logout ignoring server.servlet.context-path

Hello,

After upgrading to 2.3 the logout action is ignoring the server.servlet.context-path value and it redirects to / instead of <value_of_server.servlet.context-path>/login.
You can replicate by creating a new project and adding server.servlet.context-path=/demo (or any other value) in the application.properties.
Is there anything I can do to solve it ?
Thanks in advance.

Kind regards,
Radu Mantale

Hi,

Thank you for reporting the problem. I’ve created an issue for this. The issue will be fixed in the next 2.3 patch release.

Until then, you may create the following configuration in your project, that will assign a correct logout URL:

import com.google.common.base.Strings;
import io.jmix.flowui.view.View;
import io.jmix.securityflowui.security.FlowuiVaadinWebSecurity;
import jakarta.servlet.ServletContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.stereotype.Component;

@Component
public class ExtFlowuiVaadinWebSecurity extends FlowuiVaadinWebSecurity {

    private static final Logger log = LoggerFactory.getLogger(ExtFlowuiVaadinWebSecurity.class);

    private ServletContext servletContext;

    @Autowired
    protected void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    @Override
    protected void initLoginView(HttpSecurity http) throws Exception {
        String loginViewId = uiProperties.getLoginViewId();
        if (Strings.isNullOrEmpty(loginViewId)) {
            log.debug("Login view Id is not defined");
            return;
        }
        Class<? extends View<?>> controllerClass =
                viewRegistry.getViewInfo(loginViewId).getControllerClass();
        String contextPath = servletContext.getContextPath();
        if (!contextPath.startsWith("/"))
            contextPath = "/" + contextPath;
        setLoginView(http, controllerClass, contextPath);
    }
}
1 Like

It works, thank you for the solution.