-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from zlt2000/dev
Dev
- Loading branch information
Showing
77 changed files
with
467 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...mons/zlt-common-core/src/main/java/com/central/common/context/LoginUserContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.central.common.context; | ||
|
||
import com.alibaba.ttl.TransmittableThreadLocal; | ||
import com.central.common.model.SysUser; | ||
|
||
/** | ||
* 登录用户holder | ||
* | ||
* @author zlt | ||
* @date 2022/6/26 | ||
* <p> | ||
* Blog: https://zlt2000.gitee.io | ||
* Github: https://github.com/zlt2000 | ||
*/ | ||
public class LoginUserContextHolder { | ||
private static final ThreadLocal<SysUser> CONTEXT = new TransmittableThreadLocal<>(); | ||
|
||
public static void setUser(SysUser user) { | ||
CONTEXT.set(user); | ||
} | ||
|
||
public static SysUser getUser() { | ||
return CONTEXT.get(); | ||
} | ||
|
||
public static void clear() { | ||
CONTEXT.remove(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
zlt-commons/zlt-common-core/src/main/java/com/central/common/utils/LoginUserUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.central.common.utils; | ||
|
||
import cn.hutool.core.util.StrUtil; | ||
import com.central.common.constant.SecurityConstants; | ||
import com.central.common.feign.UserService; | ||
import com.central.common.model.SysRole; | ||
import com.central.common.model.SysUser; | ||
import org.springframework.security.authentication.AnonymousAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* 获取当前登录人工具类 | ||
* | ||
* @author zlt | ||
* @version 1.0 | ||
* @date 2022/6/26 | ||
* <p> | ||
* Blog: https://zlt2000.gitee.io | ||
* Github: https://github.com/zlt2000 | ||
*/ | ||
public class LoginUserUtils { | ||
/** | ||
* 获取当前登录人 | ||
*/ | ||
public static SysUser getCurrentUser(HttpServletRequest request, boolean isFull) { | ||
SysUser user = null; | ||
|
||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
if (authentication != null && !(authentication instanceof AnonymousAuthenticationToken)) { | ||
Object principal = authentication.getPrincipal(); | ||
//客户端模式只返回一个clientId | ||
if (principal instanceof SysUser) { | ||
user = (SysUser)principal; | ||
} | ||
} | ||
if (user == null) { | ||
String userId = request.getHeader(SecurityConstants.USER_ID_HEADER); | ||
String username = request.getHeader(SecurityConstants.USER_HEADER); | ||
String roles = request.getHeader(SecurityConstants.ROLE_HEADER); | ||
|
||
if (StrUtil.isAllNotBlank(username, userId)) { | ||
if (isFull) { | ||
UserService userService = SpringUtil.getBean(UserService.class); | ||
user = userService.selectByUsername(username); | ||
} else { | ||
user = new SysUser(); | ||
user.setId(Long.valueOf(userId)); | ||
user.setUsername(username); | ||
} | ||
if (StrUtil.isNotBlank(roles)) { | ||
List<SysRole> sysRoleList = new ArrayList<>(); | ||
Arrays.stream(roles.split(",")).forEach(role -> { | ||
SysRole sysRole = new SysRole(); | ||
sysRole.setCode(role); | ||
sysRoleList.add(sysRole); | ||
}); | ||
user.setRoles(sysRoleList); | ||
} | ||
} | ||
} | ||
return user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.