Jelajahi Sumber

修改密码匹配前端SM3

wukai 2 tahun lalu
induk
melakukan
0774b3fe8f

+ 3 - 2
doc-common/src/main/java/com/doc/common/constant/UserConstants.java

@@ -72,7 +72,8 @@ public class UserConstants
 
     /**
      * 密码长度限制
+     * 因为前端需要用SM3加密,所以固定为64位
      */
-    public static final int PASSWORD_MIN_LENGTH = 5;
-    public static final int PASSWORD_MAX_LENGTH = 20;
+    public static final int PASSWORD_MIN_LENGTH = 64;
+    public static final int PASSWORD_MAX_LENGTH = 64;
 }

+ 6 - 2
doc-common/src/main/java/com/doc/common/utils/encrypt/Sm3Util.java

@@ -1,5 +1,6 @@
 package com.doc.common.utils.encrypt;
 
+import com.doc.common.utils.SecurityUtils;
 import org.bouncycastle.crypto.digests.SM3Digest;
 import org.bouncycastle.util.encoders.Hex;
 
@@ -29,7 +30,10 @@ public class Sm3Util {
     }
 
     public static void main(String[] args) throws Exception {
-        String message = "Hello World!!!";
-        System.out.println("SM3 Digest: " + encrypt(message));
+        String message = "1234567";
+        String en1 = encrypt(message);
+        String en2 = SecurityUtils.encryptPassword(en1);
+        System.out.println("SM3 Digest 1: " + en1);
+        System.out.println("SM3 Digest 2: " + en2);
     }
 }

+ 9 - 14
doc-framework/src/main/java/com/doc/framework/config/SecurityConfig.java

@@ -23,18 +23,17 @@ import javax.annotation.Resource;
 
 /**
  * spring security配置
- * 
+ *
  * @author ruoyi
  */
 @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
-public class SecurityConfig extends WebSecurityConfigurerAdapter
-{
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
     /**
      * 自定义用户认证逻辑
      */
     @Resource
     private UserDetailsService userDetailsService;
-    
+
     /**
      * 认证失败处理类
      */
@@ -52,7 +51,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      */
     @Resource
     private JwtAuthenticationTokenFilter authenticationTokenFilter;
-    
+
     /**
      * 跨域过滤器
      */
@@ -73,8 +72,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      */
     @Bean
     @Override
-    public AuthenticationManager authenticationManagerBean() throws Exception
-    {
+    public AuthenticationManager authenticationManagerBean() throws Exception {
         return super.authenticationManagerBean();
     }
 
@@ -94,8 +92,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      * authenticated       |   用户登录后可访问
      */
     @Override
-    protected void configure(HttpSecurity httpSecurity) throws Exception
-    {
+    protected void configure(HttpSecurity httpSecurity) throws Exception {
         // 注解标记允许匿名访问的url
         ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity.authorizeRequests();
         permitAllUrl.getUrls().forEach(url -> registry.antMatchers(url).permitAll());
@@ -115,7 +112,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/login", "/register", "/captchaImage").permitAll()
                 // 增加API接口允许匿名访问
                 .antMatchers("/api/**").permitAll()
-                // 增加API接口允许匿名访问
+                // 增加onlyoffice接口允许匿名访问
                 .antMatchers("/only-office/**").permitAll()
                 // 增加websocket允许匿名访问
                 .antMatchers("/websocket/**").permitAll()
@@ -139,8 +136,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      * 强散列哈希加密实现
      */
     @Bean
-    public BCryptPasswordEncoder bCryptPasswordEncoder()
-    {
+    public BCryptPasswordEncoder bCryptPasswordEncoder() {
         return new BCryptPasswordEncoder();
     }
 
@@ -148,8 +144,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
      * 身份认证接口
      */
     @Override
-    protected void configure(AuthenticationManagerBuilder auth) throws Exception
-    {
+    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
         auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
     }
 }