jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
487 stars 112 forks source link

Logout button ignores the server.servlet.context-path property #3435

Closed gorbunkov closed 1 day ago

gorbunkov commented 2 days ago

Environment

Jmix version: 2.3.0

Bug Description

If the server.servlet.context-path is set, then Logout button redirects to the root URL ("/").

See forum.

Steps To Reproduce

  1. Create new project
  2. Set the application property:
    server.servlet.context-path=/demo
  3. Login with admin at http://localhost:8080/demo
  4. Click the "Logout" button

Current Behavior

The application redirects to the http://localhost:8080 instead of http://localhost:8080/demo

Screenshot 2024-07-01 at 13 45 04

Expected Behavior

The login view is displayed.

Workaround

The workaround is to define the extended Flowui security configuration in the project:

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);
    }
}
konyashkina commented 1 day ago

Tested on Jmix version: 2.3.999-SNAPSHOT Jmix Studio plugin version: 2.3.SNAPSHOT6530-241 IntelliJ version: IntelliJ IDEA 2024.1.1