adiao 3 years ago
parent
commit
641a144c0e
  1. 26
      app-service/src/main/java/com/depsystem/app/systemServer/config/WebSecurityConfig.java

26
app-service/src/main/java/com/depsystem/app/systemServer/config/WebSecurityConfig.java

@ -8,18 +8,29 @@ @@ -8,18 +8,29 @@
package com.depsystem.app.systemServer.config;
import cn.hutool.json.JSONUtil;
<<<<<<< HEAD
import com.depsystem.app.systemServer.securityServer.securityFilter.AuthenticationServerImpl;
import com.depsystem.app.systemServer.securityServer.handler.AuthenticationsFailureHandler;
import com.depsystem.app.systemServer.securityServer.handler.AuthenticationsSuccessHandler;
=======
import com.depsystem.app.systemServer.securityServer.AuthenticationServerImpl;
import com.depsystem.app.systemServer.securityServer.handler.AuthenticationsFailureHandler;
import com.depsystem.app.systemServer.securityServer.handler.AuthenticationsSuccessHandler;
import com.depsystem.app.systemServer.securityServer.securityFilter.CaptchaVerifyFilter;
>>>>>>> 024d1f4 (最新版Spring boot + Vue3 + Spring Security 6 项目模板)
import com.depsystem.app.systemServer.util.ResponseResult;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
<<<<<<< HEAD
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
=======
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
>>>>>>> 024d1f4 (最新版Spring boot + Vue3 + Spring Security 6 项目模板)
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@ -28,11 +39,15 @@ import org.springframework.security.core.AuthenticationException; @@ -28,11 +39,15 @@ 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.SecurityFilterChain;
<<<<<<< HEAD
=======
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
>>>>>>> 024d1f4 (最新版Spring boot + Vue3 + Spring Security 6 项目模板)
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import javax.swing.*;
import java.io.IOException;
@ -43,9 +58,12 @@ public class WebSecurityConfig { @@ -43,9 +58,12 @@ public class WebSecurityConfig {
@Resource
AuthenticationServerImpl authenticationServer;
<<<<<<< HEAD
=======
@Autowired
StringRedisTemplate stringRedisTemplate;
>>>>>>> 024d1f4 (最新版Spring boot + Vue3 + Spring Security 6 项目模板)
@Bean
public AuthenticationManager authenticationManager(HttpSecurity httpSecurity) throws Exception {
return httpSecurity.userDetailsService(authenticationServer)
@ -58,6 +76,11 @@ public class WebSecurityConfig { @@ -58,6 +76,11 @@ public class WebSecurityConfig {
http.authorizeHttpRequests(author ->
author
.requestMatchers("/captcha").permitAll()
<<<<<<< HEAD
.requestMatchers("/index").hasAnyRole("admin1")
.requestMatchers("/{name}/**").hasAnyRole("admin2","admin3")
=======
>>>>>>> 024d1f4 (最新版Spring boot + Vue3 + Spring Security 6 项目模板)
.anyRequest().authenticated()
)
.formLogin()
@ -74,7 +97,10 @@ public class WebSecurityConfig { @@ -74,7 +97,10 @@ public class WebSecurityConfig {
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(this::onAuthenticationFailure);
<<<<<<< HEAD
=======
http.addFilterBefore(new CaptchaVerifyFilter(this::onAuthenticationFailure,stringRedisTemplate), UsernamePasswordAuthenticationFilter.class);
>>>>>>> 024d1f4 (最新版Spring boot + Vue3 + Spring Security 6 项目模板)
return http.build();
}

Loading…
Cancel
Save