2 Replies Latest reply on Jan 14, 2009 9:22 AM by Wolfgang Knauf

    Problem with css files in login.jsp page

    Marcin Misiewicz Newbie

      Hi

      In my webapp I have configured form-based authentication. Here is my the code snippet of my web.xml file :

       <security-constraint>
       <web-resource-collection>
       <web-resource-name>Protected resources</web-resource-name>
       <url-pattern>/restricted/*</url-pattern>
       </web-resource-collection>
       <auth-constraint>
       <role-name>user</role-name>
       </auth-constraint>
       <user-data-constraint>
       <transport-guarantee>NONE</transport-guarantee>
       </user-data-constraint>
       </security-constraint>
      
       <login-config>
       <auth-method>FORM</auth-method>
       <form-login-config>
       <form-login-page>/login.jsp</form-login-page>
       <form-error-page>/error.html</form-error-page>
       </form-login-config>
       </login-config>
      
       <security-role>
       <description>The role required to login to application</description>
       <role-name>user</role-name>
       </security-role>
      


      Authentication works ok.
      But when I wan't to customize look of the login.jsp page with css and use javascript, insted of css file or js file I get always login.jsp file. It looks like all the resources are protected event outside of the restricted area when I get redirected to the login.jsp.
      When I hit css or js file in the browser I get the correct value. Also when I hit login.jsp directly not through redirect.

      Here is the login.jsp :

      <%@ page language="java" contentType="text/html; charset=UTF-8"
       pageEncoding="UTF-8"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Insert title here</title>
       <link rel="stylesheet" type="text/css" href="login.css" />
      </head>
      <body>
       <form method="POST" action="<%=request.getContextPath()%>/j_security_check">
       User: <input type="text" name="j_username" size="15"><br>
       Password: <input type="password" name="j_password" maxlength="20" size="15"><br>
       <INPUT TYPE="SUBMIT" VALUE="Send" >
       </form>
      </body>
      </html>
      


      Does anybody had similar problem. What am I doing wrong ?

      Thanks
      Martin

        • 1. Re: Problem with css files in login.jsp page
          Marcin Misiewicz Newbie

          When I turn on TCP/IP monitor I can see that the browser want to get /myapp/restricted/login.css not /myapp/login.css.

          And of course instead of content of css file I get login.jsp.

          Please help. I don't know what am I doing wrong.

          I guess there is something wrong with redirect to login.jsp. I think that after successful redirect the url in the browser should point to the login.jsp, but in my case it is still pointing to the restricted resource.

          I have tested this in FF, Chrome and IE and result is the same in every browser.
          I'm using jboss 5.0 GA.

          Thanks in advance
          Martin

          • 2. Re: Problem with css files in login.jsp page
            Wolfgang Knauf Master

            Hi Martin,

            try this:

            <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/login.css" />


            Explanation: you call a page like "/restricted/mypage.jsp", which redirects you to the login page. But your browser still sees "/restricted/mypage.jsp" (see address bar) and thinks that "login.css" is a relative URL in the "restricted" area.

            Hope this helps

            Wolfgang