Including icons in Activity diagram in PlantUML?

359 Views Asked by At

Context

To improve my understanding on how SSH is used I drew a diagram in PlantUML using the Domain Story: Live Example enter image description here

However, I think it looks a bit chaotic, hence I would like to convert it into a sequence diagram instead.

Error

When I try to import an icon into the sequence diagram as:

@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

it throws

rectangle "color:Purple<$ma_door{schale=1}>\r Public Key" as setup_public_key <<MA_DOOR>>{}

See Live Example

Question

How can I include the material/common icons like door, key and quiz etc. in a sequence diagram?

Code

@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

2

There are 2 best solutions below

1
On BEST ANSWER

When I try to import an icon into the sequence diagram as: ... it throws:

The import is not the source of the error. The problem is with the line of the macro (MA_DOOR) that creates an element (rectangle) which has {} at the end. A rectangle is not compatible with the sequence diagram notation, and the {} at the end is a syntax error.

The solution is either to use the MA_DOOR macro with a participant argument and remove the {} at the end, or to use the sprites (<$ma_door{scale=1}>) directly in an element name.

@startuml
' Style the entity (see https://github.com/plantuml/plantuml-stdlib/blob/master/material/door.puml)
hide <<MA DOOR>> stereotype
<style>
.MA DOOR {
    BackgroundColor LightGreen
}
</style>

actor Bob #red
!include <material/common>
!include <material/door>
' the following macro generates an entity of type participant and doesn't have {} at the end
' see https://github.com/plantuml/plantuml-stdlib/blob/master/material/door.puml for how the macro is defined
MA_DOOR(Purple, 1, setup_public_key, participant, "Public key")

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

Bob -> setup_public_key : open
Bob -> door : open
@enduml

enter image description here

2
On

The essence of the answer was given by @Fuhrmanator. For completeness, attached are the two plantuml sequence diagrams of initial setup and usage of SSH.

Initial SSH Setup

@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

enter image description here

SSH Usage

@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

enter image description here