From d6197fe099fa4ae60effb73db08ff5a76f07f57f Mon Sep 17 00:00:00 2001 From: jeesun Date: Tue, 9 Jul 2019 09:38:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simon/controller/OauthUserController.java | 11 ++-- .../main/java/com/simon/dto/OauthUserDto.java | 55 +++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/simon/dto/OauthUserDto.java diff --git a/api/src/main/java/com/simon/controller/OauthUserController.java b/api/src/main/java/com/simon/controller/OauthUserController.java index 58ecdda..5bbdd12 100644 --- a/api/src/main/java/com/simon/controller/OauthUserController.java +++ b/api/src/main/java/com/simon/controller/OauthUserController.java @@ -8,6 +8,7 @@ import com.simon.common.domain.UserEntity; import com.simon.common.exception.RegisterException; import com.simon.common.factory.SmsServiceFactory; import com.simon.common.utils.BeanUtils; +import com.simon.dto.OauthUserDto; import com.simon.model.OauthUser; import com.simon.service.BaseSmsService; import com.simon.service.OauthUserService; @@ -110,14 +111,16 @@ public class OauthUserController extends BaseController { @ApiOperation(value = "更新个人信息") @PatchMapping @ResponseBody - public ResultMsg update(@RequestBody OauthUser oauthUser, @ApiIgnore @ApiParam(hidden = true) Authentication authentication) { - oauthUserService.updateByPrimaryKeySelective(oauthUser); + public ResultMsg update(@RequestBody OauthUserDto oauthUserDto, @ApiIgnore @ApiParam(hidden = true) Authentication authentication) { UserEntity userEntity = getCurrentUser(authentication); if (null != userEntity) { //更新session中的principal - BeanUtils.copyPropertiesIgnoreNull(oauthUser, userEntity); + BeanUtils.copyPropertiesIgnoreNull(oauthUserDto, userEntity); } - + OauthUser oauthUser = new OauthUser(); + oauthUser.setId(userEntity.getId()); + BeanUtils.copyPropertiesIgnoreNull(oauthUserDto, oauthUser); + oauthUserService.updateByPrimaryKeySelective(oauthUser); return ResultMsg.success(); } diff --git a/common/src/main/java/com/simon/dto/OauthUserDto.java b/common/src/main/java/com/simon/dto/OauthUserDto.java new file mode 100644 index 0000000..d74f64f --- /dev/null +++ b/common/src/main/java/com/simon/dto/OauthUserDto.java @@ -0,0 +1,55 @@ +package com.simon.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.simon.common.config.AppConfig; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDate; + +/** + * @author simon + * @version 1.0 + * @date 2019-07-09 9:28 + */ +@ApiModel(description = "用户dto") +@Data +@EqualsAndHashCode(callSuper = false) +public class OauthUserDto implements Serializable { + private static final long serialVersionUID = -4619525018151286048L; + + @ApiModelProperty(value = "用户名") + private String username; + + @ApiModelProperty(value = "手机号") + private String phone; + + @ApiModelProperty(value = "邮箱") + private String email; + + @ApiModelProperty(value = "地址") + private String address; + + @ApiModelProperty(value = "年龄") + private Integer age; + + @ApiModelProperty(value = "生日") + @JSONField(format = AppConfig.DATE_PATTERN_DAY) + @DateTimeFormat(pattern = AppConfig.DATE_PATTERN_DAY) + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = AppConfig.DATE_PATTERN_DAY, timezone = AppConfig.DATE_TIMEZONE) + private LocalDate birth; + + @ApiModelProperty(value = "头像") + private String headPhoto; + + @ApiModelProperty(value = "个人简介") + private String personBrief; + + @ApiModelProperty(value = "性别") + private Boolean sex; +} -- Gitee From c7118a30079d3c31c2570f45f5c177ea429bfadb Mon Sep 17 00:00:00 2001 From: jeesun Date: Tue, 9 Jul 2019 09:42:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E7=9A=84=E6=97=A0=E7=94=A8=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/simon/controller/TableController.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/web/src/main/java/com/simon/controller/TableController.java b/web/src/main/java/com/simon/controller/TableController.java index 3c16e88..bc7e4de 100644 --- a/web/src/main/java/com/simon/controller/TableController.java +++ b/web/src/main/java/com/simon/controller/TableController.java @@ -88,23 +88,6 @@ public class TableController extends BaseController { } } - /*@RequestMapping(value = "generate", method = RequestMethod.GET) - @ResponseBody - public ResultMsg generate( - @RequestParam String tableName, - @RequestParam String entityName, - @ApiParam(value = "表id列类型", required = false, example = "Long") @RequestParam(required = false, defaultValue = "Long") String idType, - @RequestParam(required = false) String genModules, - Authentication authentication) { - if (null != authentication) { - UserEntity userEntity = getCurrentUser(authentication); - CodeGenerator.genCodeByCustomModelName(tableName, entityName, idType, genModules, userEntity.getUsername()); - } else { - CodeGenerator.genCodeByCustomModelName(tableName, entityName, idType, genModules); - } - return ResultMsg.success(); - }*/ - @GetMapping(value = "codeGenerate") public String codeGenerate( Model model, -- Gitee From f072772b44acd5cedffcd90b42d2a63f05c37155 Mon Sep 17 00:00:00 2001 From: jeesun Date: Wed, 10 Jul 2019 11:56:04 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86propert?= =?UTF-8?q?ies=E6=96=87=E4=BB=B6=E4=B9=B1=E7=A0=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9B=E6=9B=B4=E6=96=B0README=EF=BC=9B=E4=BF=AE=E5=A4=8Dapi?= =?UTF-8?q?=E6=A8=A1=E5=9D=97DataSourceConfig=E6=9C=AA=E7=94=9F=E6=95=88?= =?UTF-8?q?=E7=9A=84bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +-- api/pom.xml | 19 ++++++++++--------- .../simon/common/config/DataSourceConfig.java | 2 ++ api/src/main/resources/application.properties | 2 +- api/src/main/resources/code-gen.properties | 6 +++--- pom.xml | 1 + tutorial/api.md | 7 ++++++- web/pom.xml | 19 ++++++++++--------- web/src/main/resources/application.properties | 2 +- web/src/main/resources/code-gen.properties | 6 +++--- 10 files changed, 38 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 04125f3..7be1424 100644 --- a/README.md +++ b/README.md @@ -118,5 +118,4 @@ IntelliJ IDEA或Eclipse请先安装lombok插件。 ![管理端主页](tutorial/screenshots/index.png) ## 分享交流 -在使用过程中有任何疑问或者问题,可以微信扫码询问。 -![author](tutorial/screenshots/author.jpg) \ No newline at end of file +在使用过程中有任何疑问或者问题,请提交issue,我会在收到的第一时间予以回复。 \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml index 351bac1..0f8cdea 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -1,22 +1,22 @@ + + com.simon + oauthserver + 2.0.20190506-alpha + ../pom.xml + + 4.0.0 api - 2.0.20190506-alpha + ${parent.version} jar api Api Module - - com.simon - oauthserver - 2.0.20190506-alpha - ../pom.xml - - org.springframework.cloud @@ -112,6 +112,7 @@ org.springframework.boot spring-boot-devtools + runtime true @@ -276,7 +277,7 @@ com.simon common - 2.0.20190506-alpha + ${parent.version} diff --git a/api/src/main/java/com/simon/common/config/DataSourceConfig.java b/api/src/main/java/com/simon/common/config/DataSourceConfig.java index e09d2e6..68fd993 100644 --- a/api/src/main/java/com/simon/common/config/DataSourceConfig.java +++ b/api/src/main/java/com/simon/common/config/DataSourceConfig.java @@ -7,6 +7,7 @@ import org.mybatis.spring.SqlSessionFactoryBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.core.JdbcTemplate; @@ -20,6 +21,7 @@ import java.util.Properties; * @author simon * @date 2019-02-18 */ +@Configuration public class DataSourceConfig { @Value("${mybatis.mapper-locations}") private String mapperLocations; diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties index db67a42..e269efe 100644 --- a/api/src/main/resources/application.properties +++ b/api/src/main/resources/application.properties @@ -1,4 +1,4 @@ -# 벻Ҫserver.portƶyamlļУ޷ȷļ· +# \u8BF7\u4E0D\u8981\u628Aserver.port\u914D\u7F6E\u79FB\u52A8\u5230yaml\u6587\u4EF6\u4E2D\uFF0C\u5426\u5219\u5C06\u65E0\u6CD5\u6B63\u786E\u8BBE\u7F6E\u6587\u4EF6\u8BBF\u95EE\u8DEF\u5F84 server.port=8181 spring.profiles.include=common \ No newline at end of file diff --git a/api/src/main/resources/code-gen.properties b/api/src/main/resources/code-gen.properties index 128eb86..0a48263 100644 --- a/api/src/main/resources/code-gen.properties +++ b/api/src/main/resources/code-gen.properties @@ -1,4 +1,4 @@ -# +# \u4EE3\u7801\u751F\u6210\u5668\u914D\u7F6E # MySQL jdbc_url=jdbc:mysql://127.0.0.1:3306/thymelte?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false jdbc_username=root @@ -17,6 +17,6 @@ jdbc_driver_class_name=com.mysql.cj.jdbc.Driver #jdbc_password=thymelte123456 #jdbc_driver_class_name=oracle.jdbc.driver.OracleDriver -# Spring BootģĿ¼ -# Mapperӿڵȫ޶(ڶᵽĺļ̳нӿMapper) +# Spring Boot\u6A21\u5757\u76EE\u5F55 +# Mapper\u63D2\u4EF6\u57FA\u7840\u63A5\u53E3\u7684\u5B8C\u5168\u9650\u5B9A\u540D(\u7B2C\u4E8C\u6B65\u63D0\u5230\u7684\u6838\u5FC3\u7EE7\u627F\u63A5\u53E3Mapper) mapper_interface_reference=@base.package@.common.mapper.MyMapper \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3a7900c..12ebd1b 100644 --- a/pom.xml +++ b/pom.xml @@ -184,6 +184,7 @@ org.springframework.boot spring-boot-devtools ${spring-boot.version} + runtime true diff --git a/tutorial/api.md b/tutorial/api.md index 470e36b..8f937eb 100644 --- a/tutorial/api.md +++ b/tutorial/api.md @@ -156,4 +156,9 @@ status=200,返回的json数据: ## app实践指南 app获取到token信息后,需要保存token信息和请求时间。在传access_token之前,需要检查access_token是否过期。为了减少后台压力,检查access_token是否过期应该是在app本地完成。通过token的key`expires_in`(剩余有效期)的值,以及本地记录的请求时间,和当前时间做对比,可以很方便地判断出access_token是否过期。如果过期了,需要通过refresh_token获取新的access_token。因为access_token的有效期只有2个小时,这个验证是必须的。 -refresh_token同理。 +refresh_token同理。 +但是,Spring Security Oauth2授权框架没有解决一个账号多端登录的问题。账号和token是一对一的关系,如果系统允许一个账号多端登录,那么必然出现以下这种情况。用户在客户端A和客户端B同时登录,客户端A的access_token过期了,客户端A选择刷新access_token;在客户端A刷新了access_token之后,客户端B发现自己手上的access_token不可用了,也选择刷新access_token,造成客户端A手上的access_token不可用了,循环反复,客户端A和客户端B一直在疯狂刷新access_token。 +如何解决上面的问题呢?此处提供三种解决方案以供参考。 +1. 设置access_token永不失效,不去刷新access_token; +2. 自定义刷新access_token的请求接口,在接口里判断access_token是否过期,过期了就刷新并返回access_token,没过期就直接返回access_token。 +3. 记录每次刷新token的设备,如果这一次刷新的设备和上一次一致就返回新token,如果设备不一致就返回上一次的token,如果上一次的token已过期就返回新token,这样让两台设备的token保持一样就不会出现问题。 \ No newline at end of file diff --git a/web/pom.xml b/web/pom.xml index 776d516..2b5ca72 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -1,22 +1,22 @@ + + com.simon + oauthserver + 2.0.20190506-alpha + ../pom.xml + + 4.0.0 web - 2.0.20190506-alpha + ${parent.version} jar web Web Module - - com.simon - oauthserver - 2.0.20190506-alpha - ../pom.xml - - org.springframework.cloud @@ -97,6 +97,7 @@ org.springframework.boot spring-boot-devtools + runtime true @@ -327,7 +328,7 @@ com.simon common - 2.0.20190506-alpha + ${parent.version} diff --git a/web/src/main/resources/application.properties b/web/src/main/resources/application.properties index 953198b..baef00f 100644 --- a/web/src/main/resources/application.properties +++ b/web/src/main/resources/application.properties @@ -1,4 +1,4 @@ -# 벻Ҫserver.portƶyamlļУ޷ȷļ· +# \u8BF7\u4E0D\u8981\u628Aserver.port\u914D\u7F6E\u79FB\u52A8\u5230yaml\u6587\u4EF6\u4E2D\uFF0C\u5426\u5219\u5C06\u65E0\u6CD5\u6B63\u786E\u8BBE\u7F6E\u6587\u4EF6\u8BBF\u95EE\u8DEF\u5F84 server.port=8182 spring.profiles.include=common \ No newline at end of file diff --git a/web/src/main/resources/code-gen.properties b/web/src/main/resources/code-gen.properties index bd71763..3ccb414 100644 --- a/web/src/main/resources/code-gen.properties +++ b/web/src/main/resources/code-gen.properties @@ -1,4 +1,4 @@ -# +# \u4EE3\u7801\u751F\u6210\u5668\u914D\u7F6E # MySQL jdbc_url=jdbc:mysql://127.0.0.1:3306/thymelte?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false jdbc_username=root @@ -17,6 +17,6 @@ jdbc_driver_class_name=com.mysql.cj.jdbc.Driver #jdbc_password=yuhang #jdbc_driver_class_name=oracle.jdbc.OracleDriver -# Spring BootģĿ¼ -# Mapperӿڵȫ޶(ڶᵽĺļ̳нӿMapper) +# Spring Boot\u6A21\u5757\u76EE\u5F55 +# Mapper\u63D2\u4EF6\u57FA\u7840\u63A5\u53E3\u7684\u5B8C\u5168\u9650\u5B9A\u540D(\u7B2C\u4E8C\u6B65\u63D0\u5230\u7684\u6838\u5FC3\u7EE7\u627F\u63A5\u53E3Mapper) mapper_interface_reference=@base.package@.common.mapper.MyMapper \ No newline at end of file -- Gitee