Browse Source

新增springSercuriyt 密码加密测试类

tags/v2.4.1
xiaoying 1 year ago
parent
commit
c47704922f
7 changed files with 70 additions and 5 deletions
  1. +5
    -0
      tuoheng_oidc_admin/pom.xml
  2. +12
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/TuohengOidcAdminApplication.java
  3. +39
    -0
      tuoheng_oidc_admin/src/test/java/com/tuoheng/passwordTest.java
  4. +4
    -0
      tuoheng_oidc_admin/target/classes/application-prod.yml
  5. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/TuohengOidcAdminApplication.class
  6. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class
  7. +10
    -5
      tuoheng_oidc_admin/target/classes/mapper/TenantMapper.xml

+ 5
- 0
tuoheng_oidc_admin/pom.xml View File

@@ -123,6 +123,11 @@
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>


+ 12
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/TuohengOidcAdminApplication.java View File

@@ -2,6 +2,9 @@ package com.tuoheng;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootApplication
public class TuohengOidcAdminApplication {
@@ -11,4 +14,13 @@ public class TuohengOidcAdminApplication {
System.out.println("TuoHeng-Oidc-Admin 启动成功~");
}

/**
* 注册bean -> 测试 spring security 加密获取密码密文
* @return
*/
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}

}

+ 39
- 0
tuoheng_oidc_admin/src/test/java/com/tuoheng/passwordTest.java View File

@@ -0,0 +1,39 @@
package com.tuoheng;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.test.context.junit4.SpringRunner;

/**
* @Author xiaoying
* @Date 2023/2/21 11:12
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class passwordTest {

@Autowired
PasswordEncoder passwordEncoder;
/*
明文,加密成密文
*/
@Test
public void test1() {
String password = "123";
String encode = "{bcrypt}" + passwordEncoder.encode(password);
System.out.println(encode);
//$2a$10$K.gyCkGOvQAbBQg.HAai1O5cvE./sVWLCfiLURhCVjhHVt1SSOAi6
}

//判断明文和密文是否一致
@Test
public void test2() {
String password = "123";
String encode = "{bcrypt}$2a$10$apjRNzmuDrDx2DiGAaVaZeM/HzyxMU3bOEWpZwYsbp5nc9jv1A7FK";
boolean matches = passwordEncoder.matches(password, encode);
System.out.println(matches);
}
}

+ 4
- 0
tuoheng_oidc_admin/target/classes/application-prod.yml View File

@@ -65,3 +65,7 @@ spring:
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接
min-idle: 1 # 连接池中的最小空闲连接
# 自定义配置
tuoheng:
#airport配置地址
airport-url: https://airport.t-aaron.com

BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/TuohengOidcAdminApplication.class View File


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class View File


+ 10
- 5
tuoheng_oidc_admin/target/classes/mapper/TenantMapper.xml View File

@@ -3,8 +3,10 @@
<mapper namespace="com.tuoheng.mapper.TenantMapper">

<insert id="insertTenant" parameterType="com.tuoheng.model.po.TenantPo" keyProperty="id" useGeneratedKeys="true">
INSERT INTO t_tenant (user_id, remark, `code`, `name`,province_code,province_name,city_code,city_name,district_code,district_name)
VALUES (#{userId}, #{remark}, #{code}, #{name},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName})
INSERT INTO t_tenant (user_id, remark, `code`, `name`, province_code, province_name, city_code, city_name,
district_code, district_name)
VALUES (#{userId}, #{remark}, #{code}, #{name}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName},
#{districtCode}, #{districtName})
</insert>
<update id="updateById" parameterType="com.tuoheng.model.po.TenantPo">
update t_tenant
@@ -15,7 +17,7 @@
<if test="enabled != null">
enabled = #{enabled},
</if>
<if test="provinceCode != null and provinceCode !=''">
<!--<if test="provinceCode != null and provinceCode !=''">
province_code = #{provinceCode},
</if>
<if test="provinceName != null and provinceName !=''">
@@ -32,7 +34,9 @@
</if>
<if test="districtName != null and districtName !=''">
district_name = #{districtName},
</if>
</if>-->
province_code=#{provinceCode},province_name=#{provinceName},city_code =#{cityCode},city_name
=#{cityName},district_code =#{districtCode},district_name =#{districtName}
</set>
where id = #{id}
</update>
@@ -42,7 +46,8 @@
where code = #{code}
</select>
<select id="findList" resultType="com.tuoheng.model.po.TenantPo">
SELECT id, user_id, remark,enabled, code, name
SELECT id, user_id, remark,enabled, code,
name,province_code,province_name,city_code,city_name,district_code,district_name
FROM t_tenant
WHERE enabled = 1
<if test="query.name != null and query.name != ''">

Loading…
Cancel
Save