Browse Source

终端设置新增明文安全码

tags/v2.2
RuoYi 4 years ago
parent
commit
1305507bf4
  1. 3
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysClientDetailsController.java
  2. 16
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysClientDetails.java
  3. 3
      ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysClientDetailsServiceImpl.java
  4. 6
      ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysClientDetailsMapper.xml
  5. 8
      ruoyi-ui/src/views/system/client/index.vue
  6. 5
      sql/ry_20200822.sql

3
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysClientDetailsController.java

@ -17,7 +17,6 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo; import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.SysClientDetails; import com.ruoyi.system.domain.SysClientDetails;
import com.ruoyi.system.service.ISysClientDetailsService; import com.ruoyi.system.service.ISysClientDetailsService;
@ -68,7 +67,6 @@ public class SysClientDetailsController extends BaseController
{ {
return AjaxResult.error("新增终端'" + clientId + "'失败,编号已存在"); return AjaxResult.error("新增终端'" + clientId + "'失败,编号已存在");
} }
sysClientDetails.setClientSecret(SecurityUtils.encryptPassword(sysClientDetails.getClientSecret()));
return toAjax(sysClientDetailsService.insertSysClientDetails(sysClientDetails)); return toAjax(sysClientDetailsService.insertSysClientDetails(sysClientDetails));
} }
@ -80,7 +78,6 @@ public class SysClientDetailsController extends BaseController
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody SysClientDetails sysClientDetails) public AjaxResult edit(@RequestBody SysClientDetails sysClientDetails)
{ {
sysClientDetails.setClientSecret(SecurityUtils.encryptPassword(sysClientDetails.getClientSecret()));
return toAjax(sysClientDetailsService.updateSysClientDetails(sysClientDetails)); return toAjax(sysClientDetailsService.updateSysClientDetails(sysClientDetails));
} }

16
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysClientDetails.java

@ -68,6 +68,11 @@ public class SysClientDetails extends BaseEntity
*/ */
private String autoapprove; private String autoapprove;
/**
* 终端明文安全码
*/
private String originSecret;
public String getClientId() public String getClientId()
{ {
return clientId; return clientId;
@ -178,6 +183,16 @@ public class SysClientDetails extends BaseEntity
this.autoapprove = autoapprove; this.autoapprove = autoapprove;
} }
public String getOriginSecret()
{
return originSecret;
}
public void setOriginSecret(String originSecret)
{
this.originSecret = originSecret;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@ -192,6 +207,7 @@ public class SysClientDetails extends BaseEntity
.append("refreshTokenValidity", getRefreshTokenValidity()) .append("refreshTokenValidity", getRefreshTokenValidity())
.append("additionalInformation", getAdditionalInformation()) .append("additionalInformation", getAdditionalInformation())
.append("autoapprove", getAutoapprove()) .append("autoapprove", getAutoapprove())
.append("originSecret", getOriginSecret())
.toString(); .toString();
} }
} }

3
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysClientDetailsServiceImpl.java

