This commit is contained in:
limqhz
2022-05-14 01:14:16 +08:00
parent a3df75bd66
commit 9e1dd3af77
31 changed files with 625 additions and 2240 deletions

View File

@@ -8,8 +8,18 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
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.core.AuthenticationException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.authentication.AuthenticationEntryPointFailureHandler;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@@ -29,9 +39,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http.authorizeRequests()
.antMatchers("/","/index").permitAll()
.antMatchers("/register","/login","/toLogin").permitAll()
.antMatchers("/source","/source/view/*").permitAll()
.antMatchers("/blog","/blog/read/*").permitAll()
.antMatchers("/hotspot").permitAll()
.antMatchers("/blog/**").authenticated()
.antMatchers("/source/**").authenticated()
.antMatchers("/user/**").authenticated()
.antMatchers("/wx/**").authenticated()
.antMatchers("/*").authenticated();
// 登录配置
@@ -40,6 +54,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.passwordParameter("password")
.loginPage("/toLogin")
.loginProcessingUrl("/login") // 登陆表单提交请求
.failureForwardUrl("/loginError")
.defaultSuccessUrl("/index"); // 设置默认登录成功后跳转的页面
// 注销配置