last day (15 days later) » 

8:31 AM
0
Q: Not able to load Css file in html page

majoI am trying to make a login page using spring security, and have added the .css file in the AntMatcher list for permission. but still, I am getting the following error when trying to load the CSS file. Exception: Refused to apply style from 'http://localhost:8080/css/defaultStyle.css' because i...

 
Open the URL to the css in the browser and see whether it is shown there, it might be that you will not find it in the root but rather below some context-root. Maybe something like http://localhost:8080/myapp/css/defaultStyle.css.
 
I checked that.i have put it in root folder where it was working before I applied Security It shows. This application has no explicit mapping for /error, so you are seeing this as a fallback. Mon Jul 01 13:35:13 IST 2019 There was an unexpected error (type=Not Found, status=404). No message available
 
Try this: @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers( "/resources/**" ); //make static content available - only for spring mvc applications }
 
already did that. web.ignoring() .antMatchers("/*.css") // or better ending with ".{js,html}" or something .antMatchers("/resources/static/**/*");
 
What happens if you put that file into src/main/resources/static/css?
 
8:31 AM
added the structure for CSS file. it is put in both folders. still, none is working
did you see the structure i added in question
 
Once i also had that issue and when i googled it these days i remember it said that there are comments in the css file which can not be parsed which ends up in that error.
But for me i found that was not the issue. I had a wrong path.
 
there are no comments in the file
how do i check the correct path for the file.
 
it doesn't show the file
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Jul 01 14:04:12 IST 2019
There was an unexpected error (type=Unauthorized, status=401).
Full authentication is required to access this resource
 
please also enter the file name in the url
ah ok
it gives 401
so its blocked
my webapp looks like this

protected void handleAuthorization( HttpSecurity httpSecurity ) throws Exception {
httpSecurity.authorizeRequests()
.antMatchers( "/*", "/css/*" ).permitAll() //allow to show the website itself
.antMatchers( HttpMethod.POST, jwtConfig.getUri() ).permitAll()
.antMatchers( HttpMethod.POST, "/api/**").hasRole("ADMIN")
.antMatchers( HttpMethod.PUT, "/api/**").hasRole("ADMIN")
.antMatchers( HttpMethod.DELETE, "/api/**").hasRole("ADMIN")
.anyRequest().authenticated();
}

and is workin
can you please paste the complete security config?
 
8:36 AM
ok i will try that
 
need to call someone - just a sec
 
sure
after fixing the authentication i am getting a new error message.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Jul 01 14:10:36 IST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
 
you have that file?
 
which file
 
you get 404 when calling ...url.../file.css?
the complete java class whcih is your security config
 
8:41 AM
yes
ok let me send it to you
package com.domo.config;

import com.domo.security.CustomAccessDeniedHandler;
import com.domo.security.CustomUserDetailsService;
import com.domo.security.JwtAuthenticationEntryPoint;
import com.domo.security.JwtAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
i have done many experiments with it to solve this issue
 
i can imagine ^^
 
before adding the spring security the file was loading correctly
so the path is not the problem. I THINK
after adding the security it has started to show this problem
 
ok can you please do
.antMatchers( "/*", "/css/*" ).permitAll()
not just / but /*
please try
 
ok
in which section are you asking to do this?
 
replace this:

@Override
public void configure( HttpSecurity http ) throws Exception
{

/* http.cors().and().csrf().disable()
.authorizeRequests()
// .antMatchers( "/","/css/**" ).permitAll() //Adding this line solved it


with this


@Override
public void configure( HttpSecurity http ) throws Exception
{

/* http.cors().and().csrf().disable()
.authorizeRequests()
// .antMatchers( "/*","/css/**" ).permitAll() //Adding this line solved it
is it working?
package com.domo.config;

import com.domo.security.CustomAccessDeniedHandler;
import com.domo.security.CustomUserDetailsService;
import com.domo.security.JwtAuthenticationEntryPoint;
import com.domo.security.JwtAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
@majo still there?
 
9:49 AM
sorry
i left for lunch
I tried what you sent. but still no change
 

last day (15 days later) »