登录参数与登录后的扩展数据中可传入扩展数据

This commit is contained in:
yangzhao635226@163.com 2020-07-23 16:30:18 +08:00
parent 1e71b5024a
commit 12997246d8
5 changed files with 18 additions and 5 deletions

View File

@ -19,6 +19,7 @@ import com.diboot.core.vo.KeyValue;
import com.diboot.iam.entity.IamRole;
import java.util.List;
import java.util.Map;
/**
* IAM扩展接口
@ -32,9 +33,10 @@ public interface IamExtensible {
* 获取用户扩展对象 (如当前岗位)
* @param userType
* @param userId
* @param extObj 登录扩展信息
* @return
*/
KeyValue getUserExtentionObj(String userType, Long userId);
KeyValue getUserExtentionObj(String userType, Long userId, Map<String, Object> extObj);
/**
* 获取可扩展的角色

View File

@ -130,8 +130,10 @@ public class PwdAuthServiceImpl implements AuthService {
private BaseJwtAuthToken initBaseJwtAuthToken(AuthCredential credential){
BaseJwtAuthToken token = new BaseJwtAuthToken(getAuthType(), credential.getUserTypeClass());
// 设置账号密码
token.setAuthAccount(credential.getAuthAccount()).setAuthSecret(credential.getAuthSecret());
token.setRememberMe(credential.isRememberMe());
token.setAuthAccount(credential.getAuthAccount())
.setAuthSecret(credential.getAuthSecret())
.setRememberMe(credential.isRememberMe())
.setExtObj(credential.getExtObj());
// 生成token
return token.generateAuthtoken(getExpiresInMinutes());
}

View File

@ -22,6 +22,7 @@ import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Map;
/**
* 登录凭证
@ -50,6 +51,12 @@ public abstract class AuthCredential implements Serializable {
* 记住我
*/
private boolean rememberMe;
/**
* 扩展属性
*/
private Map<String, Object> extObj;
/**
* 账号
* @return

View File

@ -25,6 +25,8 @@ import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.RememberMeAuthenticationToken;
import java.util.Map;
/**
* @author Yangzhao
* @version v2.0
@ -59,7 +61,7 @@ public class BaseJwtAuthToken implements RememberMeAuthenticationToken {
/**
* 扩展属性
*/
private KeyValue extObj;
private Map<String, Object> extObj;
/**authz token*/
private String authtoken;

View File

@ -107,7 +107,7 @@ public class BaseJwtRealm extends AuthorizingRealm {
throw new AuthenticationException("用户不存在");
}
if(iamUserRoleService.getIamExtensible() != null){
KeyValue extentionObj = iamUserRoleService.getIamExtensible().getUserExtentionObj(jwtToken.getUserTypeClass().getSimpleName(), account.getUserId());
KeyValue extentionObj = iamUserRoleService.getIamExtensible().getUserExtentionObj(jwtToken.getUserTypeClass().getSimpleName(), account.getUserId(), jwtToken.getExtObj());
if(extentionObj != null){
loginUser.setExtentionObj(extentionObj);
}