Commit 0b156ed7836cc023dfc7ed09a59c2f1b7980ba4a

Authored by 王富生
1 parent 43df1f77

提交

src/main/java/com/zteits/oa/configuration/FilterRegistrationConfig.java 0 → 100644
  1 +package com.zteits.oa.configuration;
  2 +
  3 +import org.springframework.boot.web.servlet.FilterRegistrationBean;
  4 +import org.springframework.context.annotation.Bean;
  5 +import org.springframework.context.annotation.Configuration;
  6 +
  7 +import com.zteits.oa.configuration.fiter.ResponseHeaderFilter;
  8 +
  9 +@Configuration
  10 +public class FilterRegistrationConfig {
  11 + /**
  12 + * 添加响应请求头Filter
  13 + * @return
  14 + * 2017年5月8日 zhaowg
  15 + */
  16 + @Bean
  17 + public FilterRegistrationBean ResponseHeaderFilterRegistration() {
  18 + FilterRegistrationBean registration = new FilterRegistrationBean(new ResponseHeaderFilter());
  19 + registration.addServletRegistrationBeans();
  20 + registration.addUrlPatterns("/*");
  21 + return registration;
  22 + }
  23 +}
... ...
src/main/java/com/zteits/oa/report/vo/OAuthResult.java 0 → 100644
  1 +package com.zteits.oa.report.vo;
  2 +
  3 +import com.zteits.oa.api.base.constants.ErrorType;
  4 +import com.zteits.oa.api.dto.asraop.LoginOathRes;
  5 +
  6 +/**
  7 + * Copyright: Copyright (c) 2017 zteits
  8 + *
  9 + * @ClassName: com.zteits.oauth.portal.vo
  10 + * @Description:
  11 + * @version: v1.0.0
  12 + * @author: atao
  13 + * @date: 2017/5/9 下午3:39
  14 + * Modification History:
  15 + * Date Author Version Description
  16 + * ---------------------------------------------------------*
  17 + * 2017/5/9 atao v1.0.0 创建
  18 + */
  19 +public class OAuthResult<T extends LoginOathRes> {
  20 +
  21 + private String code;
  22 + private String errMsg;
  23 + private T data;
  24 +
  25 + public OAuthResult(boolean success) {
  26 + if (success) {
  27 + this.code = ErrorType.BIZ_SUCCESS.getCode();
  28 + this.errMsg = ErrorType.BIZ_SUCCESS.getMsg();
  29 + }
  30 +
  31 + }
  32 +
  33 + public String getCode() {
  34 + return code;
  35 + }
  36 +
  37 + public void setCode(String code) {
  38 +
  39 + this.code = code;
  40 + }
  41 +
  42 + public String getErrMsg() {
  43 + return errMsg;
  44 + }
  45 +
  46 + public void setErrMsg(String errMsg) {
  47 + this.errMsg = errMsg;
  48 + }
  49 +
  50 + public T getData() {
  51 + return data;
  52 + }
  53 +
  54 + public void setData(T data) {
  55 + this.data = data;
  56 + }
  57 +
  58 + public void setErrorType(ErrorType errorType) {
  59 + this.code = errorType.getCode();
  60 + this.errMsg = errorType.getMsg();
  61 + }
  62 +
  63 + public void setErrorType(ErrorType errorType, String errMsg) {
  64 + this.code = errorType.getCode();
  65 + this.errMsg = errMsg;
  66 + }
  67 +
  68 +}
... ...
src/main/java/com/zteits/oa/report/web/OAuthController.java
... ... @@ -20,6 +20,7 @@ import com.zteits.oa.api.dto.asraop.LoginOathRes;
20 20 import com.zteits.oa.api.dto.asraop.param.AsraOpQueryReq;
21 21 import com.zteits.oa.api.dto.asraop.param.LoginOauthReq;
22 22 import com.zteits.oa.api.service.report.query.AsraOpRueryService;
  23 +import com.zteits.oa.report.vo.OAuthResult;
