Announcement Announcement Module
Collapse
No announcement yet.
Sitemesh problem after login Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sitemesh problem after login

    Hi,

    My problem is after the login the page is not decorated. I already searched the forums for the solution, but couldn't found any post that solves my probelm.

    This is the code of the redirect:

    Code:
    public String login() {
    	// authentication stuff... 
    
    	SavedRequest savedRequest = (SavedRequest)session.getAttribute(AuthenticationProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
    	String targetUrl = (savedRequest != null) ? savedRequest.getRequestURI() : "";
    	if (!"".equals(targetUrl)) {
    		session.removeAttribute(AuthenticationProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
    		SecurityMBean.log.info("targetUrl: " + savedRequest.getRequestURI());
    		 
    		String ctxPath = request.getContextPath();
    		int idx = targetUrl.indexOf(ctxPath);
    		String target = targetUrl.substring(idx + ctxPath.length());
    		forward(target);
    	}
    	return outcome;
    }
    
    
    
    protected void forward(String viewId) {
        ViewHandler viewHandler = getApplication().getViewHandler();
        FacesContext facesCtx = getFacesContext();
        UIViewRoot view = viewHandler.createView(facesCtx, viewId);
        facesCtx.setViewRoot(view);
        facesCtx.renderResponse();
    }
    Parts of my web.xml:

    Code:
    <filter>
    	<filter-name>Sitemesh</filter-name>
    	<filter-class>
    		com.opensymphony.module.sitemesh.filter.PageFilter
    	</filter-class>
    </filter>
    <filter-mapping>
    	<filter-name>Sitemesh</filter-name>
    	<url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <filter>
    	<filter-name>Acegi Filter Chain Proxy</filter-name>
    	<filter-class>
    		org.acegisecurity.util.FilterToBeanProxy
    	</filter-class>
    	<init-param>
    		<param-name>targetBean</param-name>
    		<param-value>acegiFilterChainProxy</param-value>
    	</init-param>
    </filter>
    
    <filter-mapping>
    	<filter-name>Acegi Filter Chain Proxy</filter-name>
    	<servlet-name>FacesServlet</servlet-name>
    	<dispatcher>FORWARD</dispatcher>
    	<dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    And my decorators.xml

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <decorators defaultdir="/WEB-INF/decorators">
    	<excludes>
           	<pattern>/login.jsf</pattern>
           	<pattern>/welcome.jsf</pattern>
        </excludes>
    
        <decorator name="main" page="main.jsp">
            <pattern>/*</pattern>
        </decorator>
        
    </decorators>
    The problem is when I try to access for e.g. /user/list.jsf it redirects to /login.jsf, wich renders smooth (no decorator). After I login, it redirects to /user/list.jsf page without decoration, and does not change the URL in the address bar.

    Part of my faces-navigation.xml:

    Code:
    <navigation-rule>
    	<from-view-id>*</from-view-id>
    	<navigation-case>
    		<from-outcome>login</from-outcome>
    		<to-view-id>/login.jsp</to-view-id>
    	</navigation-case>
    </navigation-rule>
    
    <navigation-rule>
    	<from-view-id>/login.jsp</from-view-id>
    	<navigation-case>
    		<from-outcome>welcome</from-outcome>
    		<to-view-id>/welcome.jsp</to-view-id>
    	</navigation-case>
    	<navigation-case>
    		<from-outcome>error</from-outcome>
    		<to-view-id>/login.jsp</to-view-id>
    	</navigation-case>
    </navigation-rule>
    
    <navigation-rule>
    	<from-view-id>/user/list.jsp</from-view-id>
    	<navigation-case>
    		<from-outcome>form</from-outcome>
    		<to-view-id>/user/form.jsp</to-view-id>
    	</navigation-case>
    	<navigation-case>
    		<from-outcome>view</from-outcome>
    		<to-view-id>/user/view.jsp</to-view-id>
    	</navigation-case>
    </navigation-rule>
    Is this a face-navigation.xml issue?

    How can I fix this?

    Thanks!

  • #2
    Solved

    I changed the code of my forward method from (lines removed in red):

    Code:
    public String login() {
    	// authentication stuff... 
    
    	SavedRequest savedRequest = (SavedRequest)session.getAttribute(AuthenticationProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
    	String targetUrl = (savedRequest != null) ? savedRequest.getRequestURI() : "";
    	if (!"".equals(targetUrl)) {
    		session.removeAttribute(AuthenticationProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
    		SecurityMBean.log.info("targetUrl: " + savedRequest.getRequestURI());
    		 
    		String ctxPath = request.getContextPath();
    		int idx = targetUrl.indexOf(ctxPath);
    		String target = targetUrl.substring(idx + ctxPath.length());
    		forward(target);
    	}
    	return outcome;
    }
    
    
    
    protected void forward(String viewId) throws IOException {
        ViewHandler viewHandler = getApplication().getViewHandler();
        FacesContext facesCtx = getFacesContext();
        UIViewRoot view = viewHandler.createView(facesCtx, viewId);
        facesCtx.setViewRoot(view);
        facesCtx.renderResponse();
    }
    to:

    Code:
    public String login() {
    	// authentication stuff... 
    
    	SavedRequest savedRequest = (SavedRequest)session.getAttribute(AuthenticationProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
    	String targetUrl = (savedRequest != null) ? savedRequest.getRequestURI() : "";
    	if (!"".equals(targetUrl)) {
    		session.removeAttribute(AuthenticationProcessingFilter.ACEGI_SAVED_REQUEST_KEY);
    		SecurityMBean.log.info("targetUrl: " + savedRequest.getRequestURI());
    
    	    	 try {
    	    		 forward(targetUrl);
    	    	 } catch (Exception e) { // on error, fallback to welcome screen }
    
    	}
    	return outcome;
    }
    
    
    protected void forward(String viewId) throws IOException {
        ViewHandler viewHandler = getApplication().getViewHandler();
        FacesContext facesCtx = getFacesContext();
        facesCtx.getExternalContext().redirect(viewId);
    }

    Comment

    Working...
    X