Linux中國

使用 Emacs 創建 OAuth 2.0 的 UML 序列圖

看起來 OAuth 2.0 框架 已經越來越廣泛地應用於 web (和 移動) 應用。太棒了!

雖然協議本身並不複雜,但有很多的使用場景、流程和實現可供選擇。正如生活中的大多數事物一樣,魔鬼在於細節之中。

在審查 OAuth 2.0 實現或編寫滲透測試報告時我習慣畫出 UML 圖。這方便讓人理解發生了什麼事情,並發現潛在的問題。畢竟,一圖抵千言。

使用基於 GPL 開源協議 Emacs 編輯器來實現,再加上基於 GPL 開源協議的工具 PlantUML (也可以選擇基於 Eclipse Public 協議的 Graphviz) 很容易做到這一點。

Emacs 是世界上最萬能的編輯器。在這種場景中,我們用它來編輯文本,並自動將文本轉換成圖片。PlantUML 是一個允許你用人類可讀的文本來寫 UML 並完成該轉換的工具。Graphviz 是一個可視化的軟體,這裡我們可以用它來顯示圖片。

下載 預先編譯好了的 PlantUML jar 文件Emacs 還可以選擇下載並安裝 Graphviz

安裝並啟動 Emacs,然後將下面 Lisp 代碼(實際上是配置)寫入你的啟動文件中(~/.emacs.d/init.d),這段代碼將會:

  • 配置 org 模式(一種用來組織並編輯文本文件的模式)來使用 PlantUML
  • plantuml 添加到可識別的 「org-babel」 語言中(這讓你可以在文本文件中執行源代碼)
  • 將 PlantUML 代碼標註為安全的,從而允許執行
  • 自動顯示生成的結果圖片
;; tell org-mode where to find the plantuml JAR file (specify the JAR file)
(setq org-plantuml-jar-path (expand-file-name "~/plantuml.jar"))

;; use plantuml as org-babel language
(org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))

;; helper function
(defun my-org-confirm-babel-evaluate (lang body)
"Do not ask for confirmation to evaluate code for specified languages."
(member lang '("plantuml")))

;; trust certain code as being safe
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)

;; automatically show the resulting image
(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 來測試是否安裝正常:

#+BEGIN_SRC plantuml :file test.png
@startuml
version
@enduml
#+END_SRC

一切順利的話,你會在 Emacs 中看到文本下面顯示了一張圖片。

注意:

要快速插入類似 #+BEGIN_SRC#+END_SRC 這樣的代碼片段,你可以使用內置的 Easy Templates 系統:輸入 <s 然後按下 TAB,它就會自動為你插入模板。

還有更複雜的例子,下面是生成上面圖片的 UML 源代碼:

#+BEGIN_SRC plantuml :file t:/oauth2-abstract-protocol-flow.png
@startuml
hide footbox
title Oauth 2.0 Abstract protocol flow
autonumber
actor user as "resource owner (user)"
box "token stays secure" #FAFAFA
participant client as "client (application)"
participant authorization as "authorization server"
database resource as "resource server"
end box

group user authorizes client
client -> user : request authorization
note left
**grant types**:
# authorization code
# implicit
# password
# client_credentials
end note
user --> client : authorization grant
end

group token is generated
client -> authorization : request tokennpresent authorization grant
authorization --> client :var: access token
note left
**response types**:
# code
# token
end note
end group

group resource can be accessed
client -> resource : request resourcenpresent token
resource --> client : resource
end group
@enduml
#+END_SRC

你難道會不喜歡 Emacs 和開源工具的多功能性嗎?

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

作者:Peter Mosmans 選題:lujun9972 譯者:lujun9972 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的電子郵箱地址不會被公開。 必填項已用 * 標註

    此站點使用Akismet來減少垃圾評論。了解我們如何處理您的評論數據

    More in:Linux中國