OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Cannot access script.js when using spring boot security to login

  • Thread starter Thread starter agen7p
  • Start date Start date
A

agen7p

Guest
Hey guys i'm trying to implement login by using Spring boot security, but i cannot using default username and password (defined in application.properties) to login. When i hit the button, it direct me to this url: http://localhost:8080/static/js/scripts.js?continue I got the HTTP ERROR 403 say that i don't have authorization to view this page. Here is the code in my SecurityConfig.java

Code:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
        http
            .csrf(csrf -> csrf.disable())
            .authorizeHttpRequests(authz -> authz
                .requestMatchers("/login", "/register", "/clubs", "/css/**", "/js/**")
                .permitAll()
            )
            .formLogin(form -> form
                .loginPage("/login")
                .defaultSuccessUrl("/clubs?success")
                .loginProcessingUrl("/login")
                .failureUrl("/login?error=true")
                .permitAll()
            )
            .logout(logout -> logout
                .logoutUrl("/logout")
                .permitAll());
        return http.build();
    }

}

I try to go back, login again and it works! I don't know why it always fails at the first time.

<p>Hey guys i'm trying to implement login by using Spring boot security, but i cannot using default username and password (defined in application.properties) to login. When i hit the button, it direct me to this url: http://localhost:8080/static/js/scripts.js?continue
I got the HTTP ERROR 403 say that i don't have authorization to view this page.
Here is the code in my SecurityConfig.java</p>
<pre><code>@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(authz -> authz
.requestMatchers("/login", "/register", "/clubs", "/css/**", "/js/**")
.permitAll()
)
.formLogin(form -> form
.loginPage("/login")
.defaultSuccessUrl("/clubs?success")
.loginProcessingUrl("/login")
.failureUrl("/login?error=true")
.permitAll()
)
.logout(logout -> logout
.logoutUrl("/logout")
.permitAll());
return http.build();
}

}
</code></pre>
<p>I try to go back, login again and it works! I don't know why it always fails at the first time.</p>
 

Latest posts

D
Replies
0
Views
1
Dhanushka Amarakoon
D
S
Replies
0
Views
1
Shikhar Ambashta
S
Top