14 files modified
2 files added
| | |
| | | } |
| | | bladeUserDetails = new BladeUserDetails(user.getId(), |
| | | tenantId, userInfo.getOauthId(), user.getName(), user.getRealName(), user.getDeptId(), user.getPostId(), user.getRoleId(), Func.join(userInfo.getRoles()), Func.toStr(userOauth.getAvatar(), TokenUtil.DEFAULT_AVATAR), |
| | | userOauth.getUsername(), AuthConstant.ENCRYPT + user.getPassword(), detail, true, true, true, true, |
| | | userOauth.getClientIds(),userOauth.getUsername(), AuthConstant.ENCRYPT + user.getPassword(), detail, true, true, true, true, |
| | | AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(userInfo.getRoles()))); |
| | | } else { |
| | | throw new InvalidGrantException("social grant failure, feign client return error"); |
| | |
| | | String token = JwtUtil.getToken(auth); |
| | | Claims claims = JwtUtil.parseJWT(token); |
| | | if (!StringUtils.isBlank(token) && null!=claims) { |
| | | SecurityContext context = SecurityContextHolder.getContext(); |
| | | //判断 Token 状态 |
| | | String tenantId = String.valueOf(claims.get(TokenConstant.TENANT_ID)); |
| | | String userId = String.valueOf(claims.get(TokenConstant.USER_ID)); |
| | |
| | | */ |
| | | private final String avatar; |
| | | /** |
| | | * 客户端id |
| | | */ |
| | | private final String clients; |
| | | /** |
| | | * 用户详情 |
| | | */ |
| | | private final Kv detail; |
| | | |
| | | public BladeUserDetails(Long userId, String tenantId, String oauthId, String name, String realName, String deptId, String postId, String roleId, String roleName, String avatar, String username, String password, Kv detail, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) { |
| | | public BladeUserDetails(Long userId, String tenantId, String oauthId, String name, String realName, String deptId, String postId, String roleId, String roleName, String avatar,String clients,String username, String password, Kv detail, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) { |
| | | super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); |
| | | this.userId = userId; |
| | | this.tenantId = tenantId; |
| | |
| | | this.roleId = roleId; |
| | | this.roleName = roleName; |
| | | this.avatar = avatar; |
| | | this.clients = clients; |
| | | this.detail = detail; |
| | | } |
| | | |
| | |
| | | delFailCount(tenantId, username); |
| | | return new BladeUserDetails(user.getId(), |
| | | user.getTenantId(), StringPool.EMPTY, user.getName(), user.getRealName(), user.getDeptId(), user.getPostId(), user.getRoleId(), Func.join(userInfo.getRoles()), Func.toStr(user.getAvatar(), TokenUtil.DEFAULT_AVATAR), |
| | | username, AuthConstant.ENCRYPT + user.getPassword(), userInfo.getDetail(), true, true, true, true, |
| | | user.getClientIds(),username, AuthConstant.ENCRYPT + user.getPassword(), userInfo.getDetail(), true, true, true, true, |
| | | AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(userInfo.getRoles()))); |
| | | } else { |
| | | throw new UsernameNotFoundException("没有找到用户信息"); |
| | |
| | | info.put(TokenUtil.AVATAR, principal.getAvatar()); |
| | | info.put(TokenUtil.DETAIL, principal.getDetail()); |
| | | info.put(TokenUtil.LICENSE, TokenUtil.LICENSE_NAME); |
| | | // 用户绑定的client_id |
| | | info.put("client_ids", principal.getClients()); |
| | | ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(info); |
| | | |
| | | //token状态设置 |
| New file |
| | |
| | | package org.springblade.auth.utils; |
| | | |
| | | import io.jsonwebtoken.Claims; |
| | | import org.springblade.core.jwt.JwtUtil; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | |
| | | public class AuthUtils extends AuthUtil { |
| | | |
| | | /** |
| | | * 查询用户客户端id |
| | | * @return |
| | | */ |
| | | public static String getClientIds(){ |
| | | String auth = AuthUtil.getHeader(); |
| | | String token = JwtUtil.getToken(auth); |
| | | Claims claims = JwtUtil.parseJWT(token); |
| | | String clientIds = String.valueOf(claims.get("client_ids")); |
| | | // 返回 |
| | | return clientIds; |
| | | } |
| | | } |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | import javax.validation.Valid; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 应用管理控制器 |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 客户端列表树 |
| | | * @param authClient |
| | | * @return |
| | | */ |
| | | @GetMapping("/tree") |
| | | @ApiOperationSupport(order = 7) |
| | | @ApiOperation(value = "分页", notes = "传入client") |
| | | public R tree(AuthClient authClient) { |
| | | List<AuthClient> pages = clientService.tree(authClient); |
| | | return R.data(pages); |
| | | } |
| | | |
| | | } |
| | |
| | | package org.springblade.system.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springblade.system.entity.AuthClient; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Mapper 接口 |
| | |
| | | */ |
| | | public interface AuthClientMapper extends BaseMapper<AuthClient> { |
| | | |
| | | /** |
| | | * 客户端列表树 |
| | | * @param authClient |
| | | * @return |
| | | */ |
| | | List<AuthClient> tree(@Param("authClient") AuthClient authClient); |
| | | } |
| | |
| | | <result column="autoapprove" property="autoapprove"/> |
| | | </resultMap> |
| | | |
| | | <!--客户端列表树--> |
| | | <select id="tree" resultType="org.springblade.system.entity.AuthClient"> |
| | | select id,client_id,client_name from blade_client |
| | | where is_deleted = 0 |
| | | <if test="authClient.clientId!=null and authClient.clientId!='' and authClient.clientId!='sys'"> |
| | | and client_id = #{authClient.clientId} |
| | | </if> |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | import org.springblade.core.mp.base.BaseService; |
| | | import org.springblade.system.entity.AuthClient; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 服务类 |
| | | * |
| | |
| | | */ |
| | | public interface IAuthClientService extends BaseService<AuthClient> { |
| | | |
| | | /** |
| | | * 客户端列表树 |
| | | * @param authClient |
| | | * @return |
| | | */ |
| | | List<AuthClient> tree(AuthClient authClient); |
| | | } |
| | |
| | | */ |
| | | package org.springblade.system.service.impl; |
| | | |
| | | import io.jsonwebtoken.Claims; |
| | | import org.springblade.auth.service.BladeUserDetails; |
| | | import org.springblade.auth.utils.AuthUtils; |
| | | import org.springblade.core.jwt.JwtUtil; |
| | | import org.springblade.core.launch.constant.TokenConstant; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.system.entity.AuthClient; |
| | | import org.springblade.system.mapper.AuthClientMapper; |
| | | import org.springblade.system.service.IAuthClientService; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.security.Principal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 服务实现类 |
| | |
| | | @Service |
| | | public class AuthClientServiceImpl extends BaseServiceImpl<AuthClientMapper, AuthClient> implements IAuthClientService { |
| | | |
| | | /** |
| | | * 客户端列表树 |
| | | * @param authClient |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<AuthClient> tree(AuthClient authClient) { |
| | | authClient.setClientId(AuthUtils.getClientId()); |
| | | return baseMapper.tree(authClient); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 客户端id |
| | | */ |
| | | private String clientId; |
| | | private String clientIds; |
| | | |
| | | |
| | | } |
| | |
| | | */ |
| | | private String avatar; |
| | | /** |
| | | * 客户端id |
| | | */ |
| | | private String clientIds; |
| | | /** |
| | | * 用户网址 |
| | | */ |
| | | private String blog; |
| | |
| | | <if test="user.tenantId!=null and user.tenantId != ''"> |
| | | and tenant_id = #{user.tenantId} |
| | | </if> |
| | | <if test="user.clientIds!=null and user.clientIds != ''"> |
| | | and client_ids = #{user.clientIds} |
| | | </if> |
| | | <if test="user.account!=null and user.account != ''"> |
| | | and account = #{user.account} |
| | | </if> |
| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.auth.utils.AuthUtils; |
| | | import org.springblade.common.cache.DictCache; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.constant.TenantConstant; |
| | |
| | | @Override |
| | | public IPage<User> selectUserPage(IPage<User> page, User user, Long deptId, String tenantId) { |
| | | List<Long> deptIdList = SysCache.getDeptChildIds(deptId); |
| | | String clientIds = AuthUtils.getClientIds(); |
| | | if (Strings.isBlank(user.getClientIds()) && !clientIds.equals("sys")){ |
| | | user.setClientIds(AuthUtils.getClientIds()); |
| | | } |
| | | return page.setRecords(baseMapper.selectUserPage(page, user, deptIdList, tenantId)); |
| | | } |
| | | |
| New file |
| | |
| | | package org.springblade.system.vo; |
| | | |
| | | import lombok.Data; |
| | | import org.springblade.system.entity.AuthClient; |
| | | |
| | | @Data |
| | | public class ClientVO extends AuthClient { |
| | | |
| | | private String client; |
| | | } |