IBM Support

HTTP Status 400 - Invalid direct reference to form login page

Troubleshooting


Problem

Directly requesting /teamworks/login.jsp or /portal/login.do displays the Invalid direct reference error when using JBoss application server.

Resolving The Problem

Directly browsing to /teamworks/login.jsp or /portal/login.do displays the Invalid direct reference error when using JBoss application server. This is a Tomcat specific problem. The root cause here is that for form based login pages, if you directly request the login page, Tomcat doesn't know where you should be redirected after authentication and throws the above error. Sadly, you can hit this a lot as it is very common to bookmark the login page itself.

The following code will fix this for the teamworks and portal login pages.

To fix /teamworks/login.jsp in Teamworks 6.0.1 and 6.1, edit the login.jsp found here:


    /process-server/applications/teamworks.ear/teamworks.war/login.jsp

Find this section:

    <%@ include file="html/common/prolog.jsp" %>
    <html>

and put the following code between the <%@ ... %> and the <html> tags:

    <%
    // inserted to prevent direct accesses to login.jsp from causing problems
    String agent = request.getHeader ("User-Agent");
    boolean skip = false;
    if (agent!=null &amp;&amp; agent.contains("Jakarta Commons")) {
    // we need this because of redirect-login's use of jakarta commons
    skip = true;
    }
    if (session.isNew() &amp;&amp; !skip) {
    //out.println ("Session is new<br>");
    String referer = request.getHeader("Referer");
    //out.println ("referer:" + referer + "<br>");
    //out.println ("request URI:" + request.getRequestURI() + "<br>");
    // The referer is sometimes null but should be so we get it from the request attributes instead
    String servletRequest = (String) request.getAttribute ("javax.servlet.forward.request_uri");
    if (servletRequest != null) {
    if (!servletRequest.contains ("login.jsp")) {
    String queryString = (String) request.getAttribute ("javax.servlet.forward.query_string");
    if (queryString != null) {
    servletRequest += "?" + queryString;
    }
    referer = servletRequest;
    //out.println ("referer =" + servletRequest + "<br>");
    }
    }
    if (referer == null) {
    //out.println ("send redirect to home");
    response.sendRedirect("cs_main.lsw");
    }
    else {
    //out.println ("send redirect to:" + referer);
    response.sendRedirect(referer);
    }
    }

    %>

To fix /portal/login.do in Teamworks 6.0.1 and 6.1, edit /portal/login.jsp found here:

    /process-server/applications/portal.war/login.jsp

and put this right after the taglibs on the top of the page:

    <%
    if (session.isNew()) {
    //out.println ("Session is new<br>");
    String referer = request.getHeader("Referer");
    //out.println ("referer:" + referer + "<br>");
    //out.println ("request URI:" + request.getRequestURI() + "<br>");
    // The referer is sometimes null but should be so we get it from the request attributes instead
    String servletRequest = (String) request.getAttribute ("javax.servlet.forward.request_uri");
    if (servletRequest != null) {
    if (!servletRequest.contains ("login.do")) {
    String queryString = (String) request.getAttribute ("javax.servlet.forward.query_string");
    if (queryString != null) {
    servletRequest += "?" + queryString;
    }
    referer = servletRequest;
    //out.println ("referer =" + servletRequest + "<br>");
    }
    }
    if (referer == null) {
    //out.println ("send redirect to home");
    response.sendRedirect("jsp/getSavedSearch.do");
    }
    else {
    //out.println ("send redirect to:" + referer);
    response.sendRedirect(referer);
    }
    }

    %>

The above code will prevent the error by redirecting the user to a real page before trying to render the login page.

NOTE: if -- after applying these changes -- your teamworks or portal page does not render and an examination of the server logs indicates a jsp compile error similar to:


    2008-05-12 18:16:52,630 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/portal].[jsp]] Servlet.service() for servlet jsp threw exception

    org.apache.jasper.JasperException: Unable to compile class for JSP

    An error occurred at line: 7 in the jsp file: /login.jsp

    Generated servlet error:

    The method contains(String) is undefined for the type String


you are probably using a version of Teamworks prior to Teamworks 6, which calls for a 1.4.x JVM, which does not yet have a "contains" method for the String type.

