diff --git a/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/pojo/auth/PwdRsaSecretProperties.java b/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/pojo/auth/PwdRsaSecretProperties.java new file mode 100644 index 000000000..6bd9fff55 --- /dev/null +++ b/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/pojo/auth/PwdRsaSecretProperties.java @@ -0,0 +1,59 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.auth.api.pojo.auth; + +import cn.hutool.crypto.asymmetric.RSA; +import lombok.Data; + +/** + * 用在系统登录,密码加密的RSA非对称加密秘钥对 + * + * @author fengshuonan + * @date 2022/10/16 15:28 + */ +@Data +public class PwdRsaSecretProperties { + + /** + * RSA非对称加密,公钥 + */ + private String publicKey; + + /** + * RSA非对称加密,私钥 + */ + private String privateKey; + + public static void main(String[] args) { + // 测试生成秘钥对 + RSA rsa = new RSA(); + String publicKeyBase64 = rsa.getPublicKeyBase64(); + String privateKeyBase64 = rsa.getPrivateKeyBase64(); + + System.out.println(publicKeyBase64); + System.out.println(privateKeyBase64); + } + +} diff --git a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java index 4e3a9ccfc..34b69d08d 100644 --- a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java +++ b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/auth/AuthServiceImpl.java @@ -317,7 +317,7 @@ public class AuthServiceImpl implements AuthServiceApi { } // 3. 解密密码的密文 - // String decryptPassword = passwordTransferEncryptApi.decrypt(loginRequest.getPassword()); + String decryptPassword = passwordTransferEncryptApi.decrypt(loginRequest.getPassword()); // 4. 如果开启了单点登录,并且CaToken没有值,走单点登录,获取loginCode if (ssoProperties.getOpenFlag() && StrUtil.isEmpty(caToken)) { @@ -330,7 +330,7 @@ public class AuthServiceImpl implements AuthServiceApi { SsoServerApi ssoServerApi = SpringUtil.getBean(SsoServerApi.class); SsoLoginCodeRequest ssoLoginCodeRequest = new SsoLoginCodeRequest(); ssoLoginCodeRequest.setAccount(loginRequest.getAccount()); - ssoLoginCodeRequest.setPassword(loginRequest.getPassword()); + ssoLoginCodeRequest.setPassword(decryptPassword); String remoteLoginCode = ssoServerApi.createSsoLoginCode(ssoLoginCodeRequest); return new LoginResponse(remoteLoginCode); } diff --git a/kernel-d-auth/auth-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/auth/starter/GunsAuthAutoConfiguration.java b/kernel-d-auth/auth-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/auth/starter/GunsAuthAutoConfiguration.java index 16d840774..dd558f9c6 100644 --- a/kernel-d-auth/auth-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/auth/starter/GunsAuthAutoConfiguration.java +++ b/kernel-d-auth/auth-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/auth/starter/GunsAuthAutoConfiguration.java @@ -29,6 +29,7 @@ import cn.stylefeng.roses.kernel.auth.api.cookie.SessionCookieCreator; import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander; import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi; import cn.stylefeng.roses.kernel.auth.api.password.PasswordTransferEncryptApi; +import cn.stylefeng.roses.kernel.auth.api.pojo.auth.PwdRsaSecretProperties; import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser; import cn.stylefeng.roses.kernel.auth.password.BcryptPasswordStoredEncrypt; import cn.stylefeng.roses.kernel.auth.password.RsaPasswordTransferEncrypt; @@ -43,6 +44,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import javax.annotation.Resource; import java.util.Set; @@ -55,6 +57,9 @@ import java.util.Set; @Configuration public class GunsAuthAutoConfiguration { + @Resource + private PwdRsaSecretProperties pwdRsaSecretProperties; + /** * jwt操作工具类的配置 * @@ -95,9 +100,7 @@ public class GunsAuthAutoConfiguration { @Bean @ConditionalOnMissingBean(PasswordTransferEncryptApi.class) public PasswordTransferEncryptApi passwordTransferEncryptApi() { - String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCytSVn3ff7eBJckAFYwgJjqE9Zq2uAL4g+hkfQqGALdT8NJKALFxNzeSD/xTBLAJrtALWbN1dvyktoVNPAuuzCZO1BxYZNaAU3IKFaj73OSPzca5SGY0ibMw0KvEPkC3sZQeqBqx+VqYAqan90BeG/r9p36Eb0wrshj5XmsFeo6QIDAQAB"; - String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALK1JWfd9/t4ElyQAVjCAmOoT1mra4AviD6GR9CoYAt1Pw0koAsXE3N5IP/FMEsAmu0AtZs3V2/KS2hU08C67MJk7UHFhk1oBTcgoVqPvc5I/NxrlIZjSJszDQq8Q+QLexlB6oGrH5WpgCpqf3QF4b+v2nfoRvTCuyGPleawV6jpAgMBAAECgYBS9fUfetQcUWl0vwVhBu/FA+WSYxnMsEQ3gm7kVsX/i7Zxi4cgnt3QxXKkSg5ZQzaov6OPIuncY7UOAhMrbZtq/Hh8atdTVC/Ng/X9Bomodplq/+KTe/vIfWW5rlQAnMNFVaidxhCVRlRHNusapmj2vYwsiyI9kXUJNHryxtFC4QJBANtQuh3dtd79t3MVaC3TUD/EsGBe9TB3Eykbgv0muannC2Oq8Ci4vIp0NSA+FNCoB8ctgfKJUdBS8RLVnYyu3RcCQQDQmY+AuAXEpO9SgcYeRnQSOU2OSuC1wLt1MRVpPTdvE3bfRnkVxMrK0n3YilQWkQzfkERSG4kRFLIw605xPWn/AkEAiw3vQ9p8Yyu5MiXDjTKrchMyxZfPnHATXQANmJcCJ0DQDtymMxuWp66wtIXIStgPPnGTMAVzM0Qzh/6bS0Tf9wJAWj+1yFjVlghNyoJ+9qZAnYnRNhjLM5dZAxDjVI65pwLi0SKqTHLB0hJThBYE32aODUNba7KiEJPFrEiBvZh2fQJARbboHuHT0PqD1UTJGgodHlaw48kreBU+twext/9/jIqvwmFF88BmQgssHGW/tn4E6Qy3+rCCNWreEReY0gATYw=="; - return new RsaPasswordTransferEncrypt(publicKey, privateKey); + return new RsaPasswordTransferEncrypt(pwdRsaSecretProperties.getPublicKey(), pwdRsaSecretProperties.getPrivateKey()); } /** diff --git a/kernel-d-auth/auth-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/auth/starter/GunsPasswordRsaPropAutoConfiguration.java b/kernel-d-auth/auth-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/auth/starter/GunsPasswordRsaPropAutoConfiguration.java new file mode 100644 index 000000000..b04d80ae3 --- /dev/null +++ b/kernel-d-auth/auth-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/auth/starter/GunsPasswordRsaPropAutoConfiguration.java @@ -0,0 +1,54 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.auth.starter; + +import cn.stylefeng.roses.kernel.auth.api.pojo.auth.PwdRsaSecretProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +/** + * 密码认证配置 + * + * @author fengshuonan + * @date 2022/10/16 15:33 + */ +@Configuration +public class GunsPasswordRsaPropAutoConfiguration { + + /** + * 密码加密传输的配置,RSA加密密钥对 + * + * @author fengshuonan + * @date 2022/10/16 15:34 + */ + @Bean + @ConfigurationProperties(prefix = "guns.password.rsa") + public PwdRsaSecretProperties pwdRsaSecretProperties() { + return new PwdRsaSecretProperties(); + } + +} diff --git a/kernel-d-auth/auth-spring-boot-starter/src/main/resources/META-INF/spring.factories b/kernel-d-auth/auth-spring-boot-starter/src/main/resources/META-INF/spring.factories index c74753131..d4a9b0a15 100644 --- a/kernel-d-auth/auth-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/kernel-d-auth/auth-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,4 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ cn.stylefeng.roses.kernel.auth.starter.GunsAuthAutoConfiguration,\ cn.stylefeng.roses.kernel.auth.starter.GunsSsoAutoConfiguration,\ - cn.stylefeng.roses.kernel.auth.starter.GunsAuthTokenCacheAutoConfiguration \ No newline at end of file + cn.stylefeng.roses.kernel.auth.starter.GunsAuthTokenCacheAutoConfiguration,\ + cn.stylefeng.roses.kernel.auth.starter.GunsPasswordRsaPropAutoConfiguration \ No newline at end of file