使用 Emacs 创建 OAuth 2.0 的 UML 序列图 | Linux 中国

2019 年 3 月 3 日 Linux中国
在审查 OAuth 2.0 实现或编写渗透测试报告时我习惯画出 UML 图。这方便让人理解发生了什么事情,并发现潜在的问题。毕竟,一图抵千言。
-- Peter Mosmans

看起来 OAuth 2.0 框架[1] 已经越来越广泛地应用于 web (和 移动) 应用。太棒了!

虽然协议本身并不复杂,但有很多的使用场景、流程和实现可供选择。正如生活中的大多数事物一样,魔鬼在于细节之中。

在审查 OAuth 2.0 实现或编写渗透测试报告时我习惯画出 UML 图。这方便让人理解发生了什么事情,并发现潜在的问题。毕竟,一图抵千言。

使用基于 GPL 开源协议 Emacs[2] 编辑器来实现,再加上基于 GPL 开源协议的工具 PlantUML[3] (也可以选择基于 Eclipse Public 协议的 Graphviz[4]) 很容易做到这一点。

Emacs 是世界上最万能的编辑器。在这种场景中,我们用它来编辑文本,并自动将文本转换成图片。PlantUML 是一个允许你用人类可读的文本来写 UML 并完成该转换的工具。Graphviz 是一个可视化的软件,这里我们可以用它来显示图片。

下载 预先编译好了的 PlantUML jar 文件 [5]Emacs[6] 还可以选择下载并安装 Graphviz[7]

安装并启动 Emacs,然后将下面 Lisp 代码(实际上是配置)写入你的启动文件中(~/.emacs.d/init.d),这段代码将会:

