From 1c213527ba512334d1b43fa11f1c7992c1d70b3d Mon Sep 17 00:00:00 2001 From: JerryMa1024 Date: Thu, 23 Jul 2020 20:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0IAM=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- diboot-docs/guide/diboot-iam/开始使用.md | 2 ++ diboot-docs/guide/diboot-iam/自定义扩展.md | 27 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/diboot-docs/guide/diboot-iam/开始使用.md b/diboot-docs/guide/diboot-iam/开始使用.md index 2164433..e5044dd 100644 --- a/diboot-docs/guide/diboot-iam/开始使用.md +++ b/diboot-docs/guide/diboot-iam/开始使用.md @@ -18,6 +18,8 @@ compile("com.diboot:diboot-iam-base-spring-boot-starter:{latestVersion}") > 如果使用diboot-devtools,还需要引入devtools相关依赖,可一键生成iam-base相关的controller。 +注: iam初始化的账号密码为: admin/123456 ,启动成功后请及时修改密码。 + ## 2、参数配置: * 注解配置: diff --git a/diboot-docs/guide/diboot-iam/自定义扩展.md b/diboot-docs/guide/diboot-iam/自定义扩展.md index 5f75c36..96b5943 100644 --- a/diboot-docs/guide/diboot-iam/自定义扩展.md +++ b/diboot-docs/guide/diboot-iam/自定义扩展.md @@ -10,25 +10,44 @@ MyAuthCredential credential = new MyAuthCredential(); String authtoken = AuthServiceFactory.getAuthService("WX_CP").applyToken(credential); ~~~ -## 2、替换用户类型 +## 2、替换用户类型或扩展多种用户类型 默认的用户实体为IamUser,获取当前登录用户对象: ~~~java IamUser currentUser = IamSecurityUtils.getCurrentUser(); ~~~ 如果预置属性如果不能满足业务场景需要,可替换用户为你的实体: +* 首先在登录的方法中,生成token前传入当前用户类型: +(如果有多种用户类型共用登录接口,可以从前端登录页传入"用户类型值") ~~~java MyAuthCredential credential = new MyAuthCredential(); -credential.setUserTypeClass(Employee.class); // 替换用户类型为自定义 +credential.setUserTypeClass(Employee.class); // 用户类型为自定义 String authtoken = AuthServiceFactory.getAuthService("WX_CP").applyToken(credential); ~~~ -获取用户对象改为: +获取用户对象相关代码改为: ~~~java Employee currentUser = IamSecurityUtils.getCurrentUser(); ~~~ +或多种用户: +~~~java +// 获取当前登录用户抽象对象 +BaseLoginUser currentUser = IamSecurityUtils.getCurrentUser(); +// 查询用户角色 +IamRoleVO roleVO = null; +if(currentUser instanceof IamUser){ + IamUser user = (IamUser) currentUser; + // 角色权限数据 + roleVO = iamUserService.buildRoleVo4FrontEnd(user); +} +else if(currentUser instanceof Employee){ + List roleVOList = iamUserRoleService.getAllRoleVOList(currentUser); + roleVO = IamHelper.buildRoleVo4FrontEnd(roleVOList); +} +... +~~~ ## 3、替换缓存Manager 组件默认缓存类为shiro的内存缓存实现:MemoryConstrainedCacheManager,如果需要替换为redis等自定义缓存, -需要创建缓存实现类实现CacheManager接口,并配置参数diboot.iam.cache-manager-class为你的缓存类。 +需要创建缓存实现类实现CacheManager接口 (可以参考MemoryConstrainedCacheManager的源码),并配置参数diboot.iam.cache-manager-class为你的缓存类。 ``` diboot.iam.cache-manager-class=com.xxx.MyCacheManager ```