Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
93c64689
提交
93c64689
authored
7月 04, 2020
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
创建 mall-spring-boot-starter-security-user 模块,用于用户的认证拦截器
上级
d89e5bad
显示空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
345 行增加
和
186 行删除
+345
-186
ServiceExceptionUtil.java
...n/iocoder/common/framework/util/ServiceExceptionUtil.java
+4
-2
pom.xml
common/mall-security-annotations/pom.xml
+15
-0
RequiresAuthenticate.java
...cn/iocoder/security/annotations/RequiresAuthenticate.java
+1
-1
RequiresNone.java
...in/java/cn/iocoder/security/annotations/RequiresNone.java
+1
-1
RequiresPermissions.java
.../cn/iocoder/security/annotations/RequiresPermissions.java
+1
-1
pom.xml
common/mall-spring-boot-starter-security-user/pom.xml
+47
-0
UserSecurityAutoConfiguration.java
...l/security/user/config/UserSecurityAutoConfiguration.java
+35
-0
UserSecurityContext.java
.../mall/security/user/core/context/UserSecurityContext.java
+18
-0
UserSecurityContextHolder.java
...security/user/core/context/UserSecurityContextHolder.java
+35
-0
UserSecurityInterceptor.java
...curity/user/core/interceptor/UserSecurityInterceptor.java
+72
-0
spring.factories
...ecurity-user/src/main/resources/META-INF/spring.factories
+2
-0
pom.xml
common/pom.xml
+2
-0
pom.xml
mall-dependencies/pom.xml
+10
-0
SystemErrorCodeEnum.java
...iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java
+2
-3
UserVO.java
.../java/cn/iocoder/mall/userservice/rpc/user/vo/UserVO.java
+4
-0
pom.xml
user-web-app/pom.xml
+5
-0
UserController.java
.../iocoder/mall/userweb/controller/user/UserController.java
+48
-0
UserInfoVO.java
...n/iocoder/mall/userweb/controller/user/vo/UserInfoVO.java
+2
-2
package-info.java
...in/java/cn/iocoder/mall/userweb/convert/package-info.java
+0
-1
UserConvert.java
...ava/cn/iocoder/mall/userweb/convert/user/UserConvert.java
+15
-0
UserManager.java
...ava/cn/iocoder/mall/userweb/manager/user/UserManager.java
+23
-0
application.yml
user-web-app/src/main/resources/application.yml
+3
-1
PassportController.java
...user/application/controller/users/PassportController.java
+0
-56
UserController.java
...all/user/application/controller/users/UserController.java
+0
-56
UserConvert.java
...cn/iocoder/mall/user/application/convert/UserConvert.java
+0
-22
UsersAccessTokenVO.java
...er/mall/user/application/vo/users/UsersAccessTokenVO.java
+0
-20
UsersMobileRegisterVO.java
...mall/user/application/vo/users/UsersMobileRegisterVO.java
+0
-20
没有找到文件。
common/common-framework/src/main/java/cn/iocoder/common/framework/util/ServiceExceptionUtil.java
浏览文件 @
93c64689
...
...
@@ -71,11 +71,13 @@ public class ServiceExceptionUtil {
}
public
static
ServiceException
exception
(
Enumerable
enumerable
)
{
return
exception
(
enumerable
.
getCode
());
String
messagePattern
=
messages
.
getOrDefault
(
enumerable
.
getCode
(),
enumerable
.
getMessage
());
return
exception0
(
enumerable
.
getCode
(),
messagePattern
);
}
public
static
ServiceException
exception
(
Enumerable
enumerable
,
Object
...
params
)
{
return
exception
(
enumerable
.
getCode
(),
params
);
String
messagePattern
=
messages
.
getOrDefault
(
enumerable
.
getCode
(),
enumerable
.
getMessage
());
return
exception0
(
enumerable
.
getCode
(),
messagePattern
,
params
);
}
/**
...
...
common/mall-security-annotations/pom.xml
0 → 100644
浏览文件 @
93c64689
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
common
</artifactId>
<groupId>
cn.iocoder.mall
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
mall-security-annotations
</artifactId>
</project>
common/mall-s
pring-boot-starter-security/src/main/java/cn/iocoder/mall/security/core/annotation
/RequiresAuthenticate.java
→
common/mall-s
ecurity-annotations/src/main/java/cn/iocoder/security/annotations
/RequiresAuthenticate.java
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
security
.
core
.
annotation
;
package
cn
.
iocoder
.
security
.
annotations
;
import
java.lang.annotation.*
;
...
...
common/mall-s
pring-boot-starter-security/src/main/java/cn/iocoder/mall/security/core/annotation
/RequiresNone.java
→
common/mall-s
ecurity-annotations/src/main/java/cn/iocoder/security/annotations
/RequiresNone.java
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
security
.
core
.
annotation
;
package
cn
.
iocoder
.
security
.
annotations
;
import
java.lang.annotation.*
;
...
...
common/mall-s
pring-boot-starter-security/src/main/java/cn/iocoder/mall/security/core/annotation
/RequiresPermissions.java
→
common/mall-s
ecurity-annotations/src/main/java/cn/iocoder/security/annotations
/RequiresPermissions.java
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
security
.
core
.
annotation
;
package
cn
.
iocoder
.
security
.
annotations
;
import
java.lang.annotation.*
;
...
...
common/mall-spring-boot-starter-security-user/pom.xml
0 → 100644
浏览文件 @
93c64689
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
common
</artifactId>
<groupId>
cn.iocoder.mall
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
mall-spring-boot-starter-security-user
</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
<artifactId>
system-service-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<!-- Spring 核心 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
<artifactId>
mall-spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
<artifactId>
mall-security-annotations
</artifactId>
</dependency>
<!-- RPC 相关 -->
<dependency>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo
</artifactId>
</dependency>
</dependencies>
</project>
common/mall-spring-boot-starter-security-user/src/main/java/cn/iocoder/mall/security/user/config/UserSecurityAutoConfiguration.java
0 → 100644
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
security
.
user
.
config
;
import
cn.iocoder.mall.security.user.core.interceptor.UserSecurityInterceptor
;
import
cn.iocoder.mall.web.config.CommonWebAutoConfiguration
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
@Configuration
@AutoConfigureAfter
(
CommonWebAutoConfiguration
.
class
)
// 在 CommonWebAutoConfiguration 之后自动配置,保证过滤器的顺序
@ConditionalOnWebApplication
(
type
=
ConditionalOnWebApplication
.
Type
.
SERVLET
)
public
class
UserSecurityAutoConfiguration
implements
WebMvcConfigurer
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
// ========== 拦截器相关 ==========
@Bean
public
UserSecurityInterceptor
userSecurityInterceptor
()
{
return
new
UserSecurityInterceptor
();
}
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
// UserSecurityInterceptor 拦截器
registry
.
addInterceptor
(
this
.
userSecurityInterceptor
());
logger
.
info
(
"[addInterceptors][加载 UserSecurityInterceptor 拦截器完成]"
);
}
}
common/mall-spring-boot-starter-security-user/src/main/java/cn/iocoder/mall/security/user/core/context/UserSecurityContext.java
0 → 100644
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
security
.
user
.
core
.
context
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
/**
* User Security 上下文
*/
@Data
@Accessors
(
chain
=
true
)
public
class
UserSecurityContext
{
/**
* 用户编号
*/
private
Integer
userId
;
}
common/mall-spring-boot-starter-security-user/src/main/java/cn/iocoder/mall/security/user/core/context/UserSecurityContextHolder.java
0 → 100644
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
security
.
user
.
core
.
context
;
/**
* {@link UserSecurityContext} Holder
*
* 参考 spring security 的 ThreadLocalSecurityContextHolderStrategy 类,简单实现。
*/
public
class
UserSecurityContextHolder
{
private
static
final
ThreadLocal
<
UserSecurityContext
>
SECURITY_CONTEXT
=
new
ThreadLocal
<
UserSecurityContext
>();
public
static
void
setContext
(
UserSecurityContext
context
)
{
SECURITY_CONTEXT
.
set
(
context
);
}
public
static
UserSecurityContext
getContext
()
{
UserSecurityContext
ctx
=
SECURITY_CONTEXT
.
get
();
// 为空时,设置一个空的进去
if
(
ctx
==
null
)
{
ctx
=
new
UserSecurityContext
();
SECURITY_CONTEXT
.
set
(
ctx
);
}
return
ctx
;
}
public
static
Integer
getUserId
()
{
UserSecurityContext
ctx
=
SECURITY_CONTEXT
.
get
();
return
ctx
!=
null
?
ctx
.
getUserId
()
:
null
;
}
public
static
void
clear
()
{
SECURITY_CONTEXT
.
remove
();
}
}
common/mall-spring-boot-starter-security-user/src/main/java/cn/iocoder/mall/security/user/core/interceptor/UserSecurityInterceptor.java
0 → 100644
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
security
.
user
.
core
.
interceptor
;
import
cn.iocoder.common.framework.enums.UserTypeEnum
;
import
cn.iocoder.common.framework.util.HttpUtil
;
import
cn.iocoder.common.framework.util.ServiceExceptionUtil
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.security.user.core.context.UserSecurityContext
;
import
cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder
;
import
cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum
;
import
cn.iocoder.mall.systemservice.rpc.oauth.OAuth2Rpc
;
import
cn.iocoder.mall.systemservice.rpc.oauth.vo.OAuth2AccessTokenVO
;
import
cn.iocoder.mall.web.core.util.CommonWebUtil
;
import
cn.iocoder.security.annotations.RequiresAuthenticate
;
import
cn.iocoder.security.annotations.RequiresPermissions
;
import
org.apache.dubbo.config.annotation.Reference
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
static
cn
.
iocoder
.
mall
.
systemservice
.
enums
.
SystemErrorCodeEnum
.
OAUTH_USER_TYPE_ERROR
;
public
class
UserSecurityInterceptor
extends
HandlerInterceptorAdapter
{
@Reference
(
validation
=
"true"
,
version
=
"${dubbo.consumer.OAuth2Rpc.version}"
)
private
OAuth2Rpc
oauth2Rpc
;
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
// 获得访问令牌
String
accessToken
=
HttpUtil
.
obtainAuthorization
(
request
);
Integer
userId
=
null
;
if
(
accessToken
!=
null
)
{
CommonResult
<
OAuth2AccessTokenVO
>
checkAccessTokenResult
=
oauth2Rpc
.
checkAccessToken
(
accessToken
);
checkAccessTokenResult
.
checkError
();
// 校验用户类型正确
if
(!
UserTypeEnum
.
USER
.
getValue
().
equals
(
checkAccessTokenResult
.
getData
().
getUserType
()))
{
throw
ServiceExceptionUtil
.
exception
(
OAUTH_USER_TYPE_ERROR
);
}
// 获得用户编号
userId
=
checkAccessTokenResult
.
getData
().
getUserId
();
// 设置到 Request 中
CommonWebUtil
.
setUserId
(
request
,
userId
);
CommonWebUtil
.
setUserType
(
request
,
UserTypeEnum
.
USER
.
getValue
());
// 设置到
UserSecurityContext
userSecurityContext
=
new
UserSecurityContext
().
setUserId
(
userId
);
UserSecurityContextHolder
.
setContext
(
userSecurityContext
);
}
// 校验认证
this
.
checkAuthentication
((
HandlerMethod
)
handler
,
userId
);
return
true
;
}
private
void
checkAuthentication
(
HandlerMethod
handlerMethod
,
Integer
userId
)
{
boolean
requiresAuthenticate
=
false
;
// 对于 USER 来说,默认无需登录
if
(
handlerMethod
.
hasMethodAnnotation
(
RequiresAuthenticate
.
class
)
||
handlerMethod
.
hasMethodAnnotation
(
RequiresPermissions
.
class
))
{
// 如果需要权限验证,也认为需要认证
requiresAuthenticate
=
true
;
}
if
(
requiresAuthenticate
&&
userId
==
null
)
{
throw
ServiceExceptionUtil
.
exception
(
SystemErrorCodeEnum
.
OAUTH2_NOT_AUTHENTICATION
);
}
}
@Override
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
{
// 清空 SecurityContext
UserSecurityContextHolder
.
clear
();
}
}
common/mall-spring-boot-starter-security-user/src/main/resources/META-INF/spring.factories
0 → 100644
浏览文件 @
93c64689
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.iocoder.mall.security.user.config.UserSecurityAutoConfiguration
common/pom.xml
浏览文件 @
93c64689
...
...
@@ -16,7 +16,9 @@
<module>
mall-spring-boot
</module>
<module>
mall-spring-boot-starter-swagger
</module>
<module>
mall-spring-boot-starter-web
</module>
<module>
mall-security-annotations
</module>
<module>
mall-spring-boot-starter-security
</module>
<module>
mall-spring-boot-starter-security-user
</module>
<module>
mall-spring-boot-starter-mybatis
</module>
</modules>
<dependencies>
...
...
mall-dependencies/pom.xml
浏览文件 @
93c64689
...
...
@@ -140,11 +140,21 @@
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
<artifactId>
mall-security-annotations
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
<artifactId>
mall-spring-boot-starter-security
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
<artifactId>
mall-spring-boot-starter-security-user
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
...
...
system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/enums/SystemErrorCodeEnum.java
浏览文件 @
93c64689
...
...
@@ -15,13 +15,12 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<Syste
OAUTH2_ACCESS_TOKEN_NOT_FOUND
(
1001001001
,
"访问令牌不存在"
),
OAUTH2_ACCESS_TOKEN_TOKEN_EXPIRED
(
1001001002
,
"访问令牌已过期"
),
OAUTH2_ACCESS_TOKEN_INVALID
(
1001001003
,
"访问令牌已失效"
),
OAUTH2_NOT_AUTHENTICAT
E
(
1001001004
,
"账号未登陆
"
),
OAUTH2_NOT_AUTHENTICAT
ION
(
1001001004
,
"账号未登录
"
),
OAUTH2_REFRESH_TOKEN_NOT_FOUND
(
1001001005
,
"刷新令牌不存在"
),
OAUTH_REFRESH_TOKEN_EXPIRED
(
1001001006
,
"访问令牌已过期"
),
OAUTH_REFRESH_TOKEN_INVALID
(
1001001007
,
"刷新令牌已失效"
),
// 其它 1001001100 开始
OAUTH2_ACCOUNT_NOT_FOUND
(
1001001100
,
"账号不存在"
),
OAUTH2_ACCOUNT_PASSWORD_ERROR
(
1001001101
,
"密码不正确"
),
OAUTH_USER_TYPE_ERROR
(
1001001101
,
"用户类型并不正确"
),
// ========== 管理员模块 1002002000 ==========
ADMIN_NOT_FOUND
(
1002002000
,
"管理员不存在"
),
...
...
user-service-project/user-service-api/src/main/java/cn/iocoder/mall/userservice/rpc/user/vo/UserVO.java
浏览文件 @
93c64689
...
...
@@ -17,6 +17,10 @@ public class UserVO implements Serializable {
* 用户编号
*/
private
Integer
id
;
/**
* 手机号
*/
private
String
mobile
;
/**
* 昵称
*/
...
...
user-web-app/pom.xml
浏览文件 @
93c64689
...
...
@@ -31,6 +31,11 @@
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
<artifactId>
mall-spring-boot-starter-security-user
</artifactId>
</dependency>
<!-- RPC 相关 -->
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
...
...
user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/UserController.java
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
userweb
.
controller
.
user
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder
;
import
cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO
;
import
cn.iocoder.mall.userweb.manager.user.UserManager
;
import
cn.iocoder.security.annotations.RequiresAuthenticate
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
cn
.
iocoder
.
common
.
framework
.
vo
.
CommonResult
.
success
;
@Api
(
tags
=
"用户信息 API"
)
@RestController
@RequestMapping
(
"/user"
)
public
class
UserController
{
@Autowired
private
UserManager
userManager
;
@ApiOperation
(
value
=
"用户信息"
)
@GetMapping
(
"/info"
)
@RequiresAuthenticate
public
CommonResult
<
UserInfoVO
>
info
()
{
UserInfoVO
user
=
userManager
.
getUser
(
UserSecurityContextHolder
.
getUserId
());
return
success
(
user
);
}
// @PostMapping("/update_avatar")
// @RequiresLogin
// @ApiOperation(value = "更新头像")
// public CommonResult<Boolean> updateAvatar(@RequestParam("avatar") String avatar) {
// // 创建
// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
// .setAvatar(avatar);
// // 更新头像
// return success(userService.updateUser(userUpdateDTO));
// }
//
// @PostMapping("/update_nickname")
// @RequiresLogin
// @ApiOperation(value = "更新昵称")
// public CommonResult<Boolean> updateNickname(@RequestParam("nickname") String nickname) {
// // 创建
// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
// .setNickname(nickname);
// // 更新头像
// return success(userService.updateUser(userUpdateDTO));
// }
}
user
/user-start/src/main/java/cn/iocoder/mall/user/application/vo/users/UsersUser
VO.java
→
user
-web-app/src/main/java/cn/iocoder/mall/userweb/controller/user/vo/UserInfo
VO.java
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
user
.
application
.
vo
.
users
;
package
cn
.
iocoder
.
mall
.
user
web
.
controller
.
user
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
@@ -8,7 +8,7 @@ import lombok.experimental.Accessors;
@ApiModel
(
"用户信息 VO"
)
@Data
@Accessors
(
chain
=
true
)
public
class
User
sUser
VO
{
public
class
User
Info
VO
{
@ApiModelProperty
(
value
=
"用户编号"
,
required
=
true
,
example
=
"123"
)
private
Integer
id
;
...
...
user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/package-info.java
deleted
100644 → 0
浏览文件 @
d89e5bad
package
cn
.
iocoder
.
mall
.
userweb
.
convert
;
user-web-app/src/main/java/cn/iocoder/mall/userweb/convert/user/UserConvert.java
0 → 100644
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
userweb
.
convert
.
user
;
import
cn.iocoder.mall.userservice.rpc.user.vo.UserVO
;
import
cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.factory.Mappers
;
@Mapper
public
interface
UserConvert
{
UserConvert
INSTANCE
=
Mappers
.
getMapper
(
UserConvert
.
class
);
UserInfoVO
convert
(
UserVO
bean
);
}
user-web-app/src/main/java/cn/iocoder/mall/userweb/manager/user/UserManager.java
0 → 100644
浏览文件 @
93c64689
package
cn
.
iocoder
.
mall
.
userweb
.
manager
.
user
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.userservice.rpc.user.UserRpc
;
import
cn.iocoder.mall.userservice.rpc.user.vo.UserVO
;
import
cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO
;
import
cn.iocoder.mall.userweb.convert.user.UserConvert
;
import
org.apache.dubbo.config.annotation.Reference
;
import
org.springframework.stereotype.Service
;
@Service
public
class
UserManager
{
@Reference
(
version
=
"${dubbo.consumer.UserRpc.version}"
,
validation
=
"false"
)
private
UserRpc
userRpc
;
public
UserInfoVO
getUser
(
Integer
id
)
{
CommonResult
<
UserVO
>
userResult
=
userRpc
.
getUser
(
id
);
userResult
.
checkError
();
return
UserConvert
.
INSTANCE
.
convert
(
userResult
.
getData
());
}
}
user-web-app/src/main/resources/application.yml
浏览文件 @
93c64689
...
...
@@ -16,7 +16,7 @@ spring:
dubbo
:
# Spring Cloud Alibaba Dubbo 专属配置
cloud
:
subscribed-services
:
'
user-service,
system-service'
# 设置订阅的应用列表,默认为 * 订阅所有应用
subscribed-services
:
'
user-service,system-service'
# 设置订阅的应用列表,默认为 * 订阅所有应用
# Dubbo 服务消费者的配置
consumer
:
timeout
:
10000
...
...
@@ -26,3 +26,5 @@ dubbo:
version
:
1.0.0
OAuth2Rpc
:
version
:
1.0.0
SystemLogRPC
:
version
:
1.0.0
user/user-start/src/main/java/cn/iocoder/mall/user/application/controller/users/PassportController.java
deleted
100644 → 0
浏览文件 @
d89e5bad
package
cn
.
iocoder
.
mall
.
user
.
application
.
controller
.
users
;
import
cn.iocoder.common.framework.constant.UserTypeEnum
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.system.api.OAuth2Service
;
import
cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO
;
import
cn.iocoder.mall.system.api.dto.oauth2.OAuth2RefreshTokenDTO
;
import
cn.iocoder.mall.user.api.UserService
;
import
io.swagger.annotations.Api
;
import
org.apache.dubbo.config.annotation.Reference
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
cn
.
iocoder
.
common
.
framework
.
vo
.
CommonResult
.
success
;
@RestController
@RequestMapping
(
"users/passport"
)
@Api
(
"Passport 模块"
)
public
class
PassportController
{
@Reference
(
validation
=
"true"
,
version
=
"${dubbo.consumer.OAuth2Service.version}"
)
private
OAuth2Service
oauth2Service
;
@Reference
(
validation
=
"true"
,
version
=
"${dubbo.provider.UserService.version}"
)
private
UserService
userService
;
// TODO 功能:手机密码登陆
// @PostMapping("/mobile/pwd/login")
// public OAuth2AccessToken mobileLogin(@RequestParam("mobile") String mobile,
// @RequestParam("password") String password) {
// return oauth2Service.getAccessToken(clientId, clientSecret, mobile, password);
// }
// TODO 芋艿,改绑手机号
// TODO 功能:qq 登陆
@PostMapping
(
"/qq/login"
)
public
String
qqLogin
()
{
return
null
;
}
// TODO 功能:qq 绑定
@PostMapping
(
"/qq/bind"
)
public
String
qqBind
()
{
return
null
;
}
@PostMapping
(
"/refresh_token"
)
// TODO 功能:刷新 token
public
CommonResult
<
OAuth2AccessTokenBO
>
refreshToken
(
@RequestParam
(
"refreshToken"
)
String
refreshToken
)
{
return
success
(
oauth2Service
.
refreshToken
(
new
OAuth2RefreshTokenDTO
().
setRefreshToken
(
refreshToken
)
.
setUserType
(
UserTypeEnum
.
USER
.
getValue
())));
}
// TODO 功能:退出,销毁 token
}
user/user-start/src/main/java/cn/iocoder/mall/user/application/controller/users/UserController.java
deleted
100644 → 0
浏览文件 @
d89e5bad
package
cn
.
iocoder
.
mall
.
user
.
application
.
controller
.
users
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.user.api.UserService
;
import
cn.iocoder.mall.user.api.bo.UserBO
;
import
cn.iocoder.mall.user.api.dto.UserUpdateDTO
;
import
cn.iocoder.mall.user.application.convert.UserConvert
;
import
cn.iocoder.mall.user.application.vo.users.UsersUserVO
;
import
cn.iocoder.mall.user.sdk.annotation.RequiresLogin
;
import
cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.dubbo.config.annotation.Reference
;
import
org.springframework.web.bind.annotation.*
;
import
static
cn
.
iocoder
.
common
.
framework
.
vo
.
CommonResult
.
success
;
@RestController
@RequestMapping
(
"/users/user"
)
@Api
(
"用户模块"
)
public
class
UserController
{
@Reference
(
validation
=
"true"
,
version
=
"${dubbo.provider.UserService.version}"
)
private
UserService
userService
;
@GetMapping
(
"/info"
)
@RequiresLogin
@ApiOperation
(
value
=
"用户信息"
)
public
CommonResult
<
UsersUserVO
>
info
()
{
UserBO
userResult
=
userService
.
getUser
(
UserSecurityContextHolder
.
getContext
().
getUserId
());
return
success
(
UserConvert
.
INSTANCE
.
convert2
(
userResult
));
}
@PostMapping
(
"/update_avatar"
)
@RequiresLogin
@ApiOperation
(
value
=
"更新头像"
)
public
CommonResult
<
Boolean
>
updateAvatar
(
@RequestParam
(
"avatar"
)
String
avatar
)
{
// 创建
UserUpdateDTO
userUpdateDTO
=
new
UserUpdateDTO
().
setId
(
UserSecurityContextHolder
.
getContext
().
getUserId
())
.
setAvatar
(
avatar
);
// 更新头像
return
success
(
userService
.
updateUser
(
userUpdateDTO
));
}
@PostMapping
(
"/update_nickname"
)
@RequiresLogin
@ApiOperation
(
value
=
"更新昵称"
)
public
CommonResult
<
Boolean
>
updateNickname
(
@RequestParam
(
"nickname"
)
String
nickname
)
{
// 创建
UserUpdateDTO
userUpdateDTO
=
new
UserUpdateDTO
().
setId
(
UserSecurityContextHolder
.
getContext
().
getUserId
())
.
setNickname
(
nickname
);
// 更新头像
return
success
(
userService
.
updateUser
(
userUpdateDTO
));
}
}
user/user-start/src/main/java/cn/iocoder/mall/user/application/convert/UserConvert.java
deleted
100644 → 0
浏览文件 @
d89e5bad
package
cn
.
iocoder
.
mall
.
user
.
application
.
convert
;
import
cn.iocoder.mall.user.api.bo.UserBO
;
import
cn.iocoder.mall.user.api.bo.UserPageBO
;
import
cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO
;
import
cn.iocoder.mall.user.application.vo.users.UsersUserVO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mappings
;
import
org.mapstruct.factory.Mappers
;
@Mapper
public
interface
UserConvert
{
UserConvert
INSTANCE
=
Mappers
.
getMapper
(
UserConvert
.
class
);
@Mappings
({})
AdminsUserPageVO
convert
(
UserPageBO
result
);
@Mappings
({})
UsersUserVO
convert2
(
UserBO
result
);
}
user/user-start/src/main/java/cn/iocoder/mall/user/application/vo/users/UsersAccessTokenVO.java
deleted
100644 → 0
浏览文件 @
d89e5bad
package
cn
.
iocoder
.
mall
.
user
.
application
.
vo
.
users
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
@ApiModel
(
"认证令牌 VO"
)
@Data
@Accessors
(
chain
=
true
)
public
class
UsersAccessTokenVO
{
@ApiModelProperty
(
value
=
"访问令牌"
,
required
=
true
,
example
=
"2e3d7635c15e47e997611707a237859f"
)
private
String
accessToken
;
@ApiModelProperty
(
value
=
"刷新令牌"
,
required
=
true
,
example
=
"d091e7c35bbb4313b0f557a6ef23d033"
)
private
String
refreshToken
;
@ApiModelProperty
(
value
=
"过期时间,单位:秒"
,
required
=
true
,
example
=
"2879"
)
private
Integer
expiresIn
;
}
user/user-start/src/main/java/cn/iocoder/mall/user/application/vo/users/UsersMobileRegisterVO.java
deleted
100644 → 0
浏览文件 @
d89e5bad
package
cn
.
iocoder
.
mall
.
user
.
application
.
vo
.
users
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
@ApiModel
(
"手机注册结果 VO"
)
@Data
@Accessors
(
chain
=
true
)
public
class
UsersMobileRegisterVO
{
@ApiModelProperty
(
value
=
"访问令牌"
,
required
=
true
,
example
=
"2e3d7635c15e47e997611707a237859f"
)
private
String
accessToken
;
@ApiModelProperty
(
value
=
"刷新令牌"
,
required
=
true
,
example
=
"d091e7c35bbb4313b0f557a6ef23d033"
)
private
String
refreshToken
;
@ApiModelProperty
(
value
=
"过期时间,单位:秒"
,
required
=
true
,
example
=
"2879"
)
private
Integer
expiresIn
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论