◈ 配置 org 模式(一种用来组织并编辑文本文件的模式)来使用 PlantUML
◈ 将  plantuml 添加到可识别的 “org-babel” 语言中(这让你可以在文本文件中执行源代码)
◈ 将 PlantUML 代码标注为安全的,从而允许执行
◈ 自动显示生成的结果图片
   
   
     
  1. ;; tell org-mode where to find the plantuml JAR file (specify the JAR file)
  2. (setq org-plantuml-jar-path (expand-file-name "~/plantuml.jar"))
  3. ;; use plantuml as org-babel language
  4. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
  5. ;; helper function
  6. (defun my-org-confirm-babel-evaluate (lang body)
  7. "Do not ask for confirmation to evaluate code for specified languages."
  8. (member lang '("plantuml")))
  9. ;; trust certain code as being safe
  10. (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
  11. ;; automatically show the resulting image
  12. (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)

如果你还没有启动文件,那么将该代码加入到 ~/.emacs.d/init.el 文件中然后重启 Emacs。

提示:Control-c Control-f 可以让你创建/打开(新)文件。Control-x Control-s 保存文件,而 Control-x Control-c 退出 Emacs。

这就结了!

要测试该配置,可以创建/打开(Control-c Control-f)后缀为 .org 的文件,例如 test.org。这会让 Emacs 切换到 org 模式并识别 “org-babel” 语法。

输入下面代码,然后在代码中输入 Control-c Control-c 来测试是否安装正常:

   
   
     
  1. #+BEGIN_SRC plantuml :file test.png
  2. @startuml
  3. version
  4. @enduml
  5. #+END_SRC

一切顺利的话,你会在 Emacs 中看到文本下面显示了一张图片。

注意:

要快速插入类似 #+BEGIN_SRC 和 #+END_SRC 这样的代码片段,你可以使用内置的 Easy Templates 系统:输入 <s 然后按下 TAB,它就会自动为你插入模板。

还有更复杂的例子,下面是生成上面图片的 UML 源代码:

   
   
     
  1. #+BEGIN_SRC plantuml :file t:/oauth2-abstract-protocol-flow.png
  2. @startuml
  3. hide footbox
  4. title Oauth 2.0 Abstract protocol flow
  5. autonumber
  6. actor user as "resource owner (user)"
  7. box "token stays secure" #FAFAFA
  8. participant client as "client (application)"
  9. participant authorization as "authorization server"
  10. database resource as "resource server"
  11. end box
  12. group user authorizes client
  13. client -> user : request authorization
  14. note left
  15. **grant types**:
  16. # authorization code
  17. # implicit
  18. # password
  19. # client_credentials
  20. end note
  21. user --> client : authorization grant
  22. end
  23. group token is generated
  24. client -> authorization : request token\npresent authorization grant
  25. authorization --> client :var: access token
  26. note left
  27. **response types**:
  28. # code
  29. # token
  30. end note
  31. end group
  32. group resource can be accessed
  33. client -> resource : request resource\npresent token
  34. resource --> client : resource
  35. end group
  36. @enduml
  37. #+END_SRC

你难道会不喜欢 Emacs 和开源工具的多功能性吗?


via: https://www.onwebsecurity.com/configuration/use-emacs-to-create-oauth-2-0-uml-sequence-diagrams.html

作者:Peter Mosmans[9] 选题:lujun9972 译者:lujun9972 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

登录查看更多
0

相关内容

统一建模语言(UML,Unified Modeling Language)是由国际软件行业组织 OMG(对象管理集团 omg.org)自 1997 年起研发的用于 IT 各领域建模的一套标准、通用、图形化的面向对象(OO)建模语言,对应的国际标准为 ISO/IEC 19505。UML 具有简单、直观、形象、表达力强等特点,因此不仅常用于复杂软件系统架构的建模和面向对象分析与设计(OOAD),也可用于复杂业务流程及系统需求的建模。UML 当前的最新版本为 v2.5(2015.3)。 UML 起源于 3 位著名的软件工程方法学家 Grady Booch、James Rumbaugh、Ivar Jacobson 融合、统一了他们各自原来的建模语言和方法。
【2020新书】实战R语言4,323页pdf
专知会员服务
98+阅读 · 2020年7月1日
【2020新书】使用高级C# 提升你的编程技能,412页pdf
专知会员服务
56+阅读 · 2020年6月26日
【干货书】流畅Python,766页pdf,中英文版
专知会员服务
223+阅读 · 2020年3月22日
TensorFlow Lite指南实战《TensorFlow Lite A primer》,附48页PPT
专知会员服务
68+阅读 · 2020年1月17日
【电子书】C++ Primer Plus 第6版,附PDF
专知会员服务
83+阅读 · 2019年11月25日
UML建模工具一览(20190909 更新)
UMLChina
12+阅读 · 2019年9月9日
34个最优秀好用的Python开源框架
专知
9+阅读 · 2019年3月1日
如何编写完美的 Python 命令行程序?
CSDN
5+阅读 · 2019年1月19日
如何使用注意力模型生成图像描述?
AI研习社
9+阅读 · 2018年8月6日
使用PaddleFluid和TensorFlow训练序列标注模型
PaperWeekly
6+阅读 · 2018年7月11日
深度学习 | 免费使用Google Colab的GPU云计算平台
沈浩老师
11+阅读 · 2018年2月4日
Learning by Abstraction: The Neural State Machine
Arxiv
6+阅读 · 2019年7月11日
Nocaps: novel object captioning at scale
Arxiv
6+阅读 · 2018年12月20日
Doubly Attentive Transformer Machine Translation
Arxiv
4+阅读 · 2018年7月30日
Arxiv
7+阅读 · 2018年6月1日
Arxiv
4+阅读 · 2018年1月29日
VIP会员
相关VIP内容
【2020新书】实战R语言4,323页pdf
专知会员服务
98+阅读 · 2020年7月1日
【2020新书】使用高级C# 提升你的编程技能,412页pdf
专知会员服务
56+阅读 · 2020年6月26日
【干货书】流畅Python,766页pdf,中英文版
专知会员服务
223+阅读 · 2020年3月22日
TensorFlow Lite指南实战《TensorFlow Lite A primer》,附48页PPT
专知会员服务
68+阅读 · 2020年1月17日
【电子书】C++ Primer Plus 第6版,附PDF
专知会员服务
83+阅读 · 2019年11月25日
相关资讯
相关论文
Top
微信扫码咨询专知VIP会员