diff --git a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java index 6b5217a86..1873bd2b4 100644 --- a/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java +++ b/mall-ums/ums-api/src/main/java/com/youlai/mall/ums/pojo/dto/AuthMemberDTO.java @@ -9,7 +9,6 @@ public class AuthMemberDTO { private String username; private String password; private Integer status; - private String clientId; private String avatar; private String nickname; diff --git a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/dto/UserDTO.java b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/dto/UserDTO.java index 71be3afdf..c39a19dc1 100644 --- a/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/dto/UserDTO.java +++ b/youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/dto/UserDTO.java @@ -13,7 +13,6 @@ public class UserDTO { private String username; private String password; private Integer status; - private String clientId; private List roleIds; } diff --git a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java index f371731b5..5ec7422d6 100644 --- a/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java +++ b/youlai-admin/admin-boot/src/main/java/com/youlai/admin/component/CustomBlockExceptionHandler.java @@ -7,12 +7,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.youlai.common.result.Result; import com.youlai.common.result.ResultCode; import jodd.net.HttpStatus; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -27,8 +23,7 @@ public class CustomBlockExceptionHandler implements BlockExceptionHandler { @Override public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception { response.setStatus(HttpStatus.ok().status()); - response.setCharacterEncoding("utf-8"); - response.setHeader("Content-Type", "application/json;charset=utf-8"); + response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=utf-8"); if(e instanceof FlowException){ diff --git a/youlai-auth/src/main/java/com/youlai/auth/domain/User.java b/youlai-auth/src/main/java/com/youlai/auth/domain/User.java index 0677aaf37..79a786d6f 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/domain/User.java +++ b/youlai-auth/src/main/java/com/youlai/auth/domain/User.java @@ -38,7 +38,6 @@ public class User implements UserDetails { this.setUsername(user.getUsername()); this.setPassword(AuthConstants.BCRYPT + user.getPassword()); this.setEnabled(Integer.valueOf(1).equals(user.getStatus())); - this.setClientId(user.getClientId()); if (CollectionUtil.isNotEmpty(user.getRoleIds())) { authorities = new ArrayList<>(); user.getRoleIds().forEach(roleId -> authorities.add(new SimpleGrantedAuthority(String.valueOf(roleId)))); @@ -50,7 +49,6 @@ public class User implements UserDetails { this.setUsername(member.getUsername()); this.setPassword(AuthConstants.BCRYPT + member.getPassword()); this.setEnabled( Integer.valueOf(1).equals(member.getStatus())); - this.setClientId(member.getClientId()); } diff --git a/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java b/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java index fdee8de52..fac6d7a65 100644 --- a/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java +++ b/youlai-auth/src/main/java/com/youlai/auth/service/UserDetailsServiceImpl.java @@ -6,6 +6,7 @@ import com.youlai.auth.domain.User; import com.youlai.common.constant.AuthConstants; import com.youlai.common.result.Result; import com.youlai.common.result.ResultCode; +import com.youlai.common.web.exception.BizException; import com.youlai.common.web.util.RequestUtils; import com.youlai.mall.ums.pojo.dto.AuthMemberDTO; import com.youlai.mall.ums.api.UmsMemberFeignService; @@ -34,26 +35,30 @@ public class UserDetailsServiceImpl implements UserDetailsService { String clientId = RequestUtils.getAuthClientId(); User user = null; + Result result; switch (clientId) { case AuthConstants.ADMIN_CLIENT_ID: // 后台用户 - Result userRes = userFeignService.getUserByUsername(username); - if (ResultCode.USER_NOT_EXIST.getCode().equals(userRes.getCode())) { - throw new UsernameNotFoundException(ResultCode.USER_NOT_EXIST.getMsg()); + result = userFeignService.getUserByUsername(username); + if (ResultCode.SUCCESS.getCode().equals(result.getCode())) { + UserDTO userDTO = (UserDTO) result.getData(); + user = new User(userDTO); + } else { + throw new BizException(ResultCode.getValue(result.getCode())); } - UserDTO userDTO = userRes.getData(); - userDTO.setClientId(clientId); - user = new User(userDTO); break; case AuthConstants.WEAPP_CLIENT_ID: // 小程序会员 - Result memberRes = memberFeignService.getUserByOpenid(username); - if (ResultCode.USER_NOT_EXIST.getCode().equals(memberRes.getCode())) { - throw new UsernameNotFoundException(ResultCode.USER_NOT_EXIST.getMsg()); + result = memberFeignService.getUserByOpenid(username); + if (ResultCode.SUCCESS.getCode().equals(result.getCode())) { + AuthMemberDTO authMemberDTO = (AuthMemberDTO) result.getData(); + user = new User(authMemberDTO); + } else { + throw new BizException(ResultCode.getValue(result.getCode())); } - AuthMemberDTO authMemberDTO = memberRes.getData(); - authMemberDTO.setClientId(clientId); - user = new User(authMemberDTO); break; } + if (user == null) { + throw new UsernameNotFoundException(ResultCode.USER_NOT_EXIST.getMsg()); + } if (!user.isEnabled()) { throw new DisabledException("该账户已被禁用!"); } else if (!user.isAccountNonLocked()) { diff --git a/youlai-common/common-core/src/main/java/com/youlai/common/result/ResultCode.java b/youlai-common/common-core/src/main/java/com/youlai/common/result/ResultCode.java index 96f915d56..58a474e01 100644 --- a/youlai-common/common-core/src/main/java/com/youlai/common/result/ResultCode.java +++ b/youlai-common/common-core/src/main/java/com/youlai/common/result/ResultCode.java @@ -1,5 +1,6 @@ package com.youlai.common.result; +import com.youlai.common.enums.QueryModeEnum; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; @@ -93,4 +94,14 @@ public enum ResultCode implements IResultCode, Serializable { ", \"msg\":\"" + msg + '\"' + '}'; } + + + public static ResultCode getValue(String code){ + for (ResultCode value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return SYSTEM_EXECUTION_ERROR; // 默认分页查询 + } } diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java index 93ad4624f..9ce3167c5 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; * @author hxrui * @date 2020-02-25 13:54 **/ -@RestControllerAdvice +//@RestControllerAdvice @Slf4j public class GlobalExceptionHandler { diff --git a/youlai-gateway/pom.xml b/youlai-gateway/pom.xml index 993aa3338..3f0f79857 100644 --- a/youlai-gateway/pom.xml +++ b/youlai-gateway/pom.xml @@ -113,13 +113,13 @@ 1.0.0 - +