在 PlantUML 的活动图中包含图标?

问题描述 投票:0回答:2

背景

为了加深我对 SSH 如何使用的理解,我使用 Domain Story 在 PlantUML 中绘制了一个图表: 实例

但是,我觉得它看起来有点混乱,因此我想将其转换为序列图

错误

当我尝试将图标导入序列图中时:

@startuml
actor Bob #red
' The only difference between actor
'and participant is the drawing
participant Alice
participant "I have a really\nlong name" as L #99FF99
/' You can also declare:
   participant L as "I have a really\nlong name"  #99FF99
  '/

' This is required to grant access to all icons.
!include <material/common>
' This imports the actual door icon.
!include <material/door>
MA_DOOR(Purple, 1, setup_public_key, rectangle, "Public key"){}


Alice->Bob: Authentication Request
Bob->Alice: Authentication Response
Bob->L: Log transaction
@enduml

它抛出

矩形“颜色:紫色<$ma_door{schale=1}> 公钥”作为 setup_public_key <>{}

查看实例

问题

如何在序列图中包含

material/common
图标,如
door
key
quiz
等?

代码

@startuml
'java -jar plantuml.jar /home/name/git/bash/bash-ssh-over-tor/visual/usage.uml

' This allows the user to create stories.
!include https://raw.githubusercontent.com/johthor/DomainStory-PlantUML/main/domainStory.puml

' This is required to grant access to all icons.
!include <material/common>
' This imports the actual door icon.
!include <material/door>
!include <material/account_key>
!include <material/key>
!include <material/cancel>
'!include <material/quiz>
!include <material/help>
!include <material/thumb_up>

Boundary("Usage") {
    Person(Alice)
    System(Leader)
    System(Follower)
    Boundary("keypair") {

        ' This creates a purple door icon.
        MA_DOOR(Purple, 1, setup_public_key, rectangle, "Public key")
        MA_KEY(Green, 1, setup_private_key, rectangle, "Private key")
    }
    ' This creates a green door. The rectangle places the icon in a rectangle.
    MA_ACCOUNT_KEY(Green, 1, setup_authorized_key, rectangle, "Authorised Public Key:\n any user that proves it has a\n private key belonging to this public key\n can have access.")

    MA_KEY(Green, 1, same_setup_private_key, rectangle, "Private key")
    MA_DOOR(Purple, 1, same_setup_public_key, rectangle, "Public key")

    MA_THUMB_UP(green, 1, solution, rectangle, "Solution")
    MA_HELP(Orange, 1, challenge, rectangle, "Challenge")
    MA_CANCEL(Red, 1, same_setup_cancel, rectangle, "This Public Key is not authorised.")
    MA_CANCEL(Red, 1, solution_rejection, rectangle, "This solution to the challenge\n was invalid or did not match the authorized key.")
}


activity(l, Leader, "Has SSH access into Follower", Follower)
activity(k, setup_authorized_key, "If the solution is valid\n and matches the Authorized\n Public key, SSH access is\n granted to the Leader", Leader)
activity(j, setup_authorized_key, "If the solution is invalid\n or does not match the Authorized Public key,\n SSH access is rejected", solution_rejection)
activity(i, Follower, "checks that the solution", solution, " is valid and matches the Authorised Public Key ", setup_authorized_key)
activity(i, solution, "and provided to ", Follower)
activity(h, challenge, "is solved", solution)
activity(g, Leader, "takes private key", setup_private_key, "and solves the challenge", challenge)
activity(f, challenge, to, Leader)
activity(e, setup_authorized_key, "If the public key is authorized\n, give a challenge", challenge)
activity(d, setup_authorized_key, "If the public key is not authorized, decline access.\n", same_setup_cancel)
activity(c, Follower, "checks is that public key: ", same_setup_public_key, "an authorised public key?", setup_authorized_key)
activity(b, Leader, "and asks Follower:\n ''Can I SSH access you with this Public Key?''", setup_public_key, to , Follower)
activity(a, Alice, "on the Leader machine", Leader)
@enduml

sequence-diagram plantuml
2个回答
1
投票

当我尝试将图标导入到序列图中时:...它抛出:

导入不是错误的根源。 问题在于宏 (

MA_DOOR
) 创建了一个元素 (
rectangle
),该元素末尾有
{}
。 它与序列图符号不兼容(即使您使用
allowmixing
)。

解决方案是直接在元素中使用精灵 (

<$ma_door{scale=1}>
):

