-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthApiController.java
More file actions
36 lines (30 loc) · 947 Bytes
/
AuthApiController.java
File metadata and controls
36 lines (30 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.gold.moni.webapi.controller.base;
import com.gold.moni.webapi.filter.jwt.attr.PowerFilter;
import com.gold.moni.webapi.filter.jwt.data.JwtUser;
import com.gold.moni.webapi.domain.vm.UserInfoVM;
import org.springframework.security.core.context.SecurityContextHolder;
/**
* 权限控制器
*/
@PowerFilter
public class AuthApiController extends BaseApiController {
/**
* 当前用户身份
* @return
*/
public UserInfoVM currentUser(){
Object user = SecurityContextHolder
.getContext()
.getAuthentication()
.getPrincipal();
return createUserInfoVM((JwtUser)user);
}
// region Helper
private UserInfoVM createUserInfoVM(JwtUser jwtUser){
return new UserInfoVM(
jwtUser.getId(),
jwtUser.getUsername(),
jwtUser.getLastLoginDate());
}
// endregion
}