知识背景:
那年还是菜鸟,开始暗恋Java,像其他的菜鸟一样开始慢慢接触面向对象,硕士之前接触都是c、c++,其实对于面向对象的理解停留在认知阶段,后来自嘲没有女朋友,我可以new一个出来,现在有暗恋开始明恋,到然后喜欢上python,不过自从接触vert.x3和RXJava、netty后,又再次燃烧起我的欲望,最近接收需要为app提供微服务,对于无状态的,没有session、cookie,我们唯一能够提供的方式就是token,JSON Web Tokens(JWT).
JWT生成的token150个字符
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0NTEzMDQ3OTgsImV4cCI6MTQ1MTMwNDg1OH0=.5kK9_8s1ZyGZ-6EBN1wF01Mzxw1g-WZQzYXSFC_C41Y=
我们通过这个token进行交换,来进行权限的验证,是否该用户能否访问我们的服务端数据。
http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
我把token的放入我的redis中,存放时间为一分钟,然后加入refreshtoken存放10分钟,一般来说refreshtoken肯定比token时间要长,因为你还需要通过refreshtoken来获取token,refreshtoken是经过md5加密后,进行存放。
// this route is excluded from the auth handler router.get("/api/newToken").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); String generateToken = jwt.generateToken(new JsonObject(), new JWTOptions().setExpiresInSeconds(1 * 60)); ctx.response().end(generateToken); redisCacheService.put("token", generateToken, 1 * 60); byte[] result = Base64.encodeBase64(generateToken.getBytes()); System.out.println(" refreshToken " + new String(result)); System.out.println(" token " + generateToken); redisCacheService.put(new String(result), generateToken, 10 * 60); });
router.get("/refreshToken").handler(ctx -> { ctx.response().putHeader("Content-Type", "text/plain"); ctx.response().end(redisCacheService.get("")); } );
至于需要鉴权校验,需要使用到如下的包
<!-- spring-boot framework end--> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>${jjwt.version}</version> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-auth-jwt</artifactId> <version>${vertx.version}</version> </dependency>
Router router = Router.router(vertx); router.route("/*").handler(SoloAuthProvider.create(vertx, redisCacheService)); router.route("/*").handler(req -> { LOGGER.info("Any requests to URI starting '/' require login"); // No auth required req.next(); }); // Create a JWT Auth Provider JWTAuth jwt = JWTAuth.create(vertx, new JsonObject() .put("keyStore", new JsonObject() .put("type", "jceks") .put("path", "keystore.jceks") .put("password", "secret")));
至于vert.x3如何使用就不在这里过多叙述,在前面的文章已有聊过。
个人结论:
app的微服务校验这块完成后,接下来都是业务功能的开发,至于你是用spring、spring-boot以及mybatis还是其它的ORM不外乎就是增删改处理工作。
ps:有提供坐标杭州或者上海的公司的架构岗位,请随时联系本人,具体联系方式可以访问http://ibyoung.github.io
相关推荐
Vert.x 内核小巧轻便. 你只需使用你想要的部分. 它还可以完全嵌入到您现有的应用程序中--我们不会强迫您以特殊的方式构建应用程序,以便您可以使用 Vert.x. Vert.x核心为以下事情提供功能: 编写TCP客户端和服务器 ...
vertx-kue, Vert.x Blueprint项目 Vert.x Kue,这是由 Vert.x 支持的优先级任务队列 Vert.x Kue Vert.x Kue 是用 Vert.x 开发的优先级任务队列,并以的Redis支持。 它是 automattic/kue的Vert.x 实现版本。这个蓝图...
Vert.x是事件驱动的,其处理请求的高性能也是基于其事件机制。Vert.x的事件机制中有几个非常重要的概念:Event Loop、Event Loop Vertical、Worker Vertical、Event Bus、Vert.x Module。 Event Loop:即事件循环,...
Eclipse Vert.x is event driven and non blocking. This means your app can handle a lot of concurrency using a small number of kernel threads. Vert.x lets your app scale with minimal hardware.
Vert.x是一个在JVM开发reactive应用的框架,可用于开发异步、可伸缩、高并发的Web应用(虽然不限于web应用)。其目的在于为JVM提供一个Node.js的替代方案。开发者可以通过它使用JavaScript、Ruby、Groovy、Java,甚至...
在发布Vert.x实例时,需要传入一个VertxOptions来实现针对Vert.x的配置项的管理
《Vert.x应用开发实例教程》旨在为Vert.x的初学者和大中专院校学生提供易于入门,全面了解和掌握Vert.x框架技术和应用的教材和辅导资料,为使用Vert.x开发实时应用和企业级应用打下良好的基础。
vert.x-2.1.2.tar.gz 下载
vert.x结合springboot开发mqtt服务端,直接启动主类。
Vert.X-generator是基于javafx8开发的图形界面Vert.x代码生成器,使用 Apache FreeMarker 作为代码文件的模板,用户可以一键将数据库中的表生成为任意风格的.java代码文件(比如经典的三层模型);该工具支持所有实现JDBC...
Zero Ecotope Framework 是一个基于 Vert.x 的中间件容器,它可以帮助软件开发人员在 Vert.x 中快速开发和实施,集中精力处理项目需求中的业务逻辑而忽略开发过程中的部分细节,项目起源于早期在 Vert.x 生态中缺少...
vert.x中文 PDF 下载
摘要:作为异步无阻塞的网络框架,Vert.x的参照物是Node.js,基本可以完成Node.js能完成的所有事情。它是作者目前见过功能最强大,依赖第三方库最少的Java框架。本文将带你深入了解Vert.x。Vert.x的由来Vert.x诞生于...
vert.x是内存占用极小的快速开发框架,springboot模版项目
Vert.x系列: Vert.x介绍:https://blog.csdn.net/haoranhaoshi/article/details/89279096 Vert.x实战一:Vert.x通过Http发布数据:https://blog.csdn.net/haoranhaoshi/article/details/89284847 Vert.x实战二:TCP...
Vert.x3.4.2full.zip
A beautifully clear tutorial on Vert.x, it helps you develop a real-time web application from the ground up. Overview Get started with developing applications for the real-time web From concept to ...
A beautifully clear tutorial on Vert.x, it helps you develop a real-time web application from the ground up. Overview Get started with developing applications for the real-time web From concept to ...
Vert.x 初始demo, 里面有打包好的jar,可以直接运行