【7.2.5】更新登录密码的RSA加密

pull/40/MERGE
fengshuonan 2022-10-16 15:48:02 +08:00
parent e9bee2f646
commit 0c4787a045
5 changed files with 123 additions and 6 deletions

View File

@ -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.
*
* GunsAPACHE 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);
}
}

View File

@ -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);
}

View File

@ -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());
}
/**

View File

@ -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.
*
* GunsAPACHE 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();
}
}

View File

@ -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
cn.stylefeng.roses.kernel.auth.starter.GunsAuthTokenCacheAutoConfiguration,\
cn.stylefeng.roses.kernel.auth.starter.GunsPasswordRsaPropAutoConfiguration