Question

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

Was it helpful?

Solution 3

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.

OTHER TIPS

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!!

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()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top