The <teamworks_install_dir>/process-server/startup/logs/daemonwrapper.log will log the JVM version, immediately after the Wrapper Started signature:


    STATUS | wrapper | 2008/05/13 10:43:51 | --> Wrapper Started as Daemon
    STATUS | wrapper | 2008/05/13 10:43:52 | Launching a JVM...
    INFO | jvm 1 | 2008/05/13 10:43:57 | Wrapper Manager: JVM #1
    INFO | jvm 1 | 2008/05/13 10:43:57 | Wrapper Manager: Registering shutdown hook
    INFO | jvm 1 | 2008/05/13 10:43:57 | Wrapper Manager: Using wrapper
    INFO | jvm 1 | 2008/05/13 10:43:57 | Calling native initialization method.
    INFO | jvm 1 | 2008/05/13 10:43:57 | Inside native WrapperManager initialization method
    INFO | jvm 1 | 2008/05/13 10:43:57 | Java Version : J2RE 1.4.2 IBM AIX build ca142-20070708 (SR9) (JIT enabled: jitc)
    INFO | jvm 1 | 2008/05/13 10:43:57 | Java VM Vendor : IBM Corporation
    :

allowing you to confirm the JVM version
In this case you would substitute:

    indexOf("pattern") != -1 in place of: contains("pattern")

So to fix /teamworks/login.jsp in Teamworks 5.5.x, edit the login.jsp and put the following underneath the prolog include:

    <%

      // inserted to prevent direct accesses to login.jsp from causing problems
      String agent = request.getHeader ("User-Agent");
      boolean skip = false;
      if (agent!=null &amp;&amp; (agent.indexOf("Jakarta Commons") != -1)) {
      // we need this because of redirect-login's use of jakarta commons
      skip = true;
      }
      if (session.isNew() &amp;&amp; !skip) {
      //out.println ("Session is new<br>");
      String referer = request.getHeader("Referer");
      //out.println ("referer:" + referer + "<br>");
      //out.println ("request URI:" + request.getRequestURI() + "<br>");
      // The referer is sometimes null but should be so we get it from the request attributes instead
      String servletRequest = (String) request.getAttribute ("javax.servlet.forward.request_uri");
      if (servletRequest != null) {
      if (servletRequest.indexOf("login.jsp") == -1) {
      String queryString = (String) request.getAttribute ("javax.servlet.forward.query_string");
      if (queryString != null) {
      servletRequest += "?" + queryString;
      }
      referer = servletRequest;
      //out.println ("referer =" + servletRequest + "<br>");
      }
      }
      if (referer == null) {
      //out.println ("send redirect to home");
      response.sendRedirect("cs_main.lsw");
      }
      else {
      //out.println ("send redirect to:" + referer);
      response.sendRedirect(referer);
      }
      }

    %>

To fix /portal/login.do in Teamworks 5.5.x, edit /portal/login.jsp and put this right after the taglibs on the top of the page:

    <%

      if (session.isNew()) {
      //out.println ("Session is new<br>");
      String referer = request.getHeader("Referer");
      //out.println ("referer:" + referer + "<br>");
      //out.println ("request URI:" + request.getRequestURI() + "<br>");
      // The referer is sometimes null but should be so we get it from the request attributes instead
      String servletRequest = (String) request.getAttribute ("javax.servlet.forward.request_uri");
      if (servletRequest != null) {
      if (servletRequest.indexOf("login.do") == -1) {
      String queryString = (String) request.getAttribute ("javax.servlet.forward.query_string");
      if (queryString != null) {
      servletRequest += "?" + queryString;
      }
      referer = servletRequest;
      //out.println ("referer =" + servletRequest + "<br>");
      }
      }
      if (referer == null) {
      //out.println ("send redirect to home");
      response.sendRedirect("jsp/getSavedSearch.do");
      }
      else {
      //out.println ("send redirect to:" + referer);
      response.sendRedirect(referer);
      }
      }

    %>
[{"Product":{"code":"SSFPRP","label":"WebSphere Lombardi Edition"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"6.1;6.0.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

343

Product Synonym

Teamworks TW Lombardi

Document Information

More support for:
WebSphere Lombardi Edition

Software version:
6.1, 6.0.1

Operating system(s):
AIX, HP-UX, Linux, Solaris, Windows

Document number:
139403

Modified date:
15 June 2018

UID

swg21439782

Manage My Notification Subscriptions