Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
D
data-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
licc
data-server
Commits
5926295c
Commit
5926295c
authored
Feb 23, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口增加权限token
parent
c9af998c
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
186 additions
and
43 deletions
+186
-43
UsersMapper.java
...mapper/src/main/java/cn/wisenergy/mapper/UsersMapper.java
+7
-0
UsersMapper.xml
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
+9
-13
AccountService.java
...rc/main/java/cn/wisenergy/service/app/AccountService.java
+8
-0
UserService.java
...e/src/main/java/cn/wisenergy/service/app/UserService.java
+8
-1
AccountServiceImpl.java
...ava/cn/wisenergy/service/app/impl/AccountServiceImpl.java
+6
-0
UserServiceImpl.java
...n/java/cn/wisenergy/service/app/impl/UserServiceImpl.java
+10
-3
AccountController.java
...wisenergy/web/admin/controller/app/AccountController.java
+13
-1
UserController.java
...cn/wisenergy/web/admin/controller/app/UserController.java
+70
-0
Swagger2.java
...c/main/java/cn/wisenergy/web/config/swagger/Swagger2.java
+41
-11
ShiroConfig.java
...min/src/main/java/cn/wisenergy/web/shiro/ShiroConfig.java
+13
-13
AuthRealm.java
...rc/main/java/cn/wisenergy/web/shiro/filter/AuthRealm.java
+1
-1
No files found.
wisenergy-mapper/src/main/java/cn/wisenergy/mapper/UsersMapper.java
View file @
5926295c
...
...
@@ -43,4 +43,11 @@ public interface UsersMapper extends BaseMapper<User> {
List
<
User
>
getList
(
Map
<
String
,
Object
>
map
);
/**
* 获取用户信息
* @param userId 用户id
* @return 用户信息
*/
User
getByUserId
(
@Param
(
"userId"
)
Integer
userId
);
}
wisenergy-mapper/src/main/resources/mapper/UsersMapper.xml
View file @
5926295c
...
...
@@ -128,20 +128,16 @@
from
<include
refid=
"table"
/>
<where>
is_delete=0
<if
test=
"startTime != null"
>
and create_time
between #{startTime}
</if>
<if
test=
"endTime != null"
>
and #{endTime}
</if>
<if
test=
"userName != null"
>
and user_name like ('%' #{userName} '%')
</if>
</where>
</select>
<if
test=
"phone != null"
>
and phone like ('%' #{phone} '%')
</if>
order by create_time desc
limit #{pageNo},#{pageSize}
<select
id=
"getByUserId"
resultType=
"cn.wisenergy.model.app.User"
>
select
<include
refid=
"cols_all"
/>
from
<include
refid=
"table"
/>
<where>
user_id=#{userId}
</where>
</select>
</mapper>
wisenergy-service/src/main/java/cn/wisenergy/service/app/AccountService.java
View file @
5926295c
...
...
@@ -2,6 +2,7 @@ package cn.wisenergy.service.app;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.app.AccountInfo
;
import
cn.wisenergy.model.app.OrderInfo
;
import
java.util.List
;
...
...
@@ -17,4 +18,11 @@ public interface AccountService {
* @return true or false
*/
R
<
Boolean
>
orderRebate
(
List
<
OrderInfo
>
list
);
/**
* 获取账户信息
* @param userId 用户id
* @return 账户信息
*/
R
<
AccountInfo
>
getByUserId
(
Integer
userId
);
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/UserService.java
View file @
5926295c
...
...
@@ -18,7 +18,14 @@ public interface UserService {
* @param userId 用户id
* @return 用户信息
*/
User
getById
(
Integer
userId
);
R
<
User
>
getById
(
Integer
userId
);
/**
* 获取用户信息
* @param userId 用户id
* @return 用户信息
*/
User
getByUserId
(
Integer
userId
);
R
<
List
<
User
>>
test
();
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/AccountServiceImpl.java
View file @
5926295c
...
...
@@ -76,4 +76,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
}
return
R
.
ok
(
0
,
true
);
}
@Override
public
R
<
AccountInfo
>
getByUserId
(
Integer
userId
)
{
AccountInfo
accountInfo
=
accountMapper
.
getByUserId
(
userId
);
return
R
.
ok
(
accountInfo
);
}
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/UserServiceImpl.java
View file @
5926295c
...
...
@@ -8,13 +8,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* @author 86187
* @ Description: 用户接口实现
* @ Author : 86187
* @ Date : 2021/1/6 16:11
* @author 86187
*/
@Service
@Slf4j
...
...
@@ -24,8 +25,14 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
private
UsersMapper
usersMapper
;
@Override
public
User
getById
(
Integer
userId
)
{
return
null
;
public
R
<
User
>
getById
(
Integer
userId
)
{
return
R
.
ok
(
usersMapper
.
getByUserId
(
userId
));
}
@Override
public
User
getByUserId
(
Integer
userId
)
{
return
usersMapper
.
getByUserId
(
userId
);
}
@Override
...
...
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/AccountController.java
View file @
5926295c
package
cn
.
wisenergy
.
web
.
admin
.
controller
.
app
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.app.AccountInfo
;
import
cn.wisenergy.model.app.User
;
import
cn.wisenergy.service.app.AccountService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -15,6 +20,13 @@ import org.springframework.web.bind.annotation.*;
@Slf4j
public
class
AccountController
{
@Autowired
private
AccountService
accountSerivce
;
private
AccountService
accountService
;
@ApiOperation
(
value
=
"获取账户信息"
,
notes
=
"获取账户信息"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"userId"
,
value
=
"用户id"
,
dataType
=
"int"
)
@GetMapping
(
"/getByUserId"
)
public
R
<
AccountInfo
>
getByUserId
(
Integer
userId
){
return
accountService
.
getByUserId
(
userId
);
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/UserController.java
0 → 100644
View file @
5926295c
package
cn
.
wisenergy
.
web
.
admin
.
controller
.
app
;
import
cn.wisenergy.common.constant.RedisConsts
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.app.User
;
import
cn.wisenergy.service.app.UserService
;
import
cn.wisenergy.web.common.BaseController
;
import
cn.wisenergy.web.config.JwtConfig
;
import
cn.wisenergy.web.shiro.JwtUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author 86187
*/
@Api
(
tags
=
"用户管理"
)
@RestController
@RequestMapping
(
"/user"
)
@Slf4j
public
class
UserController
extends
BaseController
{
@Autowired
private
UserService
userService
;
@Autowired
private
JwtUtil
jwtUtil
;
@Autowired
private
JwtConfig
jwtConfig
;
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
@ApiOperation
(
value
=
"获取用户信息"
,
notes
=
"获取用户信息"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"userId"
,
value
=
"用户id"
,
dataType
=
"int"
)
@GetMapping
(
"/getByUserId"
)
public
R
<
User
>
getByUserId
(
Integer
userId
){
return
userService
.
getById
(
userId
);
}
/**
* shiro登录
*
* @return
*/
@ApiOperation
(
value
=
"获取token接口"
,
notes
=
"获取token接口"
,
httpMethod
=
"POST"
)
@PostMapping
(
value
=
"/login"
)
public
R
<
String
>
login
(
Integer
id
)
{
if
(
null
==
id
)
{
return
R
.
error
(
"入参为空!"
);
}
//用户信息
User
user
=
userService
.
getByUserId
(
id
);
// 创建token
String
token
=
jwtUtil
.
generateToken
(
user
);
// 保存Redis
redisTemplate
.
opsForValue
().
set
(
RedisConsts
.
JWT_ACCESS_TOKEN
+
token
,
token
);
return
R
.
ok
(
token
);
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/config/swagger/Swagger2.java
View file @
5926295c
...
...
@@ -3,14 +3,21 @@ package cn.wisenergy.web.config.swagger;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.ResponseEntity
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.*
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spi.service.contexts.SecurityContext
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
import
java.time.LocalDate
;
import
java.util.List
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
//注解开启 swagger2 功能
@EnableSwagger2
//注解标示,这是一个配置类,@Configuation注解包含了@Component注解
...
...
@@ -25,27 +32,50 @@ public class Swagger2 {
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
//调用apiInfo方法,创建一个ApiInfo实例,里面是展示在文档页面信息内容
.
select
()
//控制暴露出去的路径下的实例
//如果某个接口不想暴露,可以使用以下注解
//@ApiIgnore 这样,该接口就不会暴露在 swagger2
的页面下
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"cn.wisenergy.web.admin.controller
.app
"
))
//@ApiIgnore 这样,该接口就不会暴露在 swagger2
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"cn.wisenergy.web.admin.controller"
))
.
paths
(
PathSelectors
.
any
())
.
build
();
.
build
()
.
apiInfo
(
apiInfo
())
.
pathMapping
(
"/"
)
.
directModelSubstitute
(
LocalDate
.
class
,
String
.
class
)
.
genericModelSubstitutes
(
ResponseEntity
.
class
)
.
useDefaultResponseMessages
(
false
)
.
securitySchemes
(
newArrayList
(
apiKey
()))
.
securityContexts
(
newArrayList
(
securityContext
()))
.
enableUrlTemplating
(
false
);
}
//构建 api文档的详细信息函数
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
//页面标题
.
title
(
"西田森app"
)
//创建人
.
contact
(
new
Contact
(
"WYY"
,
""
,
""
))
//版本号
.
version
(
"2.0"
)
.
title
(
"Api Documentation"
)
//描述
.
description
(
"API接口描述"
)
.
description
(
"Api Documentation"
)
.
contact
(
new
Contact
(
"Danny Lee"
,
"http://blog.51cto.com/7308310"
,
"liqinwyyx@163.com"
))
//版本号
.
version
(
"1.0.0"
)
.
build
();
}
private
ApiKey
apiKey
()
{
return
new
ApiKey
(
"BearerToken"
,
"Authorization"
,
"header"
);
}
private
SecurityContext
securityContext
()
{
return
SecurityContext
.
builder
()
.
securityReferences
(
defaultAuth
())
.
forPaths
(
PathSelectors
.
regex
(
"/.*"
))
.
build
();
}
List
<
SecurityReference
>
defaultAuth
()
{
AuthorizationScope
authorizationScope
=
new
AuthorizationScope
(
"global"
,
"accessEverything"
);
AuthorizationScope
[]
authorizationScopes
=
new
AuthorizationScope
[
1
];
authorizationScopes
[
0
]
=
authorizationScope
;
return
newArrayList
(
new
SecurityReference
(
"BearerToken"
,
authorizationScopes
));
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/shiro/ShiroConfig.java
View file @
5926295c
...
...
@@ -53,19 +53,19 @@ public class ShiroConfig {
// 设置拦截器集合
Map
<
String
,
String
>
filterChainDefinitionMap
=
new
LinkedHashMap
<
String
,
String
>();
//
filterChainDefinitionMap.put("/authInformation/save", "anon");//存储设备IMEI号和手机SIM卡ID号
//
filterChainDefinitionMap.put("/sys/login", "anon"); // 登录页面-身份认证
//
filterChainDefinitionMap.put("/sys/registered", "anon"); // 注册页面
//
filterChainDefinitionMap.put("/swagger-ui.html", "anon"); // swagger接口-匿名访问
//
filterChainDefinitionMap.put("/swagger/**", "anon");
// filterChainDefinitionMap.put("/admin/anon
/**", "anon");
//
filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
//
filterChainDefinitionMap.put("/swagger-resources/**", "anon");
//
filterChainDefinitionMap.put("/v2/api-docs", "anon");
//
filterChainDefinitionMap.put("/upload_flowChart/**", "anon");//图片地址
//
filterChainDefinitionMap.put("/webSocket/**", "anon");//socket
//
filterChainDefinitionMap.put("/message/**", "anon");//消息推送接口
//
filterChainDefinitionMap.put("/**", "oauth2"); // 其他路径均需要身份认证,一般位于最下面,优先级最低
filterChainDefinitionMap
.
put
(
"/authInformation/save"
,
"anon"
);
//存储设备IMEI号和手机SIM卡ID号
filterChainDefinitionMap
.
put
(
"/sys/login"
,
"anon"
);
// 登录页面-身份认证
filterChainDefinitionMap
.
put
(
"/sys/registered"
,
"anon"
);
// 注册页面
filterChainDefinitionMap
.
put
(
"/swagger-ui.html"
,
"anon"
);
// swagger接口-匿名访问
filterChainDefinitionMap
.
put
(
"/swagger/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/user
/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/webjars/springfox-swagger-ui/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/swagger-resources/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/v2/api-docs"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/upload_flowChart/**"
,
"anon"
);
//图片地址
filterChainDefinitionMap
.
put
(
"/webSocket/**"
,
"anon"
);
//socket
filterChainDefinitionMap
.
put
(
"/message/**"
,
"anon"
);
//消息推送接口
filterChainDefinitionMap
.
put
(
"/**"
,
"oauth2"
);
// 其他路径均需要身份认证,一般位于最下面,优先级最低
// 设置拦截器
shiroFilterFactoryBean
.
setFilterChainDefinitionMap
(
filterChainDefinitionMap
);
...
...
wisenergy-web-admin/src/main/java/cn/wisenergy/web/shiro/filter/AuthRealm.java
View file @
5926295c
...
...
@@ -99,7 +99,7 @@ public class AuthRealm extends AuthorizingRealm {
throw new IncorrectCredentialsException(RespCodeEnum.TOKEN_IS_NOT_TIMEOUT.getMsg());
}*/
//查询用户信息
User
user
=
authUserService
.
getById
(
userEntity
.
getId
());
User
user
=
authUserService
.
getBy
User
Id
(
userEntity
.
getId
());
// 判断请求token与redis中是否相同,如果token被刷新,则不判断
if
(!
refreshFlag
&&
!
StringUtils
.
equals
(
accessToken
,
redisToken
))
{
throw
new
IncorrectCredentialsException
(
RespCodeEnum
.
NO_AUTH_REQUEST
.
getMsg
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment