Answer the question
In order to leave comments, you need to log in
Where did the redirect to a static file come from?
Good day!
I'm learning spring development and ran into the following problem. Connected bootstrap via cdn and everything worked. I connected additional css & js files locally and after authorization on the site, first of all, it redirects to a static included file (before, it successfully redirected to the profile page).
Here is the structure of the header
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Styles-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="js/main.js"></script>
<link rel="stylesheet" href="css/style.css">
<title>Website Example</title>
</head>
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/","/signup").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/signin").defaultSuccessUrl("/profile")
.permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/signin")
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.passwordEncoder(NoOpPasswordEncoder.getInstance())
.usersByUsernameQuery("SELECT username, password, active FROM users WHERE username=?")
.authoritiesByUsernameQuery("SELECT u.username, ur.roles FROM users u INNER JOIN user_role ur ON u.user_id = ur.r_user_id WHERE u.username=?");
}
}
http://localhost:8080/css/style.css
instead of getting to /profile Answer the question
In order to leave comments, you need to log in
In general, I solved the problem.
Just in case, I will write the solution here to help others.
If you encounter this problem, then you must have included Spring Security and did not specify the css js fonts directories and other static content to be ignored.
The problem was observed after entering the site and after authorization, the first static file from the header was opened. In my case, style.css
SOLUTION:
Add
the following code to the
WebSecurityConfig file :
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**","/js/**","/fonts/**","/images/**");
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question