Announcement Announcement Module
Collapse
No announcement yet.
Recommending a change... Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Recommending a change...

    I created this class to allow the security system to emit context relative redirects:
    Code:
    import org.acegisecurity.ui.webapp.AuthenticationProcessingFilter;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    
    public class CustomAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
    // ------------------------------ FIELDS ------------------------------
    
        private boolean useRelativeContext = false;
    
    // --------------------- GETTER / SETTER METHODS ---------------------
    
        public void setUseRelativeContext( boolean useRelativeContext ) {
            this.useRelativeContext = useRelativeContext;
        }
    
    // ------------------------ OVERRIDING METHODS ------------------------
    
        protected void sendRedirect( HttpServletRequest request, HttpServletResponse response, String url ) throws IOException {
            String finalUrl;
            if ( !url.startsWith( "http://" ) && !url.startsWith( "https://" ) ) {
                if ( useRelativeContext ) {
                    finalUrl = url;
                } else {
                    finalUrl = request.getContextPath() + url;
                }
            } else if ( useRelativeContext ) {
                int len = request.getContextPath().length();
                int index = url.indexOf( request.getContextPath() ) + len;
                finalUrl = url.substring( index );
                if ( finalUrl.length() > 1 && finalUrl.charAt( 0 ) == '/' ) {
                    finalUrl = finalUrl.substring( 1 );
                }
            } else {
                finalUrl = url;
            }
    
            response.sendRedirect( response.encodeRedirectURL( finalUrl ) );
        }
    }
    If the obtainFullRequestUrl(HttpServletRequest request) method was not 'static', could have just overridden that method to replace the 'saved' request URL with the context relative url.

    Comments?
    Jon

  • #2
    If you want to raise an enhancement, I would enter it in JIRA.

    Comment

    Working...
    X