23 24 import com.zteits.oa.util.MD5Utils;
24 25  
25 26 import io.swagger.annotations.Api;
... ... @@ -39,8 +40,8 @@ public class OAuthController {
39 40  
40 41 @ApiOperation("用户登录")
41 42 @PostMapping("/login")
42   - public BizResult<LoginOathRes> login(@RequestBody LoginOauthReq req ) throws Exception {
43   - BizResult<LoginOathRes> result = this._login(req);
  43 + public OAuthResult<LoginOathRes> login(@RequestBody LoginOauthReq req ) throws Exception {
  44 + OAuthResult<LoginOathRes> result = this._login(req);
44 45 return result;
45 46 }
46 47 /**
... ... @@ -49,14 +50,14 @@ public class OAuthController {
49 50 * @return
50 51 * 2018年7月31日 wangfs.<br/>
51 52 */
52   - private BizResult<LoginOathRes> _login(LoginOauthReq req ){
53   - BizResult<LoginOathRes> result = new BizResult<LoginOathRes>();
  53 + private OAuthResult<LoginOathRes> _login(LoginOauthReq req ){
  54 + OAuthResult<LoginOathRes> result = new OAuthResult<LoginOathRes>(false);
54 55 LoginOathRes loginOathRes = new LoginOathRes();
55 56 String loginCode = req.getLoginCode();
56 57 String passWord = req.getPassWord();
57 58 if(StringUtils.isEmpty(loginCode) || StringUtils.isEmpty(passWord)) {
58 59 logger.info("校验登录信息,用户名 或者 登录密码为空!");
59   - result.setErrorInfo(ErrorType.PARAMM_NULL, "用户名 或者 登录密码为空");
  60 + result.setErrorType(ErrorType.PARAMM_NULL, "用户名 或者 登录密码为空");
60 61 }
61 62 AsraOpQueryReq asraOpQueryRe = new AsraOpQueryReq();
62 63 AsraOpDTO asraOpDTO = new AsraOpDTO();
... ... @@ -68,18 +69,18 @@ public class OAuthController {
68 69 asraOpDTO = asraOpReult.getData();
69 70 if(StringUtils.isEmpty(asraOpDTO.getLoginCode())){
70 71 logger.info("{}登录账号不存在",loginCode);
71   - result.setErrorInfo(ErrorType.AUTH_LOGIN_ERROR, "登录账号不存在!");
  72 + result.setErrorType(ErrorType.AUTH_LOGIN_ERROR, "登录账号不存在!");
72 73 }else{
73 74 if(!asraOpDTO.getLoginPassword().equalsIgnoreCase(MD5Utils.enMD5(passWord))){
74 75 logger.info("{}登录账号输入的密码不正确",loginCode);
75   - result.setErrorInfo(ErrorType.AUTH_PASS_ERROR, "登录密码不匹配!");
  76 + result.setErrorType(ErrorType.AUTH_PASS_ERROR, "登录密码不匹配!");
76 77 }else{
77 78 isCheckSuccess = true;
78 79 }
79 80 }
80 81  
81 82 }else{
82   - result.setErrorInfo(ErrorType.BIZ_ERROR, "用户登录失败");
  83 + result.setErrorType(ErrorType.BIZ_ERROR, "用户登录失败");
83 84 }
84 85  
85 86  
... ... @@ -93,8 +94,9 @@ public class OAuthController {
93 94 loginOathRes.setCityId(asraOpDTO.getCityId());
94 95 loginOathRes.setCityName(asraOpDTO.getCityName());
95 96 loginOathRes.setAccessToken(session.getId());
  97 + loginOathRes.setRoleId(asraOpDTO.getRoleId());
96 98 result.setData(loginOathRes);
97   - result.setErrorInfo(ErrorType.BIZ_SUCCESS, "登录成功");
  99 + result.setErrorType(ErrorType.BIZ_SUCCESS, "登录成功");
98 100 }
99 101  
100 102  
... ...