0

i am using spring security 3.0 . In spring-security.xml , i have a 1 problem when display login page. The login.jsp of CSS is not load or missing in the web browser. so please solve this problem.. Any help i appreciated u.

my spring-security.xml code is given below..

     <beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">

  <http auto-config="true"  use-expressions="true">
    <intercept-url pattern="/login.html" access="permitAll" />
     <intercept-url pattern="/logout" access="permitAll" />

   <intercept-url pattern="/accessdenied" access="permitAll"  />
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
   <form-login login-page="/login.html" default-target-url="/firstwelcome.html"  />
    <logout logout-success-url="/logout" /> 
  </http>


  <authentication-manager  alias="authenticationManager">  
      <authentication-provider>  
        <password-encoder hash="md5"/>
        <jdbc-user-service data-source-ref="dataSource"
              users-by-username-query="
              SELECT strUSERNAME, strPASSWORD, CASE blENABLED WHEN 1 THEN 'true' ELSE             'false' END 'ENABLED' 
      FROM TBLUSERS 
      WHERE strUSERNAME=?;"

    authorities-by-username-query="
     SELECT strUSERNAME, strROLENAME 
     FROM TBLUSERS
     WHERE strUSERNAME=?;"

     />
  </authentication-provider>  
  </authentication-manager>  



 </beans:beans>

and Header of the my login.jsp is given below

           <link rel="stylesheet" type="text/css" href="css/login.css">

in above login.jsp use link tag to call the css.. but unfortunately is not call ..``.plz... help me for calling the login.css file . Any help i appreciated u.

Thanks

9
  • post your project structure Commented Apr 21, 2014 at 6:27
  • in web-content folder 1)css 2)images 2) Meta-INF 3) WEB-INF ..IN CSS FOLDER login.css WEB-INF FOLDER IN 1)JSP 2)LIB 3)springservlet.xml 4)springsecurity.xml Commented Apr 21, 2014 at 7:04
  • As you views will inside web-inf , why dont you try ./ before your path ? Commented Apr 21, 2014 at 7:06
  • in <link rel="stylesheet" type="text/css" href="./css/login.css"> ? Commented Apr 21, 2014 at 7:09
  • Yes . does that loads ? Commented Apr 21, 2014 at 7:15

3 Answers 3

6

You need to add this line to spring-security.xml to allow this css

<intercept-url pattern="/css/login.css" access="permitAll"/>

so your spring-security.xml will be

<http auto-config="true"  use-expressions="true">
    <intercept-url pattern="/login.html" access="permitAll" />
     <intercept-url pattern="/logout" access="permitAll" />

   <intercept-url pattern="/css/login.css" access="permitAll"/>
   <intercept-url pattern="/accessdenied" access="permitAll"  />
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
   <form-login login-page="/login.html" default-target-url="/firstwelcome.html"  />
    <logout logout-success-url="/logout" /> 
  </http>

Hope this helps!!

Sign up to request clarification or add additional context in comments.

Comments

1

You need to add following in java config class (instead of security driven by XML config) which extends WebSecurityConfigurerAdapter Assuming your resources are in /resources/content http.authorizeRequests().antMatchers("/resources/content/**").permitAll()

Comments

0

in your spring servlet write code like this

<mvc:resources location="/resources/" mapping="/resources/**"/>

paste your css in resource folder.

  resources -> css -> style.css
  resources folder inside **webapp**

and access using

<link href="<c:url value="resources/css/style.css" />" rel="stylesheet">

I am sure about this it will solve your issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.