| | |
| | | public class SecurityUtils { |
| | | |
| | | /** |
| | | * 获取用户信息 |
| | | * 获取当前登录用户信息 |
| | | */ |
| | | private static UserDetails getUserDetails() { |
| | | final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | |
| | | throw new BusinessException(ResponseStatusEnums.TOKEN_INVALID.getCode(), ResponseStatusEnums.TOKEN_INVALID.getMessage()); |
| | | } |
| | | Integer administratorIdentity = getAdministratorIdentity(); |
| | | if (AdministratorEnums.ADMIN.getCode().equals(administratorIdentity) || AdministratorEnums.INSPECT_CUSTOMER.getCode().equals(administratorIdentity)) { |
| | | if (AdministratorEnums.ADMIN.getCode().equals(administratorIdentity)) { |
| | | UserDetails userDetails = (UserDetails) authentication.getPrincipal(); |
| | | UserDetailsService userDetailsService = SpringContextHolder.getBean("adminDetailsService"); |
| | | return userDetailsService.loadUserByUsername(userDetails.getUsername()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取系统用户名称 登录名 |
| | | * 获取当前登录用户登录名 |
| | | * |
| | | * @return 系统用户名称 |
| | | * @return 当前登录用户登录名 |
| | | */ |
| | | public static String getUsername() { |
| | | final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取系统用户id |
| | | * 获取当前登录账号的id |
| | | * |
| | | * @return 系统用户id |
| | | * @return 当前登录账号的id |
| | | */ |
| | | public static Long getUserId() { |
| | | SecurityProperties properties = SpringContextHolder.getBean(SecurityProperties.class); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取客户账号的id |
| | | * @return |
| | | */ |
| | | public static Long getClientId() { |
| | | Integer administratorIdentity = SecurityUtils.getAdministratorIdentity(); |
| | | if (AdministratorEnums.CUSTOMER.getCode().equals(administratorIdentity)) { |
| | | return SecurityUtils.getUserId(); |
| | | } |
| | | return null; |
| | | } |
| | | } |