Commit d7fa84c9 authored by maqing's avatar maqing

RSA密码加密

parent 9da726ae
...@@ -25,14 +25,22 @@ public class AuthController { ...@@ -25,14 +25,22 @@ public class AuthController {
@PostMapping("/token") @PostMapping("/token")
@SneakyThrows @SneakyThrows
public Result<OAuth2AccessToken> postAccessToken(Principal principal, @RequestParam Map<String, String> parameters) { public Result<OAuth2AccessToken> postAccessToken(Principal principal, @RequestParam Map<String, String> parameters) {
// String password = parameters.get("password"); String password = parameters.get("password");
// String decrypt = CsoftSecurityUtil.decrypt(password); String decrypt = CsoftSecurityUtil.decrypt(password);
// parameters.put("password", decrypt); parameters.put("password", decrypt);
OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody(); OAuth2AccessToken oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
return Result.success(oAuth2AccessToken); return Result.success(oAuth2AccessToken);
} }
/**
* 获取公钥
* @return
*/
@GetMapping("/genKeyPair")
public Result<String> genKeyPair() {
Map keyMap = CsoftSecurityUtil.genKeyPair();
return Result.success(keyMap.get(0).toString());
}
......
...@@ -33,7 +33,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -33,7 +33,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll() .authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()
.and() .and()
.authorizeRequests() .authorizeRequests()
.antMatchers("/getPublicKey","/oauth/logout","/genKeyPair").permitAll() .antMatchers("/getPublicKey","/oauth/token","/genKeyPair","/oauth/genKeyPair").permitAll()
.anyRequest().authenticated(); .anyRequest().authenticated();
} }
......
...@@ -32,7 +32,7 @@ public class CsoftSecurityUtil { ...@@ -32,7 +32,7 @@ public class CsoftSecurityUtil {
//生成公钥和私钥 //生成公钥和私钥
genKeyPair(); genKeyPair();
//加密字符串 //加密字符串
String message = "df723820"; String message = "Hg123admin";
System.out.println("随机生成的公钥为:" + keyMap.get(0)); System.out.println("随机生成的公钥为:" + keyMap.get(0));
System.out.println("随机生成的私钥为:" + keyMap.get(1)); System.out.println("随机生成的私钥为:" + keyMap.get(1));
String messageEn = encrypt(message, keyMap.get(0)); String messageEn = encrypt(message, keyMap.get(0));
......
...@@ -51,7 +51,7 @@ public class ResourceServerConfig { ...@@ -51,7 +51,7 @@ public class ResourceServerConfig {
http.oauth2ResourceServer().jwt() http.oauth2ResourceServer().jwt()
.jwtAuthenticationConverter(jwtAuthenticationConverter()); .jwtAuthenticationConverter(jwtAuthenticationConverter());
http.authorizeExchange() http.authorizeExchange()
.pathMatchers("/api/oauth/token", "/oauth/token").permitAll() .pathMatchers("/api/oauth/token", "/oauth/token","/oauth/genKeyPair","/api/oauth/genKeyPair").permitAll()
.anyExchange().access(authorizationManager) .anyExchange().access(authorizationManager)
.and() .and()
.exceptionHandling() .exceptionHandling()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment