From 6f831dbb46f8f7a794237cfaffccb06fabba0795 Mon Sep 17 00:00:00 2001 From: zhangdaihao Date: Mon, 5 Aug 2019 15:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=8A=A0=E5=AF=86=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E6=9A=82=E6=97=B6=E6=B3=A8=E9=87=8A=E6=8E=89\swagger?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=85=A8=E5=B1=80token,=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=9C=80=E8=A6=81token=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ant-design-vue-jeecg/src/views/user/Login.vue | 20 +++++++--------- .../java/org/jeecg/config/Swagger2Config.java | 24 +++++++++++++++---- .../system/controller/LoginController.java | 9 ++++--- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/ant-design-vue-jeecg/src/views/user/Login.vue b/ant-design-vue-jeecg/src/views/user/Login.vue index 604d9ff0..c35b2e40 100644 --- a/ant-design-vue-jeecg/src/views/user/Login.vue +++ b/ant-design-vue-jeecg/src/views/user/Login.vue @@ -227,17 +227,9 @@ created () { Vue.ls.remove(ACCESS_TOKEN) this.getRouterData(); - this.getEncrypte(); - // update-begin- --- author:scott ------ date:20190225 ---- for:暂时注释,未实现登录验证码功能 -// this.$http.get('/auth/2step-code') -// .then(res => { -// this.requiredTwoStepCaptcha = res.result.stepCode -// }).catch(err => { -// console.log('2step-code:', err) -// }) - // update-end- --- author:scott ------ date:20190225 ---- for:暂时注释,未实现登录验证码功能 - // this.requiredTwoStepCaptcha = true - + // update-begin- --- author:scott ------ date:20190805 ---- for:密码加密逻辑暂时注释掉,有点问题 + //this.getEncrypte(); + // update-end- --- author:scott ------ date:20190805 ---- for:密码加密逻辑暂时注释掉,有点问题 }, methods: { ...mapActions([ "Login", "Logout","PhoneLogin" ]), @@ -266,8 +258,12 @@ that.form.validateFields([ 'username', 'password','inputCode' ], { force: true }, (err, values) => { if (!err) { loginParams.username = values.username + // update-begin- --- author:scott ------ date:20190805 ---- for:密码加密逻辑暂时注释掉,有点问题 //loginParams.password = md5(values.password) - loginParams.password = encryption(values.password,that.encryptedString.key,that.encryptedString.iv).replace(/\+/g,"%2B"); + //loginParams.password = encryption(values.password,that.encryptedString.key,that.encryptedString.iv) + loginParams.password = values.password + // update-begin- --- author:scott ------ date:20190805 ---- for:密码加密逻辑暂时注释掉,有点问题 + that.Login(loginParams).then((res) => { this.departConfirm(res) }).catch((err) => { diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/config/Swagger2Config.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/config/Swagger2Config.java index 4d0be0e2..493868a2 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/config/Swagger2Config.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/config/Swagger2Config.java @@ -1,6 +1,7 @@ package org.jeecg.config; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.jeecg.modules.shiro.vo.DefContants; @@ -12,6 +13,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; import io.swagger.annotations.ApiOperation; +import springfox.documentation.service.ApiKey; import springfox.documentation.service.Parameter; import lombok.extern.slf4j.Slf4j; import springfox.documentation.builders.ApiInfoBuilder; @@ -20,6 +22,7 @@ import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.schema.ModelRef; import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.SecurityScheme; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @@ -62,9 +65,20 @@ public class Swagger2Config implements WebMvcConfigurer { .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .paths(PathSelectors.any()) .build() - .globalOperationParameters(setHeaderToken()); + .securitySchemes(Collections.singletonList(securityScheme())); + //.globalOperationParameters(setHeaderToken()); } + /*** + * oauth2配置 + * 需要增加swagger授权回调地址 + * http://localhost:8888/webjars/springfox-swagger-ui/o2c.html + * @return + */ + @Bean + SecurityScheme securityScheme() { + return new ApiKey(DefContants.X_ACCESS_TOKEN, DefContants.X_ACCESS_TOKEN, "header"); + } /** * JWT token * @return @@ -90,11 +104,11 @@ public class Swagger2Config implements WebMvcConfigurer { .version("1.0") // .termsOfServiceUrl("NO terms of service") // 描述 - .description("restful 风格接口") + .description("后台API接口") // 作者 -// .contact(new Contact("scott", "http://jeecg.org", "jeecgos@163.com")) -// .license("The Apache License, Version 2.0") -// .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") + .contact("JEECG团队") + .license("The Apache License, Version 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") .build(); } diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java index 25c624a2..2979daae 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java @@ -67,8 +67,11 @@ public class LoginController { Result result = new Result(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); - //步骤1:TODO 前端密码加密,后端进行密码解密,防止传输密码篡改等问题,不配就直接提示密码错误,并记录日志后期进行统计分析是否锁定 - password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密 + //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 + //前端密码加密,后端进行密码解密 + //password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密 + //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 + //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); @@ -263,7 +266,7 @@ public class LoginController { * @return */ @PostMapping("/phoneLogin") - public Result login(@RequestBody JSONObject jsonObject) { + public Result phoneLogin(@RequestBody JSONObject jsonObject) { Result result = new Result(); String phone = jsonObject.getString("mobile");