Skip to content

Commit

Permalink
Merge pull request #4 from axonivy-market/feature/XIVY-12667_optimiza…
Browse files Browse the repository at this point in the history
…tion

Feature/xivy 12667 optimization
  • Loading branch information
ivy-fhe authored Oct 26, 2023
2 parents f71d874 + edad32d commit b9b9e04
Show file tree
Hide file tree
Showing 17 changed files with 468 additions and 40 deletions.
8 changes: 3 additions & 5 deletions threema-connector-product/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ Credentials and credits are required to send messages. The credentials can be cr
![Result screen](./images/resultScreen.png)

## Setup
This Connector requires an "End-to-End Threema ID". [Request new ID](https://gateway.threema.ch/en/id-request)
<br>
For generating the keys and requesting a new Threema.Gateway ID refer to [Generate keys](https://gateway.threema.ch/en/developer/howto/create-keys/php).

To use the Threema Connector, add the following variables to your Axon Ivy Project:
1. Generate a new key pair using the "createKeyPair" process.
2. Create "End-to-End Threema ID" at: [Request new ID](https://gateway.threema.ch/en/id-request) <br>
3. Add the following variables to your Axon Ivy Project:

```
@variables.yaml@
Expand Down
21 changes: 0 additions & 21 deletions threema-connector-product/product.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,6 @@
}
]
}
},
{
"id": "maven-dropins",
"data": {
"dependencies": [
{
"groupId": "com.axonivy.connector.threema",
"artifactId": "threema-connector",
"version": "${version}"
}
],
"repositories": [
{
"id": "maven.axonivy.com",
"url": "https://maven.axonivy.com",
"snapshots": {
"enabled": "true"
}
}
]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package threema.connector.test.util;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import util.KeyPairGenerator;
import util.KeyPairGenerator.KeyPair;

public class KeyPairGeneratorTest {

@Test
void generateKeyPair() {
KeyPair keys = KeyPairGenerator.generate();
assertThat(keys.publicKey()).isNotEmpty();
assertThat(keys.privateKey()).isNotEmpty();

assertThat(keys.publicKey().length()).isEqualTo(64);
assertThat(keys.privateKey().length()).isEqualTo(64);
}

}
2 changes: 1 addition & 1 deletion threema-connector/config/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Variables:
threemaConnector:

# Your Threema.Gateway ID
# [password]
threemaId: ''

# Your Threema.Gateway Secret
# [password]
secret: ''

# Your private key associated with your Threema.Gateway ID
# [password]
privateKey: ''
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
createKeyPairData #class
threema.connector #namespace
privateKey String #field
privateKey PERSISTENT #fieldModifier
publicKey String #field
publicKey PERSISTENT #fieldModifier
16 changes: 3 additions & 13 deletions threema-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,13 @@
<target>
<mkdir dir="${project.basedir}/lib"/>
<get src="https://gateway.threema.ch/sdk/threema-msgapi-sdk-java-2.0.1.zip"
dest="${project.basedir}/lib/threema-msgapi-tool.zip"/>
</target>
</configuration>
</execution>
<execution>
<id>extract-threema-msgapi-tool</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
dest="${project.basedir}/lib/threema-msgapi-tool.zip"/>
<unzip src="${project.basedir}/lib/threema-msgapi-tool.zip"
dest="${project.basedir}/lib"
overwrite="false">
<patternset includes="threema-msgapi-tool.jar"/>
</unzip>
</unzip>
<delete file="${project.basedir}/lib/threema-msgapi-tool.zip"/>
</target>
</configuration>
</execution>
Expand Down
67 changes: 67 additions & 0 deletions threema-connector/processes/createKeyPair.p.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"format" : "10.0.0",
"id" : "18B67537F65B8CEE",
"config" : {
"data" : "threema.connector.createKeyPairData"
},
"elements" : [ {
"id" : "f0",
"type" : "RequestStart",
"name" : "start.ivp",
"config" : {
"callSignature" : "start",
"outLink" : "start.ivp"
},
"visual" : {
"at" : { "x" : 96, "y" : 64 }
},
"connect" : { "id" : "f4", "to" : "f3" }
}, {
"id" : "f1",
"type" : "TaskEnd",
"visual" : {
"at" : { "x" : 696, "y" : 64 }
}
}, {
"id" : "f3",
"type" : "Script",
"name" : "generateKeyPair",
"config" : {
"output" : {
"code" : [
"import util.KeyPairGenerator;",
"import util.KeyPairGenerator.KeyPair;",
"",
"KeyPair keys = KeyPairGenerator.generate();",
"",
"out.publicKey = keys.publicKey();",
"out.privateKey = keys.privateKey();"
]
}
},
"visual" : {
"at" : { "x" : 320, "y" : 64 }
},
"connect" : { "id" : "f6", "to" : "f5" }
}, {
"id" : "f5",
"type" : "DialogCall",
"name" : "KeyPair",
"config" : {
"dialogId" : "threema.connector.KeyPair",
"startMethod" : "start(threema.connector.createKeyPairData)",
"call" : {
"params" : [
{ "name" : "createKeyPairData", "type" : "threema.connector.createKeyPairData" }
],
"map" : {
"param.createKeyPairData" : "in"
}
}
},
"visual" : {
"at" : { "x" : 508, "y" : 64 }
},
"connect" : { "id" : "f2", "to" : "f1" }
} ]
}
19 changes: 19 additions & 0 deletions threema-connector/src/util/KeyPairGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package util;

import javax.xml.bind.DatatypeConverter;

import ch.threema.apitool.CryptTool;

public class KeyPairGenerator {

public record KeyPair(String publicKey, String privateKey) {}

public static KeyPair generate() {
byte[] publicKey = new byte[32];
byte[] privateKey = new byte[32];

CryptTool.generateKeyPair(publicKey, privateKey);
return new KeyPair(DatatypeConverter.printHexBinary(publicKey), DatatypeConverter.printHexBinary(privateKey));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<richDialogDescriptor>
<property>
<name>viewTechnology</name>
<value>JSF</value>
</property>
</richDialogDescriptor>
35 changes: 35 additions & 0 deletions threema-connector/src_hd/threema/connector/KeyPair/KeyPair.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:ic="http://ivyteam.ch/jsf/component" xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">
<h:body>
<ui:composition template="/layouts/frame-10.xhtml">
<ui:define name="title">KeyPair</ui:define>
<ui:define name="content">

<h3>Newly generated Keypair</h3>

<h:form id="form">

<p:panelGrid columns="2" layout="grid" styleClass="ui-panelgrid-blank ui-fluid"
columnClasses="ui-g-12 ui-md-3 ui-lg-2, ui-g-12 ui-md-9 ui-lg-4, ui-g-12 ui-md-3 ui-lg-2, ui-g-12 ui-md-9 ui-lg-4">

<p:outputLabel for="createKeyPairDataPrivateKey" value="Private Key" />
<p:outputLabel id="createKeyPairDataPrivateKey" value="#{data.createKeyPairData.privateKey}"></p:outputLabel>

<p:outputLabel for="createKeyPairDataPublicKey" value="Public Key" />
<p:outputLabel id="createKeyPairDataPublicKey" value="#{data.createKeyPairData.publicKey}"></p:outputLabel>

</p:panelGrid>
<br />
<div class="command-btns">
<p:commandLink id="cancel" actionListener="#{ivyWorkflowView.cancel()}" value="Cancel" />
<p:commandButton id="proceed" actionListener="#{logic.close}" value="Proceed" update="form" icon="pi pi-check" />
</div>
</h:form>

</ui:define>
</ui:composition>
</h:body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
KeyPairData #class
threema.connector.KeyPair #namespace
createKeyPairData threema.connector.createKeyPairData #field
createKeyPairData PERSISTENT #fieldModifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"format" : "10.0.0",
"id" : "18B675A6BCE832D1",
"kind" : "HTML_DIALOG",
"config" : {
"data" : "threema.connector.KeyPair.KeyPairData"
},
"elements" : [ {
"id" : "f0",
"type" : "HtmlDialogStart",
"name" : "start(createKeyPairData)",
"config" : {
"callSignature" : "start",
"input" : {
"params" : [
{ "name" : "createKeyPairData", "type" : "threema.connector.createKeyPairData" }
],
"map" : {
"out.createKeyPairData" : "param.createKeyPairData"
}
},
"guid" : "18B675A6BCFECF51"
},
"visual" : {
"at" : { "x" : 96, "y" : 64 }
},
"connect" : { "id" : "f2", "to" : "f1" }
}, {
"id" : "f1",
"type" : "HtmlDialogEnd",
"visual" : {
"at" : { "x" : 224, "y" : 64 }
}
}, {
"id" : "f3",
"type" : "HtmlDialogEventStart",
"name" : "close",
"config" : {
"guid" : "18B675A6BD2AE7CB"
},
"visual" : {
"at" : { "x" : 96, "y" : 160 }
},
"connect" : { "id" : "f5", "to" : "f4" }
}, {
"id" : "f4",
"type" : "HtmlDialogExit",
"visual" : {
"at" : { "x" : 224, "y" : 160 }
}
} ]
}
60 changes: 60 additions & 0 deletions threema-connector/webContent/layouts/frame-10.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:ic="http://ivyteam.ch/jsf/component"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions">

<!--
DESCRIPTION:
This is the default template to use the freya-ivy theme as well as iFrames approach.
PORTAL:
If you are using the Axon Ivy Portal, you can pass several parameters to it to use some features (e.g. process chain).
You'll find the list of parameters here: https://developer.axonivy.com/portal/10.0/doc/portal-developer-guide/components/layout-templates.html#components-layout-templates-iframe-task-template
For further information about iframes and usage in Portal please refer to: https://developer.axonivy.com/portal/10.0/doc/portal-developer-guide/iframe/index.html
BRANDING:
If you want to brand your dialogs, please take a look at our documentation: https://developer.axonivy.com/doc/10.0/designer-guide/user-interface/branding/index.html
STYLING:
If you want to add custom styles, you can simply add your own .css file (e.g. at the location: "webContent/layouts/styles/style.css")
and refence it below in the head part.
-->

<h:head>
<f:attribute name="primefaces.THEME" value="#{ivyFreyaTheme.theme}" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><ui:insert name="title">Ivy Html Dialog</ui:insert></title>
<link rel="shortcut icon" href="#{resource['ivy-branding:favicon']}" />
<h:outputScript name="js/layout.js" library="#{ivyFreyaTheme.library}" />
<h:outputStylesheet name="#{ivyFreyaTheme.layout}" library="#{ivyFreyaTheme.library}" />
<h:outputStylesheet name="primeflex-2.min.css" library="primeflex" />
<h:outputStylesheet name="custom.css" library="ivy-branding" />
<!-- Optional Style or Script files:
<h:outputStylesheet name="layouts/styles/style.css" />
-->
</h:head>
<h:body class="body-hd">
<ui:include src="/layouts/includes/progress-loader.xhtml" />
<div id="content" class="container frame">
<ui:insert name="content">
default content
</ui:insert>
</div>

<ui:insert name="exception">
<ui:include src="/layouts/includes/exception.xhtml" />
</ui:insert>

<!-- optional Portal parameters:
<script>
window.
</script>
-->

</h:body>
</html>
Loading

0 comments on commit b9b9e04

Please sign in to comment.