Get the App
SLTechnology News&Howtos  ›  Development  › 

What if SpringSecurity fails to jump to the page?

Shulou Source: shulou.com Published: 2022-06-03 09:35:28 11月15日 Update

This article mainly introduces the failure of the SpringSecurity jump page how to do, the article is very detailed, has a certain reference value, interested friends must read it!

Today's new SpringBoot project training, for the first time added Spring Security. After successfully starting the project, I found that it was a little different from the newly built project. No matter how I set up the home page of the system, what opened in the browser was the login interface.

No matter how I set the jump path of controller, it doesn't work. I'm so angry that I scratch my head!

After consulting all kinds of data, we found that it may be the cause of Spring Security access control, so we began to configure the control rights.

Create a new SecurityConfig class to configure permissions. The code is as follows:

Import org.springframework.context.annotation.Bean;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;import org.springframework.security.crypto.password.NoOpPasswordEncoder @ EnableWebSecuritypublic class SecurityConfig extends WebSecurityConfigurerAdapter {@ Override protected void configure (HttpSecurity http) throws Exception {/ / configuration resource file, where / css/** and index can access http .authorizeRequests () .antMatrices ("/ css/**", "/ index"). PermitAll ();}}

Some explanations:

AuthorizeRequests: configure permission authentication antMatchers for some resources or links: configure which resources or links need to be authenticated permitAll: set resources or links that are fully allowed to access

After adding the above permission settings, the index page can be accessed normally.

The above is all the contents of the article "what to do if the SpringSecurity Jump Page fails". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Permissions configuration resources pages links projects what to do content articles control authentication success code value role interests reasons guys partners files Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Redmi Linux NVidia