JDKHOME JDKHOME
  • Web

    • 权限框架Twiggy
    • 脚手架BLZO
  • 杂货
技术思考
  • Kubernetes
  • 文档
  • jdkhome
  • 友链
  • 版权声明
  • 分类
  • 标签
  • 归档
  • Web

    • 权限框架Twiggy
    • 脚手架BLZO
  • 杂货
技术思考
  • Kubernetes
  • 文档
  • jdkhome
  • 友链
  • 版权声明
  • 分类
  • 标签
  • 归档
  • 简述

  • blzo脚手架

  • blzo-ex脚手架扩展

    • blzo-ex扩展使用文档
    • blzo基础包
    • 常见工具类
    • 权限管理
    • 用户登陆功能集成
      • 说明
      • 引入
      • 使用
        • 登陆
        • 服务端接口鉴权
        • 前端接口传递token
    • 接口版本控制
    • 分布式锁集成
    • 根据ip获取对应城市
    • EMQ推送服务集成
    • google身份认证集成
  • Blzo
  • blzo-ex脚手架扩展
linkji
2019-07-31

用户登陆功能集成

# blzo-ex-usignin 用户登陆功能集成

# 说明

引入此包可以在blzo中直接实现用户登陆、鉴权等功能。

# 引入

gradle

// https://mvnrepository.com/artifact/com.jdkhome.blzo/blzo-ex-usignin
compile group: 'com.jdkhome.blzo', name: 'blzo-ex-usignin', version: 0.3.0.1.RELEASE
1
2

maven

<!-- https://mvnrepository.com/artifact/com.jdkhome.blzo/blzo-ex-usignin -->
<dependency>
    <groupId>com.jdkhome.blzo</groupId>
    <artifactId>blzo-ex-usignin</artifactId>
    <version>0.3.0.1.RELEASE</version>
</dependency>
1
2
3
4
5
6

# 使用

# 登陆

在身份验证通过后,生成登陆token

@Autowired
TokenManager tokenManager;

String token = tokenManager.createToken(user.getId());
1
2
3
4

# 服务端接口鉴权

@UserSignin
@Api("测试用户登陆")
@RequestMapping(value = "/test", method = RequestMethod.POST)
public ApiResponse apiTest(@CurrentUser Integer userId) {

    // 在controller方法上加上@UserSignin注解 表示使用该接口需要用户登录

    // 在方法参数中加入 @CurrentUser Integer userId ,以获取调用该接口的用户Id userId一定不会为空
    
    return ApiResponse.success();
}
1
2
3
4
5
6
7
8
9
10
11
@UserMaybeSignin
@Api("测试用户可能登陆")
@RequestMapping(value = "/test2", method = RequestMethod.POST)
public ApiResponse apiTest(@CurrentUser Integer userId) {

    // 在controller方法上加上@UserMaybeSignin注解 表示使用该接口需要用户登录,也可以不登录

    // 在方法参数中加入 @CurrentUser Integer userId ,以获取调用该接口的用户Id userId可能为空
    
    return ApiResponse.success();
}
1
2
3
4
5
6
7
8
9
10
11

# 前端接口传递token

在header中增加token

token = 'xxxxx'
1
上次更新: 2020/06/11, 18:06:00

← 权限管理 接口版本控制 →

最近更新
01
搭建redis
11-21
02
istio安装
10-25
03
搭建K8S高可用集群
09-13
更多文章>
鄂ICP备15015406号 | Copyright © 2015-2020 jdkhome
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式