@startuml
'allowmixing
actor Bob #red
!include <material/common>
!include <material/door>
' the following macro makes a rectangle (or something with {} at the end)
'   and is not compatible with a sequence diagram
'MA_DOOR(Purple, 1, setup_public_key, rectangle, "Public key"){}

' use the $ma_door sprite inside a participant (or actor)
participant "<color:blue>Door<$ma_door{scale=1}>" as door

Alice -> door : open
Alice->Bob: Authentication Request
Bob->Alice: Authentication Response
Bob->L: Log transaction
@enduml

enter image description here


0
投票

答案的实质是由@Fuhrmanator给出的。为了完整起见,附上 SSH 初始设置和使用的两个 plantuml 序列图。

初始 SSH 设置

@startuml
'java -jar plantuml.jar /home/name/git/bash/bash-ssh-over-tor/visual/usage.uml

' Make straight lines.
skinparam linetype ortho

' This is required to grant access to all icons.
' Full list is available at: https://github.com/plantuml/plantuml-stdlib/tree/master/material
!include <material/common>
' This imports the actual door icon.
!include <material/door>
!include <material/laptop>
!include <material/account_key>
!include <material/key>
!include <material/cancel>
!include <material/help>
!include <material/thumb_up>

'allowmixing

Actor Alice as alice
participant "<color:blue>Leader<$ma_laptop{scale=1}>" as leader
box "Private- & Public Keypair" #LightBlue
    participant "<color:Green>Private Key<$ma_key{scale=1}>" as private_key
    participant "<color:Blue>Public Key<$ma_door{scale=1}>" as public_key
end box

participant "<color:Blue>Follower<$ma_laptop{scale=1}>" as follower
participant "<color:Green>Authorized Public Keys<$ma_account_key{scale=1}>" as authorized_public_keys

alice -> leader : Create SSH private- and public key pair.
leader -> private_key : Create private key.
leader -> public_key : Create public key based on private key.

activate public_key
    public_key -> follower : Copy public key into follower.
    leader -> follower : Tell Follower to add the public key to\n the authorized lists.\n Anyone who can prove they\n have the private key belonging\n to this public key, can\n have access to Follower.
deactivate public_key

follower -> authorized_public_keys : Add the Public Key\n to the list of\n Authorized Public Keys.

@enduml

SSH 用法

@startuml
'java -jar plantuml.jar /home/name/git/bash/bash-ssh-over-tor/visual/usage.uml

' Make straight lines.
skinparam linetype ortho

' This is required to grant access to all icons.
' Full list is available at: https://github.com/plantuml/plantuml-stdlib/tree/master/material
!include <material/common>
' This imports the actual door icon.
!include <material/door>
!include <material/laptop>
!include <material/account_key>
!include <material/key>
!include <material/cancel>
!include <material/help>
!include <material/thumb_up>

'allowmixing

Actor Alice as alice
participant "<color:blue>Leader<$ma_laptop{scale=1}>" as leader
box "Private- & Public Keypair" #Gold
    participant "<color:Green>Private Key<$ma_key{scale=1}>" as private_key
    participant "<color:Blue>Public Key<$ma_door{scale=1}>" as public_key
end box

participant "<color:Green>Solution<$ma_thumb_up{scale=1}>" as solution
participant "<color:Orange>Challenge<$ma_help{scale=1}>" as challenge
participant "<color:blue>Follower<$ma_laptop{scale=1}>" as follower
participant "<color:Green>Authorized Public Keys<$ma_account_key{scale=1}>" as authorized_public_keys

alice -> leader : "Give me SSH access to Follower."
leader -> public_key : "Get the public key."
public_key -> follower : "Can I get SSH access into you with this public key?"
follower -> authorized_public_keys : "Check if the public key is in authorised public key list."

alt #Pink Failure
    authorized_public_keys -> follower: Public Key not Authorized. Access rejected.
else #LightBlue Successful case
    authorized_public_keys -> follower: Public Key is Authorized.
    follower -> challenge : Create a challenge to that needs to be solved using the private key belonging to the provided public key.
    challenge -> leader : Request to solve challenge.
end

leader -> private_key : Use private key to solve challenge.
private_key -> solution : Generate solution 'signed with private key'.
solution -> follower : Submit solution to Follower.
alt #Pink Failure
    follower -> follower: Solution is not valid. Access rejected.
else #LightGreen Successful case
    follower -> alice: Solution is valid. SSH access granted.
end

@enduml

© www.soinside.com 2019 - 2024. All rights reserved.