@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.SysClientDetails; import com.ruoyi.system.domain.SysClientDetails;
import com.ruoyi.system.mapper.SysClientDetailsMapper; import com.ruoyi.system.mapper.SysClientDetailsMapper;
import com.ruoyi.system.service.ISysClientDetailsService; import com.ruoyi.system.service.ISysClientDetailsService;
@ -53,6 +54,7 @@ public class SysClientDetailsServiceImpl implements ISysClientDetailsService
@Override @Override
public int insertSysClientDetails(SysClientDetails sysClientDetails) public int insertSysClientDetails(SysClientDetails sysClientDetails)
{ {
sysClientDetails.setClientSecret(SecurityUtils.encryptPassword(sysClientDetails.getOriginSecret()));
return sysClientDetailsMapper.insertSysClientDetails(sysClientDetails); return sysClientDetailsMapper.insertSysClientDetails(sysClientDetails);
} }
@ -66,6 +68,7 @@ public class SysClientDetailsServiceImpl implements ISysClientDetailsService
@CacheEvict(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#sysClientDetails.clientId") @CacheEvict(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#sysClientDetails.clientId")
public int updateSysClientDetails(SysClientDetails sysClientDetails) public int updateSysClientDetails(SysClientDetails sysClientDetails)
{ {
sysClientDetails.setClientSecret(SecurityUtils.encryptPassword(sysClientDetails.getOriginSecret()));
return sysClientDetailsMapper.updateSysClientDetails(sysClientDetails); return sysClientDetailsMapper.updateSysClientDetails(sysClientDetails);
} }

6
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysClientDetailsMapper.xml

@ -16,10 +16,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="refreshTokenValidity" column="refresh_token_validity" /> <result property="refreshTokenValidity" column="refresh_token_validity" />
<result property="additionalInformation" column="additional_information" /> <result property="additionalInformation" column="additional_information" />
<result property="autoapprove" column="autoapprove" /> <result property="autoapprove" column="autoapprove" />
<result property="originSecret" column="origin_secret" />
</resultMap> </resultMap>
<sql id="selectSysClientDetailsVo"> <sql id="selectSysClientDetailsVo">
select client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove from sys_oauth_client_details select client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove, origin_secret from sys_oauth_client_details
</sql> </sql>
<select id="selectSysClientDetailsList" parameterType="SysClientDetails" resultMap="SysClientDetailsResult"> <select id="selectSysClientDetailsList" parameterType="SysClientDetails" resultMap="SysClientDetailsResult">
@ -48,6 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="refreshTokenValidity != null">refresh_token_validity,</if> <if test="refreshTokenValidity != null">refresh_token_validity,</if>
<if test="additionalInformation != null">additional_information,</if> <if test="additionalInformation != null">additional_information,</if>
<if test="autoapprove != null">autoapprove,</if> <if test="autoapprove != null">autoapprove,</if>
<if test="originSecret != null">origin_secret,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="clientId != null">#{clientId},</if> <if test="clientId != null">#{clientId},</if>
@ -61,6 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="refreshTokenValidity != null">#{refreshTokenValidity},</if> <if test="refreshTokenValidity != null">#{refreshTokenValidity},</if>
<if test="additionalInformation != null">#{additionalInformation},</if> <if test="additionalInformation != null">#{additionalInformation},</if>
<if test="autoapprove != null ">#{autoapprove},</if> <if test="autoapprove != null ">#{autoapprove},</if>
<if test="originSecret != null ">#{originSecret},</if>
</trim> </trim>
</insert> </insert>
@ -77,6 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="refreshTokenValidity != null">refresh_token_validity = #{refreshTokenValidity},</if> <if test="refreshTokenValidity != null">refresh_token_validity = #{refreshTokenValidity},</if>
<if test="additionalInformation != null">additional_information = #{additionalInformation},</if> <if test="additionalInformation != null">additional_information = #{additionalInformation},</if>
<if test="autoapprove != null">autoapprove = #{autoapprove},</if> <if test="autoapprove != null">autoapprove = #{autoapprove},</if>
<if test="originSecret != null">origin_secret = #{originSecret},</if>
</trim> </trim>
where client_id = #{clientId} where client_id = #{clientId}
</update> </update>

8
ruoyi-ui/src/views/system/client/index.vue

@ -52,7 +52,7 @@
<el-table v-loading="loading" :data="clientList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="clientList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="clientId" /> <el-table-column label="编号" align="center" prop="clientId" />
<el-table-column label="安全码" align="center" prop="clientSecret" :show-overflow-tooltip="true" /> <el-table-column label="安全码" align="center" prop="originSecret" :show-overflow-tooltip="true" />
<el-table-column label="授权范围" align="center" prop="scope" /> <el-table-column label="授权范围" align="center" prop="scope" />
<el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :show-overflow-tooltip="true" /> <el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :show-overflow-tooltip="true" />
<el-table-column label="令牌时效" align="center" prop="accessTokenValidity" /> <el-table-column label="令牌时效" align="center" prop="accessTokenValidity" />
@ -91,8 +91,8 @@
<el-form-item label="编号" prop="clientId"> <el-form-item label="编号" prop="clientId">
<el-input v-model="form.clientId" placeholder="请输入编号" :disabled="!isAdd" /> <el-input v-model="form.clientId" placeholder="请输入编号" :disabled="!isAdd" />
</el-form-item> </el-form-item>
<el-form-item label="安全码" prop="clientSecret"> <el-form-item label="安全码" prop="originSecret">
<el-input v-model="form.clientSecret" placeholder="请输入安全码" /> <el-input v-model="form.originSecret" placeholder="请输入安全码" />
</el-form-item> </el-form-item>
<el-form-item label="授权范围" prop="scope"> <el-form-item label="授权范围" prop="scope">
<el-input v-model="form.scope" placeholder="请输入授权范围" /> <el-input v-model="form.scope" placeholder="请输入授权范围" />
@ -155,7 +155,7 @@ export default {
clientId: [ clientId: [
{ required: true, message: "编号不能为空", trigger: "blur" } { required: true, message: "编号不能为空", trigger: "blur" }
], ],
clientSecret: [ originSecret: [
{ required: true, message: "安全码不能为空", trigger: "blur" } { required: true, message: "安全码不能为空", trigger: "blur" }
], ],
scope: [ scope: [

5
sql/ry_20200822.sql

@ -696,11 +696,12 @@ create table sys_oauth_client_details (
refresh_token_validity int(11) default null comment '设定终端的refresh_token的有效时间值(秒)', refresh_token_validity int(11) default null comment '设定终端的refresh_token的有效时间值(秒)',
additional_information varchar(4096) default null comment '附加信息', additional_information varchar(4096) default null comment '附加信息',
autoapprove tinyint(4) default null comment '是否登录时跳过授权', autoapprove tinyint(4) default null comment '是否登录时跳过授权',
origin_secret varchar(255) not null comment '终端明文安全码',
primary key (client_id) primary key (client_id)
) engine=innodb auto_increment=1 comment = '终端配置表'; ) engine=innodb auto_increment=1 comment = '终端配置表';
-- ---------------------------- -- ----------------------------
-- 初始化-终端配置表数据 -- 初始化-终端配置表数据
-- ---------------------------- -- ----------------------------
insert into sys_oauth_client_details values ('web', '', '$2a$10$y2hKeELx.z3Sbz.kjQ4wmuiIsv5ZSbUQ1ov4BwFH6ccirP8Knp1uq', 'server', 'password,refresh_token', '', NULL, 3600, 7200, NULL, NULL); insert into sys_oauth_client_details values ('web', '', '$2a$10$y2hKeELx.z3Sbz.kjQ4wmuiIsv5ZSbUQ1ov4BwFH6ccirP8Knp1uq', 'server', 'password,refresh_token', '', NULL, 3600, 7200, NULL, NULL, '123456');
insert into sys_oauth_client_details values ('ruoyi', '', '$2a$10$y2hKeELx.z3Sbz.kjQ4wmuiIsv5ZSbUQ1ov4BwFH6ccirP8Knp1uq', 'server', 'password,client_credentials,refresh_token', '', NULL, 3600, 7200, NULL, NULL); insert into sys_oauth_client_details values ('ruoyi', '', '$2a$10$y2hKeELx.z3Sbz.kjQ4wmuiIsv5ZSbUQ1ov4BwFH6ccirP8Knp1uq', 'server', 'password,client_credentials,refresh_token', '', NULL, 3600, 7200, NULL, NULL, '123456');
Loading…
Cancel
Save