why homepage is not reachable after adding spring security

Anna Uspenskaya

I’m adding spring security to the web site My goal is to show all images, home.html, and index.html to all users (without logging in).

I’ve allowed all requests for images and home and index pages, but still anonymous users cannot proceed to the home page without logging in

My security config Java

protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .antMatchers("/admin").hasRole("ADMIN")
            .antMatchers("/", "home", "index").permitAll()
            .antMatchers("/styles.css", "/css/**", "/js/**", "/fonts/**", "/images/**").permitAll()
            .anyRequest().hasRole("USER")
            .and()
            .formLogin()
            .loginPage("/login")
            .failureUrl("/login?login_error=1")
            .permitAll()
            .and()
            .logout()
            .logoutSuccessUrl("/")
            .permitAll();
}

My index.html page

<!doctype html>
<html lang="en"       
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

    <body>

                    <a href="login" class="btn btn-outline-danger btn-lg">login page </a>
                    <a href="home" class="btn btn-outline-danger btn-lg">home page</a>


    </body>
</html>

my Image

Dominik

Have you tried refactoring like this: .antMatchers("/", "home", "index").permitAll() -> .antMatchers("/", "/home", "/index").permitAll() ?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Testing Spring Controller POST method after adding Spring Security on Kotlin

why code after the return statement is reachable in javascript

Spring http security stop working after adding OAuth2

Why do I get a still reachable block after mallocing a char*?

After adding Spring Security to Spring MVC project, home page keeps returning 404 error

WebMVC tests failing after adding spring security, how to fix all at once?

Am I adding Spring Security to my project correctly? Access error after authorization

Cannot instantiate interface org.springframework.context.ApplicationListener after adding spring-security-oauth2

Grails 3.2.4 Application Won't Load After Adding Spring Security Plugin 3.1.1

Why Am I Getting an IllegalStateException While Adding Bcrypt to my Spring-Security.XML file?

mongodb showing state as (not reachable/healthy) after adding new secondary in other region

File upload not working from Angular 8 front-end to the Spring Boot back-end after adding Spring Security

Why Spring Boot Application logs that it started twice after adding spring-cloud-bus dependency

Adding user to session, spring security default login

Adding Security Headers in response of spring MVC Application

Adding Same Site Header to JSESSIONID Spring Security

Adding sub domains to spring security authentication

Adding a new homepage to Drupal

Why is the 'anonymousUser' authenticated in Spring Security?

Why is Spring Security permitAll not working?

Why isn’t this Spring Security AuthenticationProvider found after being Java configured?

Javascript function not reachable after settimeout

Why is Swing JFrame always reachable?

Homepage loads as usual even after adding question mark with random text and number

Spring security redirect to static resources after authentication

Spring Security and Action Required after login

How to do something after the login with Spring Security?

Spring Security throwing 403 after basic authentication

Spring Security Always Redirecting to "/" After Login