JSF redirects from HTTPS to HTTP

前端 未结 2 648
闹比i
闹比i 2021-01-13 17:32

I have my application on a test server being executed exclusively over https. When I navigate without redirecting, it works perfectly:

Example:

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-13 17:53

    I found a solution for this issue. I think it is happening because Apache receives the https connection and forwards for JBoss via http. Then when I redirect to another page, JSF doesn't know that it should be made via https.

    With a ConfigurableNavigationHandler I can intercept when it is redirected and mount the correct URL.

    public class NavigationHandler extends ConfigurableNavigationHandler {
    
        private ConfigurableNavigationHandler concreteHandler;
    
        public NavigationHandler(ConfigurableNavigationHandler concreteHandler) {
            this.concreteHandler = concreteHandler;
        }
    
        @Override
        public void handleNavigation(FacesContext context, String fromAction, String outcome) {
            if (outcome != null && outcome.contains("faces-redirect=true")) {
                try {
                    outcome = "https://server.com/project" + outcome;
                    context.getExternalContext().redirect( outcome );
                } catch (IOException e) {
                    throw new FacesException(e);
                }
            } else {
                concreteHandler.handleNavigation(context, fromAction, outcome);   
            }
        }
    }
    

    in faces-config.xml:

    
        com.example.NavigationHandler
     
    

提交回复
热议问题