feat: layui前端应用管理增加“令牌类型”配置
This commit is contained in:
+2
-2
@@ -65,8 +65,8 @@ public class SysUserController {
|
||||
*/
|
||||
@Operation(summary = "根据access_token当前登录用户")
|
||||
@GetMapping("/users/current")
|
||||
public Result<LoginAppUser> getLoginAppUser() {
|
||||
return Result.succeed(LoginUserUtils.getCurrentUser(true));
|
||||
public Result<SysUser> getLoginAppUser() {
|
||||
return Result.succeed(LoginUserUtils.getCurrentSysUser());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ import java.io.Serializable;
|
||||
public class ClientDto implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String id;
|
||||
private String clientId;
|
||||
/**
|
||||
* 应用名称
|
||||
@@ -37,7 +38,7 @@ public class ClientDto implements Serializable {
|
||||
private String autoapprove = "true";
|
||||
|
||||
/**
|
||||
* token格式: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))
|
||||
* 令牌类型: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))
|
||||
*/
|
||||
private String tokenFormat = "reference";
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import lombok.Setter;
|
||||
@Getter
|
||||
public class ResourceServerProperties {
|
||||
/**
|
||||
* token格式:
|
||||
* 令牌类型:
|
||||
* - redis: 通过 redis 来验证
|
||||
* - inMemory: 通过本地内存来验证
|
||||
* - jwt: 自包含令牌,自己解析内容
|
||||
|
||||
+14
-2
@@ -50,8 +50,7 @@ public class LoginUserUtils {
|
||||
|
||||
if (StrUtil.isAllNotBlank(username, userId)) {
|
||||
if (isFull) {
|
||||
UserService userService = SpringUtil.getBean(UserService.class);
|
||||
SysUser sysUser = userService.findByUsername(username);
|
||||
SysUser sysUser = getSysUser(username);
|
||||
if (sysUser != null) {
|
||||
return getLoginAppUser(sysUser);
|
||||
}
|
||||
@@ -77,6 +76,14 @@ public class LoginUserUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SysUser getCurrentSysUser() {
|
||||
LoginAppUser appUser = getCurrentUser(false);
|
||||
if (appUser != null) {
|
||||
return getSysUser(appUser.getUsername());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登陆的用户对象
|
||||
*/
|
||||
@@ -151,4 +158,9 @@ public class LoginUserUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static SysUser getSysUser(String username) {
|
||||
UserService userService = SpringUtil.getBean(UserService.class);
|
||||
return userService.findByUsername(username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ CREATE TABLE `oauth_client_details` (
|
||||
`create_time` datetime(0) NULL DEFAULT NULL,
|
||||
`update_time` datetime(0) NULL DEFAULT NULL,
|
||||
`client_name` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '' COMMENT '应用名称',
|
||||
`token_format` varchar(10) not null DEFAULT 'reference' COMMENT 'token格式: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))',
|
||||
`token_format` varchar(20) not null DEFAULT 'reference' COMMENT 'token格式: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))',
|
||||
`creator_id` int(11) COMMENT '创建人id',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
------------更新语句
|
||||
Use `oauth-center`;
|
||||
alter table oauth_client_details add token_format varchar(10) not null DEFAULT 'reference' COMMENT 'token格式: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))';
|
||||
alter table oauth_client_details add token_format varchar(20) not null DEFAULT 'reference' COMMENT 'token格式: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))';
|
||||
alter table oauth_client_details drop column support_id_token;
|
||||
alter table oauth_client_details drop column id_token_validity;
|
||||
@@ -33,7 +33,7 @@ public class Client extends SuperEntity {
|
||||
private String additionalInformation = "{}";
|
||||
private String autoapprove = "true";
|
||||
/**
|
||||
* token格式: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))
|
||||
* 令牌类型: reference 引用令牌(不透明), self-contained 自包含令牌(jwt))
|
||||
*/
|
||||
private String tokenFormat = "reference";
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class RedisTokensServiceImpl implements ITokensService {
|
||||
if (authorization != null) {
|
||||
OAuth2AccessToken accessToken = authorization.getAccessToken().getToken();
|
||||
if (accessToken != null && accessToken.getExpiresAt() != null) {
|
||||
tokenVo.setExpiration(Date.from(accessToken.getExpiresAt().plus(8, ChronoUnit.HOURS)));
|
||||
tokenVo.setExpiration(Date.from(accessToken.getExpiresAt()));
|
||||
}
|
||||
tokenVo.setUsername(authorization.getPrincipalName());
|
||||
tokenVo.setClientId(authorization.getRegisteredClientId());
|
||||
|
||||
@@ -30,7 +30,8 @@ public class RegisteredClientService {
|
||||
|
||||
public void saveClient(Client client) throws Exception {
|
||||
clientService.saveClient(client);
|
||||
redisson.getBucket(clientRedisKey(client.getClientId())).set(client);
|
||||
ClientDto clientDto = BeanUtil.copyProperties(client, ClientDto.class);
|
||||
redisson.getBucket(clientRedisKey(client.getClientId())).set(clientDto);
|
||||
}
|
||||
|
||||
public PageResult<ClientDto> listClient(Map<String, Object> params, boolean isPage) {
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
, scope, authorized_grant_types, autoapprove
|
||||
, access_token_validity accessTokenValiditySeconds
|
||||
, refresh_token_validity refreshTokenValiditySeconds
|
||||
, support_id_token, refresh_token_validity
|
||||
, token_format
|
||||
from oauth_client_details
|
||||
<include refid="where"/>
|
||||
</select>
|
||||
|
||||
@@ -87,16 +87,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">支持ID令牌</label>
|
||||
<label class="layui-form-label">令牌类型</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="supportIdToken" value="true" title="是" checked/>
|
||||
<input type="radio" name="supportIdToken" value="false" title="否"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">ID时效(s)</label>
|
||||
<div class="layui-input-block">
|
||||
<input name="idTokenValiditySeconds" lay-verify="number" type="text" class="layui-input" maxlength="20" value="60"/>
|
||||
<input type="radio" name="tokenFormat" value="reference" title="引用令牌(不透明)" checked/>
|
||||
<input type="radio" name="tokenFormat" value="self-contained" title="自包含令牌(jwt)"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item model-form-footer">
|
||||
@@ -134,10 +128,9 @@
|
||||
}},
|
||||
{field: 'accessTokenValiditySeconds',width:130, sort: true, title: '令牌时效(s)'},
|
||||
{field: 'refreshTokenValiditySeconds',width:130, sort: true, title: '刷新时效(s)'},
|
||||
{width:120, sort: true, title: '支持ID令牌', templet:function (d) {
|
||||
return d.supportIdToken ? "是" : "否"
|
||||
{width:150, sort: true, title: '令牌类型', templet:function (d) {
|
||||
return d.tokenFormat == 'reference' ? "引用令牌" : "自包含令牌"
|
||||
}},
|
||||
{field: 'idTokenValiditySeconds',width:130, sort: true, title: 'ID时效(s)'},
|
||||
{fixed: 'right', align: 'center',width:150, toolbar: '#app-table-bar', title: '操作'}
|
||||
]]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user