├── .github ├── CODEOWNERS └── workflows │ ├── netlicensing-dependency-review.yml │ └── netlicensing-client-release.yml ├── NetLicensingClient ├── .gitignore └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── labs64 │ │ │ └── netlicensing │ │ │ ├── schema │ │ │ └── converter │ │ │ │ ├── package-info.java │ │ │ │ ├── Converter.java │ │ │ │ ├── ItemToPaymentMethodConverter.java │ │ │ │ ├── ItemToLicenseeConverter.java │ │ │ │ ├── ItemToLicenseTypePropertiesConverter.java │ │ │ │ ├── ItemToLicensingModelPropertiesConverter.java │ │ │ │ ├── ItemToProductModuleConverter.java │ │ │ │ ├── ItemToTokenConverter.java │ │ │ │ ├── ItemToCountryConverter.java │ │ │ │ ├── ItemToBundleConverter.java │ │ │ │ ├── ItemToEntityBaseConverter.java │ │ │ │ └── ItemToNotificationConverter.java │ │ │ ├── domain │ │ │ ├── vo │ │ │ │ ├── ITokenType.java │ │ │ │ ├── Event.java │ │ │ │ ├── NotificationProtocol.java │ │ │ │ ├── TransactionStatus.java │ │ │ │ ├── WarningLevel.java │ │ │ │ ├── MetaInfo.java │ │ │ │ ├── DiscountType.java │ │ │ │ ├── LicenseTypeProperties.java │ │ │ │ ├── SecurityMode.java │ │ │ │ ├── LicenseeSecretMode.java │ │ │ │ ├── TokenType.java │ │ │ │ ├── LicensingModelProperties.java │ │ │ │ ├── PaymentMethodEnum.java │ │ │ │ ├── TransactionSource.java │ │ │ │ ├── VatMode.java │ │ │ │ ├── Page.java │ │ │ │ ├── Composition.java │ │ │ │ ├── Currency.java │ │ │ │ ├── Money.java │ │ │ │ ├── LicenseType.java │ │ │ │ └── Context.java │ │ │ └── entity │ │ │ │ ├── package-info.java │ │ │ │ ├── LicenseTransactionJoin.java │ │ │ │ ├── ProductDiscount.java │ │ │ │ ├── Notification.java │ │ │ │ ├── Bundle.java │ │ │ │ ├── PaymentMethod.java │ │ │ │ ├── BaseEntity.java │ │ │ │ ├── Token.java │ │ │ │ ├── impl │ │ │ │ ├── PaymentMethodImpl.java │ │ │ │ ├── LicenseTransactionJoinImpl.java │ │ │ │ ├── LicenseeImpl.java │ │ │ │ └── TokenImpl.java │ │ │ │ ├── Country.java │ │ │ │ ├── Licensee.java │ │ │ │ ├── ProductModule.java │ │ │ │ ├── Transaction.java │ │ │ │ ├── Product.java │ │ │ │ └── License.java │ │ │ ├── provider │ │ │ ├── HttpMethod.java │ │ │ ├── Form.java │ │ │ ├── auth │ │ │ │ ├── Authentication.java │ │ │ │ ├── TokenAuthentication.java │ │ │ │ └── UsernamePasswordAuthentication.java │ │ │ ├── AbstractRestProvider.java │ │ │ ├── RestResponse.java │ │ │ └── RestProvider.java │ │ │ ├── util │ │ │ ├── Visitable.java │ │ │ ├── PackageUtils.java │ │ │ ├── Visitor.java │ │ │ ├── DateUtils.java │ │ │ ├── ConvertUtils.java │ │ │ ├── XMLDSigValidatorCustom.java │ │ │ ├── JAXBUtils.java │ │ │ └── CheckUtils.java │ │ │ ├── service │ │ │ └── package-info.java │ │ │ └── exception │ │ │ ├── BadSignatureException.java │ │ │ ├── MalformedArgumentsException.java │ │ │ ├── WrongResponseFormatException.java │ │ │ ├── ExceptionUtils.java │ │ │ ├── RestException.java │ │ │ ├── ConversionException.java │ │ │ └── ServiceException.java │ └── resources │ │ ├── schema │ │ └── xmldsig.cat │ │ └── nlic-schema-bindings.xjb │ └── test │ ├── resources │ ├── xmldsig │ │ ├── xml-signed-inline-01.xml │ │ ├── rsa_public.pem │ │ ├── rsa_public_wrong.pem │ │ ├── xml-not-signed.xml │ │ ├── xml-signed-nlic-01.xml │ │ ├── xml-signed-nlic-02-mismatch.xml │ │ └── rsa_private.pem │ └── mock │ │ ├── netlicensing-licenseTypes-list.xml │ │ ├── netlicensing-paymentmethod-get.xml │ │ ├── netlicensing-licensee-transfer.xml │ │ ├── netlicensing-paymentmethod-update.xml │ │ ├── netlicensing-product-update.xml │ │ ├── netlicensing-licensee-get.xml │ │ ├── netlicensing-licensingModels-list.xml │ │ ├── netlicensing-product-get.xml │ │ ├── netlicensing-licensee-update.xml │ │ ├── netlicensing-productmodule-get.xml │ │ ├── netlicensing-paymentmethod-list.xml │ │ ├── netlicensing-bundle-get.xml │ │ ├── netlicensing-bundle-update.xml │ │ ├── netlicensing-productmodule-update.xml │ │ ├── netlicensing-notification-update.xml │ │ ├── netlicensing-token-get.xml │ │ ├── netlicensing-notification-get.xml │ │ ├── netlicensing-license-get.xml │ │ ├── netlicensing-licensee-validate.xml │ │ ├── netlicensing-licensetemplate-get.xml │ │ ├── netlicensing-licensetemplate-update.xml │ │ ├── netlicensing-countries-list.xml │ │ ├── netlicensing-license-update.xml │ │ ├── netlicensing-transaction-get.xml │ │ ├── netlicensing-licensee-validate-offline.xml │ │ ├── netlicensing-transaction-update.xml │ │ ├── netlicensing-licensee-list.xml │ │ ├── netlicensing-product-list.xml │ │ ├── netlicensing-productmodule-list.xml │ │ ├── netlicensing-token-list.xml │ │ ├── netlicensing-bundle-list.xml │ │ ├── netlicensing-notification-list.xml │ │ ├── netlicensing-license-list.xml │ │ ├── netlicensing-bundle-obtain.xml │ │ ├── netlicensing-transaction-list.xml │ │ └── netlicensing-licensetemplate-list.xml │ └── java │ └── com │ └── labs64 │ └── netlicensing │ └── service │ └── NetLicensingServiceTest.java ├── NetLicensingClient-demo ├── .gitignore └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── labs64 │ │ │ └── netlicensing │ │ │ ├── utils │ │ │ ├── package-info.java │ │ │ ├── TestHelpers.java │ │ │ └── ConsoleWriter.java │ │ │ ├── examples │ │ │ ├── NetLicensingExample.java │ │ │ ├── package-info.java │ │ │ └── OfflineValidation.java │ │ │ └── demo │ │ │ ├── AllExamples.java │ │ │ └── NetLicensingClientDemo.java │ └── resources │ │ ├── generate-keys.sh │ │ ├── log4j2.xml │ │ ├── rsa_public.pem │ │ ├── rsa_public_wrong.pem │ │ ├── Isb-DEMO.xml │ │ └── rsa_private.pem │ └── test │ └── java │ └── com │ └── labs64 │ └── netlicensing │ └── examples │ └── RunExamples.java ├── .gitignore └── README.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @Labs64/labs64-dev 2 | -------------------------------------------------------------------------------- /NetLicensingClient/.gitignore: -------------------------------------------------------------------------------- 1 | /.pmd 2 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/.gitignore: -------------------------------------------------------------------------------- 1 | /.pmd 2 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utilities used in NetLicensing examples 3 | */ 4 | package com.labs64.netlicensing.utils; -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Schema converters. 3 | */ 4 | package com.labs64.netlicensing.schema.converter; 5 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/ITokenType.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | public interface ITokenType { 4 | 5 | String name(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/HttpMethod.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.provider; 2 | 3 | public enum HttpMethod { 4 | 5 | GET, POST, DELETE; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/xmldsig/xml-signed-inline-01.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Labs64/NetLicensingClient-java/HEAD/NetLicensingClient/src/test/resources/xmldsig/xml-signed-inline-01.xml -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/examples/NetLicensingExample.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.examples; 2 | 3 | public interface NetLicensingExample { 4 | 5 | void execute(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/examples/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes in this package contain NetLicensing API examples for various use cases. 3 | */ 4 | package com.labs64.netlicensing.examples; 5 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/resources/schema/xmldsig.cat: -------------------------------------------------------------------------------- 1 | SYSTEM "http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd" "xmldsig-core-schema.xsd" 2 | SYSTEM "http://www.w3.org/2001/XMLSchema.dtd" "XMLSchema.dtd" 3 | SYSTEM "http://www.w3.org/2001/datatypes.dtd" "datatypes.dtd" 4 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/Visitable.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.util; 2 | 3 | public class Visitable { 4 | 5 | public void accept(final Visitor visitor) throws Exception { 6 | visitor.visit(this); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/resources/generate-keys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo Generate private key... 4 | openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048 5 | 6 | echo Generate public key... 7 | openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem 8 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/service/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Service interfaces. 3 | * 4 | * Each object in NetLicensing object model has its service interface that declares 5 | * operations available for this object or related to it. Refer to the 6 | * particular object service interface for details. 7 | */ 8 | package com.labs64.netlicensing.service; 9 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes in this package represent various NetLicensing objects. 3 | * 4 | * These entities: 5 | * - passed as parameters or returned from the NetLicensing API calls; 6 | * - persisted in a database; 7 | * - declare properties available for each NetLicensing object type. 8 | */ 9 | package com.labs64.netlicensing.domain.entity; 10 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/LicenseTransactionJoin.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | public interface LicenseTransactionJoin extends Serializable { 6 | 7 | void setTransaction(final Transaction transaction); 8 | 9 | Transaction getTransaction(); 10 | 11 | void setLicense(final License license); 12 | 13 | License getLicense(); 14 | } 15 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/test/java/com/labs64/netlicensing/examples/RunExamples.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.examples; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | public class RunExamples { 6 | 7 | @Test 8 | public void testCallEveryAPIMethod() { 9 | new CallEveryAPIMethod().execute(); 10 | } 11 | 12 | @Test 13 | public void testOfflineValidation() { 14 | new OfflineValidation().execute(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/PackageUtils.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.util; 2 | 3 | public class PackageUtils { 4 | 5 | private PackageUtils() { 6 | throw new IllegalStateException("PackageUtils class"); 7 | } 8 | 9 | public static String getImplementationVersion() { 10 | //get implementation version 11 | return PackageUtils.class.getPackage().getImplementationVersion(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Event.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | import java.util.Arrays; 4 | 5 | public enum Event { 6 | LICENSEE_CREATED, 7 | LICENSE_CREATED, 8 | WARNING_LEVEL_CHANGED; 9 | 10 | public static Event parseString(final String value) { 11 | return Arrays.stream(Event.values()).filter((e) -> e.name().equalsIgnoreCase(value)).findFirst().orElse(null); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/NotificationProtocol.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | import java.util.Arrays; 4 | 5 | public enum NotificationProtocol { 6 | WEBHOOK; 7 | 8 | public static NotificationProtocol parseString(final String value) { 9 | return Arrays.stream(NotificationProtocol.values()).filter((t) -> t.name().equalsIgnoreCase(value)) 10 | .findFirst().orElse(null); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/TransactionStatus.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | /** 4 | * The transaction status enumeration. 5 | */ 6 | public enum TransactionStatus { 7 | 8 | /** 9 | * Transaction still running. 10 | */ 11 | PENDING, 12 | 13 | /** 14 | * Transaction is closed. 15 | */ 16 | CLOSED, 17 | 18 | /** 19 | * Transaction is cancelled. 20 | */ 21 | CANCELLED 22 | 23 | } 24 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/resources/rsa_public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu5grobcnjPhzOvyG05DO 3 | OW6SlUIKa7omhJLIXl8D8fohuHUaZLoGA2Fot4OP/qFSg0DK4egbCbU+pDrasMvK 4 | vNTCMzw0ypzbyBEaYSm6wtEeU45ppawj0HjOh3NRp2Ds0hR8xSMKFRc/4d87hskj 5 | yjKXOqoOZhqjXwYk7ocIe6ADPpF4YCs5eY4/3CL1JnItdlKQRsl8ZJ0Yqe+figf9 6 | agCWvQ0O0faRdmgmr7eUhU9aXNvSJaVJXbg6TjhhxVujzehF8sh/7sxgGwqbyunE 7 | 15OWo6dArRCyNUeROu+9Jp4tET+2RA/PuqQbWW6EbJWBhpkqNdzi9CYuhuUjvk8m 8 | dwIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/xmldsig/rsa_public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu5grobcnjPhzOvyG05DO 3 | OW6SlUIKa7omhJLIXl8D8fohuHUaZLoGA2Fot4OP/qFSg0DK4egbCbU+pDrasMvK 4 | vNTCMzw0ypzbyBEaYSm6wtEeU45ppawj0HjOh3NRp2Ds0hR8xSMKFRc/4d87hskj 5 | yjKXOqoOZhqjXwYk7ocIe6ADPpF4YCs5eY4/3CL1JnItdlKQRsl8ZJ0Yqe+figf9 6 | agCWvQ0O0faRdmgmr7eUhU9aXNvSJaVJXbg6TjhhxVujzehF8sh/7sxgGwqbyunE 7 | 15OWo6dArRCyNUeROu+9Jp4tET+2RA/PuqQbWW6EbJWBhpkqNdzi9CYuhuUjvk8m 8 | dwIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/resources/rsa_public_wrong.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtq96itv1m00/czFD7IzE 3 | mLiXPpvok1vjqB9VU6kTkq6QFGAfJF1G+m1fbK5NvpiDCsfuofdCFuhVnvLnzrpd 4 | xUlse8erWEr9p9RAyh25NMK9/v0MAEAYV7zRa+ZOh31G54DwR7zk0TxyVzxKpjPi 5 | wQSnv7UCY/IR7remLIYO92K7jAg9ZB4IHTuVulCtSrSQajZ8Ep2rFGPr8OeTsj9c 6 | rBPpmL/ShdJOnL4NR0UnVWSpsCFW6wEqNafcUWnWpb98V49/p7fWDFJ1Tg6+OlVg 7 | lgsNrqrqwJpxDLKnGAkkxHaVxSnZzAYh+HP8CbJmbzzE1GRXNgy3w+smWMv6M996 8 | 9wIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/xmldsig/rsa_public_wrong.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtq96itv1m00/czFD7IzE 3 | mLiXPpvok1vjqB9VU6kTkq6QFGAfJF1G+m1fbK5NvpiDCsfuofdCFuhVnvLnzrpd 4 | xUlse8erWEr9p9RAyh25NMK9/v0MAEAYV7zRa+ZOh31G54DwR7zk0TxyVzxKpjPi 5 | wQSnv7UCY/IR7remLIYO92K7jAg9ZB4IHTuVulCtSrSQajZ8Ep2rFGPr8OeTsj9c 6 | rBPpmL/ShdJOnL4NR0UnVWSpsCFW6wEqNafcUWnWpb98V49/p7fWDFJ1Tg6+OlVg 7 | lgsNrqrqwJpxDLKnGAkkxHaVxSnZzAYh+HP8CbJmbzzE1GRXNgy3w+smWMv6M996 8 | 9wIDAQAB 9 | -----END PUBLIC KEY----- 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | 4 | # Mobile Tools for Java (J2ME) 5 | .mtj.tmp/ 6 | 7 | # Package Files # 8 | *.jar 9 | *.war 10 | *.ear 11 | 12 | # virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.html 13 | hs_err_pid* 14 | 15 | target 16 | .idea 17 | *.iml 18 | 19 | # Eclipse # 20 | .classpath 21 | .project 22 | bin/** 23 | .settings/ 24 | 25 | # External tool builders 26 | .externalToolBuilders/ 27 | 28 | # VSCode 29 | .vscode 30 | 31 | # Locally stored "Eclipse launch configurations" 32 | *.launch 33 | /.pmd 34 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/Form.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.provider; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Form { 7 | 8 | private Map params; 9 | 10 | public Form() { 11 | params = new HashMap<>(); 12 | } 13 | 14 | public void param(String key, String value) { 15 | params.put(key, value); 16 | } 17 | 18 | public Map getParams() { 19 | return params; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/WarningLevel.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | public enum WarningLevel { 4 | GREEN, 5 | YELLOW, 6 | RED; 7 | 8 | public static WarningLevel parseString(final String warningLevelStr) { 9 | if (warningLevelStr != null) { 10 | for (final WarningLevel warningLevel : WarningLevel.values()) { 11 | if (warningLevelStr.equals(warningLevel.name())) { 12 | return warningLevel; 13 | } 14 | } 15 | } 16 | return null; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/utils/TestHelpers.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.utils; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.nio.charset.StandardCharsets; 6 | 7 | import org.apache.commons.io.IOUtils; 8 | 9 | public class TestHelpers { 10 | 11 | public static String loadFileContent(final String fileName) throws IOException { 12 | final ClassLoader classloader = Thread.currentThread().getContextClassLoader(); 13 | final InputStream inputStream = classloader.getResourceAsStream(fileName); 14 | return IOUtils.toString(inputStream, StandardCharsets.UTF_8); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licenseTypes-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | FEATURE 8 | 9 | 10 | TIMEVOLUME 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-paymentmethod-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | PAYPAL 8 | true 9 | sample_paypal_subject 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensee-transfer.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | L001-TEST 8 | true 9 | P001-TEST 10 | true 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/ProductDiscount.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public interface ProductDiscount extends Comparable { 6 | 7 | void setProduct(final Product product); 8 | 9 | Product getProduct(); 10 | 11 | void setTotalPrice(final BigDecimal totalPrice); 12 | 13 | BigDecimal getTotalPrice(); 14 | 15 | void setCurrency(final String currency); 16 | 17 | String getCurrency(); 18 | 19 | void setAmountFix(final BigDecimal amountFix); 20 | 21 | BigDecimal getAmountFix(); 22 | 23 | void setAmountPercent(final BigDecimal amountPercent); 24 | 25 | BigDecimal getAmountPercent(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Notification.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.entity; 2 | 3 | import java.util.Set; 4 | 5 | import com.labs64.netlicensing.domain.vo.Event; 6 | import com.labs64.netlicensing.domain.vo.NotificationProtocol; 7 | 8 | public interface Notification extends BaseEntity { 9 | String getName(); 10 | 11 | void setName(String name); 12 | 13 | Set getEvents(); 14 | 15 | void setEvents(Set events); 16 | 17 | void addEvent(final Event event); 18 | 19 | NotificationProtocol getProtocol(); 20 | 21 | void setProtocol(NotificationProtocol notificationProtocol); 22 | 23 | String getPayload(); 24 | 25 | void setPayload(String payload); 26 | } 27 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-paymentmethod-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | PAYPAL 8 | true 9 | sample_paypal_subject 10 | 100 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-product-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | P001 8 | Product Numero Uno 9 | false 10 | v1.0 11 | true 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensee-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | L001-TEST 8 | true 9 | P001-TEST 10 | Custom property value 11 | true 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/demo/AllExamples.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.demo; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.labs64.netlicensing.examples.CallEveryAPIMethod; 7 | import com.labs64.netlicensing.examples.NetLicensingExample; 8 | import com.labs64.netlicensing.examples.OfflineValidation; 9 | 10 | public class AllExamples { 11 | 12 | public static Map> list = new HashMap<>(); 13 | 14 | private static void addExample(final Class exampleClass) { 15 | list.put(exampleClass.getSimpleName(), exampleClass); 16 | } 17 | 18 | static 19 | { 20 | addExample(CallEveryAPIMethod.class); 21 | addExample(OfflineValidation.class); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensingModels-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | TimeLimitedEvaluation 8 | 9 | 10 | TimeVolume 11 | 12 | 13 | FeatureWithTimeVolume 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/MetaInfo.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | public class MetaInfo extends GenericContext { 16 | 17 | public MetaInfo() { 18 | super(String.class); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/DiscountType.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | public enum DiscountType { 4 | FIX, 5 | 6 | PERCENT; 7 | 8 | public static DiscountType parseValue(final String discountType) { 9 | if (discountType != null) { 10 | for (final DiscountType type : DiscountType.values()) { 11 | if (discountType.equalsIgnoreCase(type.name())) { 12 | return type; 13 | } 14 | } 15 | } 16 | throw new IllegalArgumentException(discountType); 17 | } 18 | 19 | public static DiscountType parseValueSafe(final String discountType) { 20 | try { 21 | return parseValue(discountType); 22 | } catch (final IllegalArgumentException e) { 23 | return null; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-product-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | P014-TEST 8 | true 9 | Product Numero Uno 10 | v1.0 11 | Licensed to Licensee 12 | CustomPropertyValue 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensee-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | L001-TEST 8 | false 9 | P001-TEST 10 | Custom property value 11 | To be or not to be 12 | true 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-productmodule-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | PM001-TEST 8 | true 9 | Test Product Module 10 | P001-TEST 11 | TimeLimitedEvaluation 12 | false 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-paymentmethod-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | PAYPAL_SANDBOX 9 | false 10 | 11 | 12 | PAYPAL 13 | true 14 | sample_paypal_subject 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/auth/Authentication.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.provider.auth; 14 | 15 | /** 16 | * Generic interface for creating authentication headers. 17 | */ 18 | public interface Authentication { 19 | 20 | String getUsername(); 21 | 22 | String getPassword(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-bundle-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | B001-TEST 8 | true 9 | Bundle 1 10 | Description 1 11 | 10 12 | EUR 13 | LT001-TEST,LT002-TEST 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Bundle.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.entity; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | import com.labs64.netlicensing.domain.vo.Currency; 7 | 8 | public interface Bundle extends BaseEntity { 9 | void setName(String name); 10 | 11 | String getName(); 12 | 13 | void setPrice(BigDecimal price); 14 | 15 | BigDecimal getPrice(); 16 | 17 | void setCurrency(Currency currency); 18 | 19 | Currency getCurrency(); 20 | 21 | void setDescription(String description); 22 | 23 | String getDescription(); 24 | 25 | void setLicenseTemplateNumbers(List licenseTemplateNumbers); 26 | 27 | List getLicenseTemplateNumbers(); 28 | 29 | void addLicenseTemplateNumber(String licenseTemplateNumber); 30 | 31 | void removeLicenseTemplateNumber(String licenseTemplateNumber); 32 | } 33 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-bundle-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | B002-TEST 8 | true 9 | Bundle 2 10 | Description 2 11 | 20.00 12 | USD 13 | LT003-TEST,LT004-TEST 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/LicenseTypeProperties.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | /** 16 | * Interface for a license type. 17 | */ 18 | public interface LicenseTypeProperties { 19 | 20 | /** 21 | * Gets the license type name. 22 | * 23 | * @return the license type name 24 | */ 25 | String getName(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-productmodule-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | PM001-TEST 8 | true 9 | Test Product Module 10 | P001-TEST 11 | Rental 12 | false 13 | 10 14 | 3 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-notification-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | N002-TEST 8 | false 9 | Notification 2 10 | LICENSEE_CREATED 11 | WEBHOOK 12 | http://www.test.test 13 | ${event} 14 | Test Value 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/xmldsig/xml-not-signed.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | Value 23 | Value2 24 | 25 | 26 | Value 27 | Value2 28 | 29 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/SecurityMode.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | /** 16 | * Enumerates possible security modes for accessing the NetLicensing API. 17 | *

18 | * See {@link https://netlicensing.io/wiki/restful-api} for details. 19 | *

20 | */ 21 | public enum SecurityMode { 22 | 23 | BASIC_AUTHENTICATION, APIKEY_IDENTIFICATION, ANONYMOUS_IDENTIFICATION 24 | 25 | } 26 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-token-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | afeb41d9-314e-49be-8465-148c614badfa 8 | true 9 | 2014-07-23T15:19:56.147Z 10 | SHOP 11 | https://go.netlicensing.io/shop/v2/?shoptoken=afeb41d9-314e-49be-8465-148c614badfa 12 | L001-TEST 13 | VDEMO 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/PaymentMethod.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.util.Map; 16 | 17 | /** 18 | * PaymentMethod entity used internally by NetLicensing. 19 | */ 20 | public interface PaymentMethod extends BaseEntity { 21 | 22 | // Methods for working with custom properties 23 | 24 | @Deprecated 25 | Map getPaymentMethodProperties(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-notification-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | N014-TEST 8 | true 9 | Notification 14 10 | LICENSEE_CREATED,LICENSE_CREATED,WARNING_LEVEL_CHANGED 11 | WEBHOOK 12 | http://www.test.test 13 | ${event} 14 | CustomPropertyValue 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-license-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | LC001-TEST 8 | true 9 | Concrete Test License 10 | 15.00 11 | EUR 12 | false 13 | L001-TEST 14 | LT001-TEST 15 | Custom property value 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/resources/nlic-schema-bindings.xjb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/LicenseeSecretMode.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | public enum LicenseeSecretMode { 4 | 5 | /** 6 | * @deprecated 7 | */ 8 | @Deprecated DISABLED("DISABLED"), 9 | 10 | PREDEFINED("PREDEFINED"), 11 | 12 | CLIENT("CLIENT"); 13 | 14 | private final String value; 15 | 16 | /** 17 | * Instantiates a new Licensee Secret Mode. 18 | * 19 | * @param licenseeSecretModeValue 20 | * LicenseeSecretMode value 21 | */ 22 | LicenseeSecretMode(final String licenseeSecretModeValue) { 23 | value = licenseeSecretModeValue; 24 | } 25 | 26 | public static LicenseeSecretMode parseString(final String value) { 27 | for (final LicenseeSecretMode licenseeSecretMode : LicenseeSecretMode.values()) { 28 | if (licenseeSecretMode.name().equalsIgnoreCase(value)) { 29 | return licenseeSecretMode; 30 | } 31 | } 32 | return LicenseeSecretMode.PREDEFINED; 33 | } 34 | 35 | /* 36 | * (non-Javadoc) 37 | * 38 | * @see java.lang.Enum#toString() 39 | */ 40 | @Override 41 | public String toString() { 42 | return value; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensee-validate.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | M001-TEST 8 | FeatureWithTimeVolume 9 | Test module 10 | 11 | true 12 | 2014-08-06T21:30:45.574Z 13 | GREEN 14 | 15 | 16 | true 17 | 2014-08-06T21:30:45.186Z 18 | GREEN 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/TokenType.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | /** 16 | * This enum defines available token types. 17 | */ 18 | public enum TokenType implements ITokenType { 19 | 20 | DEFAULT, 21 | 22 | APIKEY, 23 | 24 | SHOP; 25 | 26 | public static ITokenType parseString(final String token) { 27 | if (token != null) { 28 | for (final TokenType tokenType : TokenType.values()) { 29 | if (token.equalsIgnoreCase(tokenType.name())) { 30 | return tokenType; 31 | } 32 | } 33 | } 34 | return null; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/BadSignatureException.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.exception; 14 | 15 | /** 16 | * The exception is thrown when signature validation of NetLicensing signed response fails. 17 | */ 18 | public class BadSignatureException extends NetLicensingException { 19 | 20 | private static final long serialVersionUID = -506669705393514519L; 21 | 22 | /** 23 | * Construct a ConversionException with the specified detail message. 24 | * 25 | * @param msg 26 | * the detail message 27 | */ 28 | public BadSignatureException(final String msg) { 29 | super(msg); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/auth/TokenAuthentication.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.provider.auth; 14 | 15 | /** 16 | */ 17 | public class TokenAuthentication implements Authentication { 18 | 19 | private final String token; 20 | 21 | /** 22 | * Token auth constructor. 23 | * 24 | * @param token 25 | * authentication token 26 | */ 27 | public TokenAuthentication(final String token) { 28 | this.token = token; 29 | } 30 | 31 | @Override 32 | public String getUsername() { 33 | return "apiKey"; 34 | } 35 | 36 | @Override 37 | public String getPassword() { 38 | return token; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/MalformedArgumentsException.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.exception; 14 | 15 | /** 16 | * Thrown when illegal arguments are passed to the NetLicensing client call. 17 | */ 18 | public class MalformedArgumentsException extends NetLicensingException { 19 | 20 | private static final long serialVersionUID = -2548284543777416222L; 21 | 22 | /** 23 | * Construct a ConversionException with the specified detail message. 24 | * 25 | * @param msg 26 | * the detail message 27 | */ 28 | public MalformedArgumentsException(final String msg) { 29 | super(msg); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensetemplate-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | LT001-TEST 8 | true 9 | Test License 10 | FEATURE 11 | 10.00 12 | EUR 13 | true 14 | true 15 | true 16 | PM001-TEST 17 | Test Product Module 18 | false 19 | 30 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/LicensingModelProperties.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | /** 16 | * Licensing models must implement this interface. 17 | *

18 | * On events that require licensing model specific actions, corresponding event handlers are called. Event handlers that 19 | * do not return any values expected to validate the passed arguments, possibly modifying them. Must throw exceptions in 20 | * case validation is not passed. 21 | */ 22 | public interface LicensingModelProperties { 23 | 24 | /** 25 | * Gets the licensing model name. 26 | * 27 | * @return the licensing model name 28 | */ 29 | String getName(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensetemplate-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | LT001-TEST 8 | true 9 | Test License Template 10 | TIMEVOLUME 11 | 10.00 12 | EUR 13 | false 14 | false 15 | false 16 | PM001-TEST 17 | Test Product Module 18 | false 19 | 30 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-countries-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | AF 8 | AFGHANISTAN 9 | 10 | false 11 | 12 | 13 | DE 14 | GERMANY 15 | 19 16 | true 17 | 18 | 19 | AT 20 | AUSTRIA 21 | 20 22 | true 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-license-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | LC001-TEST 8 | true 9 | Concrete Test License 10 | 15.00 11 | EUR 12 | false 13 | L001-TEST 14 | LT001-TEST 15 | Custom property value 16 | 30 17 | LQ2SFX4Z4 18 | 2014-07-22T12:18:41.965Z 19 | A value 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-transaction-get.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | TR001TEST 8 | true 9 | CLOSED 10 | SHOP 11 | 21.00 12 | 9.00 13 | EUR 14 | 1 15 | 19 16 | GROSS 17 | 2014-07-07T21:30:46.658Z 18 | 2014-07-07T21:30:46.658Z 19 | true 20 | VTEST 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/WrongResponseFormatException.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.exception; 14 | 15 | /** 16 | * The exception class that should be used when the content of the response of NetLicensing service doesn't meet 17 | * expectations that we impose on it. 18 | */ 19 | public class WrongResponseFormatException extends NetLicensingException { 20 | 21 | private static final long serialVersionUID = -2548284543777416222L; 22 | 23 | /** 24 | * Construct a ConversionException with the specified detail message. 25 | * 26 | * @param msg 27 | * the detail message 28 | */ 29 | public WrongResponseFormatException(final String msg) { 30 | super(msg); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensee-validate-offline.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | L001-TEST 8 | 9 | 10 | M001-TEST 11 | FeatureWithTimeVolume 12 | Test module 13 | 14 | true 15 | 2014-08-06T21:30:45.574Z 16 | GREEN 17 | 18 | 19 | true 20 | 2014-08-06T21:30:45.186Z 21 | GREEN 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/Visitor.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.util; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | // Inspired by: https://www.javaworld.com/article/2077602/learn-java/java-tip-98--reflect-on-the-visitor-design-pattern.html 6 | public class Visitor { 7 | 8 | public void visit(final Object object) throws Exception { 9 | final Method method = getMethod(object.getClass()); 10 | method.invoke(this, object); 11 | } 12 | 13 | public void visitDefault(final Object object) throws Exception { 14 | // Do nothing 15 | } 16 | 17 | protected Method getMethod(final Class targetClass) throws NoSuchMethodException { 18 | Class superClass = targetClass; 19 | while (superClass != Object.class) { 20 | try { 21 | return getClass().getMethod("visit", superClass); 22 | } catch (final NoSuchMethodException e) { 23 | superClass = superClass.getSuperclass(); 24 | } 25 | } 26 | final Class[] ifaces = targetClass.getInterfaces(); 27 | for (final Class iface : ifaces) { 28 | try { 29 | return getClass().getMethod("visit", iface); 30 | } catch (final NoSuchMethodException e) { 31 | } 32 | } 33 | return getClass().getMethod("visitDefault", Object.class); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.io.Serializable; 16 | import java.util.Map; 17 | 18 | /** 19 | * Defines properties common to all (or most) of other entities. 20 | */ 21 | public interface BaseEntity extends Serializable { 22 | 23 | // Methods for working with properties 24 | 25 | String getNumber(); 26 | 27 | void setNumber(String number); 28 | 29 | Boolean getActive(); 30 | 31 | void setActive(Boolean active); 32 | 33 | // Methods for working with custom properties 34 | 35 | Map getProperties(); 36 | 37 | void addProperty(String property, String value); 38 | 39 | void removeProperty(final String property); 40 | 41 | Map asMap(); 42 | } 43 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-transaction-update.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | TR001TEST 8 | true 9 | PENDING 10 | AUTO_LICENSE_CREATE 11 | 100.00 12 | 5.00 13 | EUR 14 | 2014-07-20T00:49:02.640Z 15 | 2014-07-19T23:47:38.266Z 16 | false 17 | 123 18 | Custom property value 19 | 1 20 | 19 21 | GROSS 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Token.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.util.Date; 16 | import java.util.Map; 17 | 18 | import com.labs64.netlicensing.domain.vo.ITokenType; 19 | 20 | /** 21 | * Token entity used internally by NetLicensing. 22 | */ 23 | public interface Token extends BaseEntity { 24 | 25 | // Methods for working with properties 26 | 27 | String getVendorNumber(); 28 | 29 | void setVendorNumber(String vendorNumber); 30 | 31 | Date getExpirationTime(); 32 | 33 | void setExpirationTime(Date expirationTime); 34 | 35 | ITokenType getTokenType(); 36 | 37 | void setTokenType(ITokenType tokenType); 38 | 39 | // Methods for working with custom properties 40 | 41 | @Deprecated 42 | Map getTokenProperties(); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/DateUtils.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.util; 14 | 15 | import java.util.Calendar; 16 | import java.util.TimeZone; 17 | 18 | import jakarta.xml.bind.DatatypeConverter; 19 | 20 | public class DateUtils { 21 | 22 | public static Calendar getCurrentDate() { 23 | return Calendar.getInstance(TimeZone.getTimeZone("UTC")); 24 | } 25 | 26 | public static Calendar parseDate(final String dateTime) { 27 | Calendar dateTimeCl = DatatypeConverter.parseDateTime(dateTime); 28 | dateTimeCl.setTimeZone(TimeZone.getTimeZone("UTC")); 29 | return dateTimeCl; 30 | } 31 | 32 | public static String printDate(final Calendar date) { 33 | date.setTimeZone(TimeZone.getTimeZone("UTC")); 34 | return DatatypeConverter.printDateTime(date); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensee-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | L001-TEST 8 | true 9 | P001-TEST 10 | true 11 | 12 | 13 | L10-TEST 14 | true 15 | P10-TEST 16 | true 17 | 18 | 19 | L002-TEST 20 | true 21 | P001-TEST 22 | Custom property value 23 | true 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/resources/Isb-DEMO.xml: -------------------------------------------------------------------------------- 1 | ICC1F7ZKeQoayrzn1iGtw7Zt96s=jYb0aGBPR9Rn4HVRJhBsIRafzW1k3D/GF7GZ62nT8dwvJszGB0kEXdFrXTj7FhUeiBcBlqxcsEUUKA5XbE7LGbNm+V+f5xZu/+n/d/miufKPAIk6CN5xoZQLDRGRSruW0LiKJsnkbzHvIF4u6G/HUyQpUfrxwiqXb+tYFpiaMgcSHL5xGzRq5Mqusw21Cdq81MhUb9oUoujgisIZWqNyebOqWuzOjNJOy0y2uml4I5U5tBAL1OlrQKjfPUiy369HwMl37A7dR9oVcahb6/YPI039xeLTn+WzyFPIV7f41o6Ytq4Iefl6swj/elNKTHi9bYzcnjmM7ebOd+hinm8feA==Msb-DEMOtrue2021-04-21T20:15:45.694ZModule using "Subscription" licensing modelSubscription -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/PaymentMethodImpl.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity.impl; 14 | 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | import com.labs64.netlicensing.domain.entity.PaymentMethod; 19 | 20 | /** 21 | * Default implementation of {@link com.labs64.netlicensing.domain.entity.PaymentMethod}. 22 | */ 23 | public class PaymentMethodImpl extends BaseEntityImpl implements PaymentMethod { 24 | 25 | private static final long serialVersionUID = -529417516632266683L; 26 | 27 | /** 28 | * @see BaseEntityImpl#getReservedProps() 29 | */ 30 | public static List getReservedProps() { 31 | return BaseEntityImpl.getReservedProps(); 32 | } 33 | 34 | @Override 35 | public Map getPaymentMethodProperties() { 36 | return getProperties(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Country.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.math.BigDecimal; 16 | 17 | /** 18 | * Country entity used internally by NetLicensing. 19 | *

20 | * Properties visible via NetLicensing API: 21 | *

22 | * code - Unique code of country. 23 | *

24 | * name - Unique name of country 25 | *

26 | * vat - Country vat. 27 | *

28 | * isEu - is country in EU. 29 | *

30 | */ 31 | public interface Country extends BaseEntity { 32 | 33 | void setCode(final String code); 34 | 35 | String getCode(); 36 | 37 | void setName(final String name); 38 | 39 | String getName(); 40 | 41 | void setVatPercent(final BigDecimal vat); 42 | 43 | BigDecimal getVatPercent(); 44 | 45 | void setIsEu(final boolean isEu); 46 | 47 | boolean getIsEu(); 48 | } 49 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/xmldsig/xml-signed-nlic-01.xml: -------------------------------------------------------------------------------- 1 | ICC1F7ZKeQoayrzn1iGtw7Zt96s=jYb0aGBPR9Rn4HVRJhBsIRafzW1k3D/GF7GZ62nT8dwvJszGB0kEXdFrXTj7FhUeiBcBlqxcsEUUKA5XbE7LGbNm+V+f5xZu/+n/d/miufKPAIk6CN5xoZQLDRGRSruW0LiKJsnkbzHvIF4u6G/HUyQpUfrxwiqXb+tYFpiaMgcSHL5xGzRq5Mqusw21Cdq81MhUb9oUoujgisIZWqNyebOqWuzOjNJOy0y2uml4I5U5tBAL1OlrQKjfPUiy369HwMl37A7dR9oVcahb6/YPI039xeLTn+WzyFPIV7f41o6Ytq4Iefl6swj/elNKTHi9bYzcnjmM7ebOd+hinm8feA==Msb-DEMOtrue2021-04-21T20:15:45.694ZModule using "Subscription" licensing modelSubscription -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/PaymentMethodEnum.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | import org.apache.commons.lang3.StringUtils; 16 | 17 | /** 18 | * This enum defines payment methods supported by NetLicensing. 19 | */ 20 | public enum PaymentMethodEnum { 21 | 22 | /** 23 | * "null" payment method is a placeholder for undefined/unset value. 24 | */ 25 | NULL, 26 | 27 | PAYPAL, 28 | 29 | PAYPAL_SANDBOX, 30 | 31 | STRIPE, 32 | 33 | STRIPE_TESTING; 34 | 35 | public static PaymentMethodEnum parseString(final String paymentMethod) { 36 | if (StringUtils.isBlank(paymentMethod)) { 37 | return null; 38 | } 39 | 40 | try { 41 | return PaymentMethodEnum.valueOf(paymentMethod); 42 | } catch (IllegalArgumentException e) { 43 | return null; 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/xmldsig/xml-signed-nlic-02-mismatch.xml: -------------------------------------------------------------------------------- 1 | ICC1F7ZKeQoayrzn1iGtw7Zt96s=jYb0aGBPR9Rn4HVRJhBsIRafzW1k3D/GF7GZ62nT8dwvJszGB0kEXdFrXTj7FhUeiBcBlqxcsEUUKA5XbE7LGbNm+V+f5xZu/+n/d/miufKPAIk6CN5xoZQLDRGRSruW0LiKJsnkbzHvIF4u6G/HUyQpUfrxwiqXb+tYFpiaMgcSHL5xGzRq5Mqusw21Cdq81MhUb9oUoujgisIZWqNyebOqWuzOjNJOy0y2uml4I5U5tBAL1OlrQKjfPUiy369HwMl37A7dR9oVcahb6/YPI039xeLTn+WzyFPIV7f41o6Ytq4Iefl6swj/elNKTHi9bYzcnjmM7ebOd+hinm8feA==Msb-DEMO-MISMATCHtrue2021-04-21T20:15:45.694ZModule using "Subscription" licensing modelSubscription -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/auth/UsernamePasswordAuthentication.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.provider.auth; 14 | 15 | /** 16 | */ 17 | public class UsernamePasswordAuthentication implements Authentication { 18 | 19 | private final String username; 20 | private final String password; 21 | 22 | /** 23 | * Constructor 24 | * 25 | * @param username 26 | * for basic HTTP authentication 27 | * @param password 28 | * for basic HTTP authentication 29 | */ 30 | public UsernamePasswordAuthentication(final String username, final String password) { 31 | this.username = username; 32 | this.password = password; 33 | } 34 | 35 | @Override 36 | public String getUsername() { 37 | return username; 38 | } 39 | 40 | @Override 41 | public String getPassword() { 42 | return password; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/Converter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import com.labs64.netlicensing.exception.ConversionException; 16 | 17 | /** 18 | * A converter converts a source object of type S to a target of type T. Implementations of this interface are 19 | * thread-safe and can be shared. 20 | * 21 | * @param 22 | * The source type 23 | * @param 24 | * The target type 25 | */ 26 | public interface Converter { 27 | 28 | /** 29 | * Convert the source of type S to target type T. 30 | * 31 | * @param source 32 | * the source object to converter, which must be an instance of S 33 | * @return the converted object, which must be an instance of T 34 | * @throws ConversionException 35 | * if the source could not be converted to the desired target type 36 | */ 37 | T convert(S source) throws ConversionException; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-product-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | P001-TEST 8 | true 9 | Test Product 1 10 | v1.0 11 | Licensed to Licensee 12 | 13 | 14 | P002-TEST 15 | true 16 | Test Product 2 17 | v1.1 18 | Licensed to Licensee 19 | 20 | 21 | P003-TEST 22 | true 23 | Test Product 3 24 | v2.0 25 | Licensed to Licensee 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.exception; 14 | 15 | /** 16 | * Helper class for implementing exception classes which are capable of holding cause exceptions. 17 | */ 18 | abstract class ExceptionUtils { 19 | 20 | /** 21 | * Build a message for the given base message and root cause. 22 | * 23 | * @param message 24 | * the base message 25 | * @param cause 26 | * the root cause 27 | * @return the full exception message 28 | */ 29 | public static String buildMessage(final String message, final Throwable cause) { 30 | if (cause != null) { 31 | StringBuilder sb = new StringBuilder(); 32 | if (message != null) { 33 | sb.append(message).append("; "); 34 | } 35 | sb.append("cause exception is ").append(cause); 36 | return sb.toString(); 37 | } else { 38 | return message; 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/LicenseTransactionJoinImpl.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity.impl; 14 | 15 | import com.labs64.netlicensing.domain.entity.License; 16 | import com.labs64.netlicensing.domain.entity.LicenseTransactionJoin; 17 | import com.labs64.netlicensing.domain.entity.Transaction; 18 | 19 | public class LicenseTransactionJoinImpl implements LicenseTransactionJoin { 20 | 21 | private static final long serialVersionUID = -4119701993632165536L; 22 | 23 | private Transaction transaction; 24 | private License license; 25 | 26 | @Override 27 | public void setTransaction(final Transaction transaction) { 28 | this.transaction = transaction; 29 | } 30 | 31 | @Override 32 | public Transaction getTransaction() { 33 | return transaction; 34 | } 35 | 36 | @Override 37 | public void setLicense(final License license) { 38 | this.license = license; 39 | } 40 | 41 | @Override 42 | public License getLicense() { 43 | return license; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/RestException.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.exception; 14 | 15 | /** 16 | * The Class RestException can be used in cases where no checked exception can be thrown (e.g. 3pp interfaces 17 | * implementation). 18 | */ 19 | public class RestException extends NetLicensingException { 20 | 21 | private static final long serialVersionUID = -3863879794574523844L; 22 | 23 | /** 24 | * Construct a RestException with the specified detail message. 25 | * 26 | * @param msg 27 | * the detail message 28 | */ 29 | public RestException(final String msg) { 30 | super(msg); 31 | } 32 | 33 | /** 34 | * Construct a RestException with the specified detail message and cause exception. 35 | * 36 | * @param msg 37 | * the detail message 38 | * @param cause 39 | * the cause exception 40 | */ 41 | public RestException(final String msg, final Throwable cause) { 42 | super(msg, cause); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/ConvertUtils.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.util; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.net.URLEncoder; 5 | import java.util.Collection; 6 | import java.util.Map; 7 | import java.util.Map.Entry; 8 | 9 | import com.labs64.netlicensing.domain.entity.BaseEntity; 10 | import com.labs64.netlicensing.provider.Form; 11 | 12 | public class ConvertUtils { 13 | 14 | public static Form entityToForm(BaseEntity entity) { 15 | final Form form = new Form(); 16 | for (final Entry prop : entity.asMap().entrySet()) { 17 | if (prop.getValue() != null) { 18 | if (prop.getValue() instanceof Collection) { 19 | for (Object value: (Collection) prop.getValue()) { 20 | form.param(prop.getKey(), value.toString()); 21 | } 22 | } else { 23 | form.param(prop.getKey(), prop.getValue().toString()); 24 | } 25 | } 26 | } 27 | return form; 28 | } 29 | 30 | public static String mapToParamString(Map params) throws UnsupportedEncodingException { 31 | StringBuilder paramStr = new StringBuilder(); 32 | for (Map.Entry param : params.entrySet()) { 33 | if (paramStr.length() != 0) 34 | paramStr.append('&'); 35 | paramStr.append(URLEncoder.encode(param.getKey(), "UTF-8")); 36 | paramStr.append('='); 37 | paramStr.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); 38 | } 39 | return paramStr.toString(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/utils/ConsoleWriter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.utils; 14 | 15 | import static java.lang.System.out; 16 | 17 | import com.labs64.netlicensing.domain.vo.Page; 18 | 19 | /** 20 | * Utility class for writing to console 21 | */ 22 | public class ConsoleWriter { 23 | 24 | public void writeMessage(final String msg) { 25 | out.println(msg); 26 | out.println(); 27 | } 28 | 29 | public void writeException(final String msg, final Exception ex) { 30 | out.println(msg); 31 | ex.printStackTrace(); 32 | out.println(); 33 | } 34 | 35 | public void writeObject(final String msg, final Object obj) { 36 | out.println(msg); 37 | out.println(obj); 38 | out.println(); 39 | } 40 | 41 | public void writePage(final String msg, final Page page) { 42 | out.println(msg); 43 | if (page != null && page.hasContent()) { 44 | for (final Object object : page.getContent()) { 45 | out.println(object); 46 | } 47 | } 48 | out.println(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/ConversionException.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.exception; 14 | 15 | /** 16 | * This exception class should be used when there's a problem during the conversion from one representation of object to 17 | * another (for example, during the transformation of an XML item to an entity). 18 | */ 19 | public class ConversionException extends NetLicensingException { 20 | 21 | private static final long serialVersionUID = -3798344733724547819L; 22 | 23 | /** 24 | * Construct a ConversionException with the specified detail message. 25 | * 26 | * @param msg 27 | * the detail message 28 | */ 29 | public ConversionException(final String msg) { 30 | super(msg); 31 | } 32 | 33 | /** 34 | * Construct a ConversionException with the specified detail message and cause exception. 35 | * 36 | * @param msg 37 | * the detail message 38 | * @param cause 39 | * the cause exception 40 | */ 41 | public ConversionException(final String msg, final Throwable cause) { 42 | super(msg, cause); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-productmodule-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | PM001-TEST 8 | true 9 | Test module 1 10 | P001-TEST 11 | TryAndBuy 12 | true 13 | 14 | 15 | PM002-TEST 16 | true 17 | Test module 2 18 | P001-TEST 19 | TryAndBuy 20 | true 21 | 22 | 23 | PM003-TEST 24 | true 25 | Test module 3 26 | P002-TEST 27 | Subscription 28 | true 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/resources/rsa_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7mCuhtyeM+HM6 3 | /IbTkM45bpKVQgpruiaEksheXwPx+iG4dRpkugYDYWi3g4/+oVKDQMrh6BsJtT6k 4 | Otqwy8q81MIzPDTKnNvIERphKbrC0R5TjmmlrCPQeM6Hc1GnYOzSFHzFIwoVFz/h 5 | 3zuGySPKMpc6qg5mGqNfBiTuhwh7oAM+kXhgKzl5jj/cIvUmci12UpBGyXxknRip 6 | 75+KB/1qAJa9DQ7R9pF2aCavt5SFT1pc29IlpUlduDpOOGHFW6PN6EXyyH/uzGAb 7 | CpvK6cTXk5ajp0CtELI1R5E6770mni0RP7ZED8+6pBtZboRslYGGmSo13OL0Ji6G 8 | 5SO+TyZ3AgMBAAECggEBAItqwjKDbg9kri7Ocl1Vpw4j0SjAVgJN7EZm2CbaspHp 9 | dZoi3aSyY7mrcSnBywhQWIRXaPCPkVibrJxdaR4vttKzxEhTnGBgRy7fFx3S54vV 10 | 4pXypy2LS2qp/cPIvoyIijhvJXNVYS7fgoiZYSIA5mplQuNEc0MK1RPP+y6SiIlm 11 | 0SEXUXl5OYn3AGQ6hJJXxbN36kOtcwb33C/cY3b9jPl1acAVk84dFl0aAv92ArST 12 | PahsxQDbRDaDxZ/lfk1mZqPexiWorAZWMck8nOyZhKu5/oXy6OcXfqVjdwmlqY05 13 | hNS7mxSOUy+7umqbcV/bdhvqMJr+DeI1vqQS5J+t3vECgYEA8GZ6oxUiuwYJ98jS 14 | Nx+i7Jj+ZTEFJ7WiepX5mOU13GlS0vAvhPdK9juEYbS7Znpp35WgwxuPsCn9hXIO 15 | gjR0eSYN7QB5RVn7zjo+SQRw2C+HAt7G/wazq3ekSdNgKe8+Wa7YxLL8ypaOy1me 16 | 7L4JQGgM6ORgnYH/+BC7P/KO80MCgYEAx8R7W2Fzo1I+RPfKQeVQ/i4a+/DMK0js 17 | XhpkMh/8NXbdHYNDdsQTQ2E8V+5gNi+zCqMuwIxA8cx9lAL32x1fMWnbHV9YwSFZ 18 | ZOEG/YFyqcBOtQztt8jHGtXN70FQdwSwqcFdntNTCjJquN2gX1n2qFR2bezcULaj 19 | Iiyc/j3AWr0CgYBQmbtidFKpq/OpnS5GBxhkBUO9/7p/vtlUCnad+bOeS73WNWtp 20 | RFRgzEGtVKBEUqSurwcwg0wgv2Nd24jbxOSMPeMLZE5En0/arBJ3/sIq6Xx1zOWh 21 | Wcjho4J0sicayDj6brIE+RHihqonqcusCmclrf0uFGwEQzLkJA/z98pP6wKBgAti 22 | iEE5+ZQqQMA/evhscEQ8Lm+DVq901Xu7d1BgAEivwIRJEdQ38n0Zko3UWQldiI+n 23 | oyd4Fs9w/wsrbCLBtsYjKUiwQWeoVebo6DQUZ4uDGTk6RmX9/FLsMnNbPpG547OZ 24 | AJPnqUjgfLKSduxYPTV0stcq85dqATwWXNAkhszlAoGBAOKLU6IKuiRLcOrVon/a 25 | KlXkjBMP2EkTVhuIzgZp6v7P8LK+UfU/6vkJvBW5U9ZosS7f13t7/bJ0AzfJLW6m 26 | J1IedEJExbLmuW7+HfEMyZ5g8dFJZvYBmN/zHQEhFUKDISDI2O2gmd9cPPsMnOxW 27 | WW8VMSYMi1Wtb9v7eRPvRZlE 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/xmldsig/rsa_private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC7mCuhtyeM+HM6 3 | /IbTkM45bpKVQgpruiaEksheXwPx+iG4dRpkugYDYWi3g4/+oVKDQMrh6BsJtT6k 4 | Otqwy8q81MIzPDTKnNvIERphKbrC0R5TjmmlrCPQeM6Hc1GnYOzSFHzFIwoVFz/h 5 | 3zuGySPKMpc6qg5mGqNfBiTuhwh7oAM+kXhgKzl5jj/cIvUmci12UpBGyXxknRip 6 | 75+KB/1qAJa9DQ7R9pF2aCavt5SFT1pc29IlpUlduDpOOGHFW6PN6EXyyH/uzGAb 7 | CpvK6cTXk5ajp0CtELI1R5E6770mni0RP7ZED8+6pBtZboRslYGGmSo13OL0Ji6G 8 | 5SO+TyZ3AgMBAAECggEBAItqwjKDbg9kri7Ocl1Vpw4j0SjAVgJN7EZm2CbaspHp 9 | dZoi3aSyY7mrcSnBywhQWIRXaPCPkVibrJxdaR4vttKzxEhTnGBgRy7fFx3S54vV 10 | 4pXypy2LS2qp/cPIvoyIijhvJXNVYS7fgoiZYSIA5mplQuNEc0MK1RPP+y6SiIlm 11 | 0SEXUXl5OYn3AGQ6hJJXxbN36kOtcwb33C/cY3b9jPl1acAVk84dFl0aAv92ArST 12 | PahsxQDbRDaDxZ/lfk1mZqPexiWorAZWMck8nOyZhKu5/oXy6OcXfqVjdwmlqY05 13 | hNS7mxSOUy+7umqbcV/bdhvqMJr+DeI1vqQS5J+t3vECgYEA8GZ6oxUiuwYJ98jS 14 | Nx+i7Jj+ZTEFJ7WiepX5mOU13GlS0vAvhPdK9juEYbS7Znpp35WgwxuPsCn9hXIO 15 | gjR0eSYN7QB5RVn7zjo+SQRw2C+HAt7G/wazq3ekSdNgKe8+Wa7YxLL8ypaOy1me 16 | 7L4JQGgM6ORgnYH/+BC7P/KO80MCgYEAx8R7W2Fzo1I+RPfKQeVQ/i4a+/DMK0js 17 | XhpkMh/8NXbdHYNDdsQTQ2E8V+5gNi+zCqMuwIxA8cx9lAL32x1fMWnbHV9YwSFZ 18 | ZOEG/YFyqcBOtQztt8jHGtXN70FQdwSwqcFdntNTCjJquN2gX1n2qFR2bezcULaj 19 | Iiyc/j3AWr0CgYBQmbtidFKpq/OpnS5GBxhkBUO9/7p/vtlUCnad+bOeS73WNWtp 20 | RFRgzEGtVKBEUqSurwcwg0wgv2Nd24jbxOSMPeMLZE5En0/arBJ3/sIq6Xx1zOWh 21 | Wcjho4J0sicayDj6brIE+RHihqonqcusCmclrf0uFGwEQzLkJA/z98pP6wKBgAti 22 | iEE5+ZQqQMA/evhscEQ8Lm+DVq901Xu7d1BgAEivwIRJEdQ38n0Zko3UWQldiI+n 23 | oyd4Fs9w/wsrbCLBtsYjKUiwQWeoVebo6DQUZ4uDGTk6RmX9/FLsMnNbPpG547OZ 24 | AJPnqUjgfLKSduxYPTV0stcq85dqATwWXNAkhszlAoGBAOKLU6IKuiRLcOrVon/a 25 | KlXkjBMP2EkTVhuIzgZp6v7P8LK+UfU/6vkJvBW5U9ZosS7f13t7/bJ0AzfJLW6m 26 | J1IedEJExbLmuW7+HfEMyZ5g8dFJZvYBmN/zHQEhFUKDISDI2O2gmd9cPPsMnOxW 27 | WW8VMSYMi1Wtb9v7eRPvRZlE 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToPaymentMethodConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import com.labs64.netlicensing.domain.entity.PaymentMethod; 16 | import com.labs64.netlicensing.domain.entity.impl.PaymentMethodImpl; 17 | import com.labs64.netlicensing.exception.ConversionException; 18 | import com.labs64.netlicensing.schema.context.Item; 19 | import com.labs64.netlicensing.schema.context.Property; 20 | 21 | /** 22 | * Convert {@link Item} entity into {@link PaymentMethod} object. 23 | */ 24 | public class ItemToPaymentMethodConverter extends ItemToEntityBaseConverter { 25 | 26 | @Override 27 | public PaymentMethod convert(final Item source) throws ConversionException { 28 | final PaymentMethod target = super.convert(source); 29 | 30 | // Custom properties 31 | for (final Property property : source.getProperty()) { 32 | if (!PaymentMethodImpl.getReservedProps().contains(property.getName())) { 33 | target.getProperties().put(property.getName(), property.getValue()); 34 | } 35 | } 36 | 37 | return target; 38 | } 39 | 40 | @Override 41 | public PaymentMethod newTarget() { 42 | return new PaymentMethodImpl(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /.github/workflows/netlicensing-dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Dependency Review Action 2 | # 3 | # This Action will scan dependency manifest files that change as part of a Pull Request, 4 | # surfacing known-vulnerable versions of the packages declared or updated in the PR. 5 | # Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable 6 | # packages will be blocked from merging. 7 | # 8 | # Source repository: https://github.com/actions/dependency-review-action 9 | # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement 10 | name: 'NetLicensing - Dependency Review' 11 | on: 12 | pull_request: 13 | branches: [ "master" ] 14 | 15 | # If using a dependency submission action in this workflow this permission will need to be set to: 16 | # 17 | # permissions: 18 | # contents: write 19 | # 20 | # https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api 21 | permissions: 22 | contents: read 23 | # Write permissions for pull-requests are required for using the `comment-summary-in-pr` option, comment out if you aren't using this option 24 | pull-requests: write 25 | 26 | jobs: 27 | dependency-review: 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: 'Checkout repository' 31 | uses: actions/checkout@v4 32 | - name: 'Dependency Review' 33 | uses: actions/dependency-review-action@v4 34 | # Commonly enabled options, see https://github.com/actions/dependency-review-action#configuration-options for all available options. 35 | with: 36 | comment-summary-in-pr: always 37 | # fail-on-severity: moderate 38 | # deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later 39 | # retry-on-snapshot-warnings: true 40 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-token-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 08b66094-a5c4-4c93-be71-567e982d9428 8 | true 9 | 2014-06-30T12:47:56.067Z 10 | SHOP 11 | 12 | https://go.netlicensing.io/shop/v2/?shoptoken=08b66094-a5c4-4c93-be71-567e982d9428 13 | 14 | ITEST-ABC-DEMO 15 | VDEMO 16 | 17 | 18 | 092da8ce-126e-4602-91d8-5c41903846d3 19 | true 20 | 2014-07-22T23:07:46.742Z 21 | DEFAULT 22 | VDEMO 23 | 24 | 25 | 0c924950-de52-4581-b2dc-5031fa04ef29 26 | true 27 | 2014-08-06T13:18:05.982Z 28 | APIKEY 29 | VDEMO 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-bundle-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | B001-TEST 8 | true 9 | Bundle 1 10 | Description 1 11 | 10 12 | EUR 13 | LT001-TEST,LT002-TEST 14 | 15 | 16 | B002-TEST 17 | true 18 | Bundle 2 19 | Description 2 20 | 20 21 | USD 22 | LT003-TEST,LT004-TEST 23 | 24 | 25 | B003-TEST 26 | true 27 | Bundle 3 28 | Description 3 29 | 30 30 | EUR 31 | LT005-TEST,LT006-TEST 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Licensee.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.util.Collection; 16 | import java.util.Map; 17 | 18 | /** 19 | * Licensee entity used internally by NetLicensing. 20 | *

21 | * Properties visible via NetLicensing API: 22 | *

23 | * number - Unique number (across all products of a vendor) that identifies the licensee. Vendor can assign this 24 | * number when creating a licensee or let NetLicensing generate one. Read-only after creation of the first license for 25 | * the licensee. 26 | *

27 | * active - If set to false, the licensee is disabled. Licensee can not obtain new licenses, and validation is 28 | * disabled (tbd). 29 | *

30 | * Arbitrary additional user properties of string type may be associated with each licensee. The name of user property 31 | * must not be equal to any of the fixed property names listed above and must be none of id, productNumber. 32 | */ 33 | public interface Licensee extends BaseEntity { 34 | 35 | // Methods for working with custom properties 36 | 37 | @Deprecated 38 | Map getLicenseeProperties(); 39 | 40 | // Methods for interacting with other entities 41 | 42 | Product getProduct(); 43 | 44 | void setProduct(Product product); 45 | 46 | Collection getLicenses(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/TransactionSource.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | /** 4 | * The transaction source enumeration. 5 | */ 6 | public enum TransactionSource { 7 | 8 | /** 9 | * Shop transaction. 10 | */ 11 | SHOP, 12 | 13 | /** 14 | * Auto transaction for license create. 15 | */ 16 | AUTO_LICENSE_CREATE, 17 | 18 | /** 19 | * Auto transaction for license update. 20 | */ 21 | AUTO_LICENSE_UPDATE, 22 | 23 | /** 24 | * Auto transaction for license delete. 25 | */ 26 | AUTO_LICENSE_DELETE, 27 | 28 | /** 29 | * Auto transaction for licensee create (with automatic licenses). 30 | */ 31 | AUTO_LICENSEE_CREATE, 32 | 33 | /** 34 | * Auto transaction for licensee delete with forceCascade. 35 | */ 36 | AUTO_LICENSEE_DELETE, 37 | 38 | /** 39 | * Transaction for update license during validate 40 | */ 41 | AUTO_LICENSEE_VALIDATE, 42 | 43 | /** 44 | * Auto transaction for license template delete with forceCascade. 45 | */ 46 | AUTO_LICENSETEMPLATE_DELETE, 47 | 48 | /** 49 | * Auto transaction for product module delete with forceCascade. 50 | */ 51 | AUTO_PRODUCTMODULE_DELETE, 52 | 53 | /** 54 | * Auto transaction for product delete with forceCascade. 55 | */ 56 | AUTO_PRODUCT_DELETE, 57 | 58 | /** 59 | * Auto transaction for transfer licenses between licensee. 60 | */ 61 | AUTO_LICENSES_TRANSFER, 62 | 63 | /** 64 | * Transaction for update licenses (inactive with PT LM, Subscription). 65 | */ 66 | SUBSCRIPTION_UPDATE, 67 | 68 | /** 69 | * Transaction for recurring payment. 70 | */ 71 | RECURRING_PAYMENT, 72 | 73 | /** 74 | * Transaction for cancel recurring payment. 75 | */ 76 | CANCEL_RECURRING_PAYMENT, 77 | 78 | /** 79 | * Transaction for obtain bundle. 80 | */ 81 | OBTAIN_BUNDLE; 82 | } 83 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/VatMode.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.domain.vo; 2 | 3 | public enum VatMode { 4 | 5 | /** 6 | * VatMode: Gross 7 | */ 8 | GROSS("GROSS"), 9 | 10 | /** 11 | * VatMode: Net 12 | */ 13 | NET("NET"); 14 | 15 | private final String value; 16 | 17 | /** 18 | * @param vatModeValue 19 | * vatMode value 20 | */ 21 | VatMode(final String vatModeValue) { 22 | value = vatModeValue; 23 | } 24 | 25 | /** 26 | * Get enum value. 27 | * 28 | * @return enum value 29 | */ 30 | public String value() { 31 | return value; 32 | } 33 | 34 | /* 35 | * (non-Javadoc) 36 | * 37 | * @see java.lang.Enum#toString() 38 | */ 39 | @Override 40 | public String toString() { 41 | return value; 42 | } 43 | 44 | /** 45 | * Parse product VAT mode to {@link VatMode} enum. 46 | * 47 | * @param value 48 | * vatMode value 49 | * @return {@link VatMode} enum object or throws {@link IllegalArgumentException} if no corresponding 50 | * {@link VatMode} enum object found 51 | */ 52 | public static VatMode parseValue(final String value) { 53 | for (final VatMode vatMode : VatMode.values()) { 54 | if (vatMode.value.equalsIgnoreCase(value)) { 55 | return vatMode; 56 | } 57 | } 58 | throw new IllegalArgumentException(value); 59 | } 60 | 61 | /** 62 | * Gets the enum safe. 63 | * 64 | * @param val 65 | * the val 66 | * @return the enum safe 67 | */ 68 | public static VatMode parseValueSafe(final String val) { 69 | try { 70 | return parseValue(val); 71 | } catch (final IllegalArgumentException e) { 72 | return null; 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-notification-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | N001-TEST 8 | true 9 | Notification 1 10 | LICENSEE_CREATED 11 | WEBHOOK 12 | http://www.test1.test 13 | ${event} 14 | 15 | 16 | N002-TEST 17 | true 18 | Notification 2 19 | LICENSE_CREATED 20 | WEBHOOK 21 | http://www.test2.test 22 | ${event.timestamp} 23 | 24 | 25 | N003-TEST 26 | true 27 | Notification 3 28 | LICENSEE_CREATED 29 | WEBHOOK 30 | http://www.test3.test 31 | ${event.data} 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Innovative License Management Solution 2 | 3 | # [Labs64 NetLicensing](https://netlicensing.io) Client (Java) 4 | 5 | [![NetLicensing Client - CI](https://github.com/Labs64/NetLicensingClient-java/actions/workflows/netlicesning-client-ci.yml/badge.svg)](https://github.com/Labs64/NetLicensingClient-java/actions/workflows/netlicesning-client-ci.yml) 6 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.labs64.netlicensing/netlicensing-client/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.labs64.netlicensing/netlicensing-client) 7 | [![Apache License 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/Labs64/NetLicensingClient-java/blob/master/LICENSE) 8 | [![📖 Documentation](https://img.shields.io/badge/📖%20Documentation-Wiki-AB6543.svg)](https://netlicensing.io/wiki/restful-api) 9 | [![NetLicensing @ LinkedIn](https://img.shields.io/badge/NetLicensing-0077B5.svg?logo=LinkedIn)](https://www.linkedin.com/showcase/netlicensing) 10 | 11 | Java wrapper for Labs64 NetLicensing [RESTful API](https://netlicensing.io/wiki/restful-api) 12 | 13 | Visit Labs64 NetLicensing at https://netlicensing.io 14 | 15 | ## Quick Start 16 | 17 | The recommended way to get started using [`netlicensing-client`](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.labs64.netlicensing%22) in your project is with a dependency management system – the snippets below can be copied and pasted into your build configuration. 18 | 19 | Maven: 20 | ```xml 21 | 22 | 23 | com.labs64.netlicensing 24 | netlicensing-client 25 | X.Y.Z 26 | 27 | 28 | ``` 29 | Gradle: 30 | ```gradle 31 | dependencies { 32 | compile 'com.labs64.netlicensing:netlicensing-client:X.Y.Z' 33 | } 34 | ``` 35 | 36 | OSGi: 37 | ``` 38 | Require-Bundle: com.labs64.netlicensing.client;bundle-version="X.Y.Z" 39 | ``` 40 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/AbstractRestProvider.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.provider; 14 | 15 | import com.labs64.netlicensing.provider.auth.Authentication; 16 | import com.labs64.netlicensing.provider.auth.TokenAuthentication; 17 | import com.labs64.netlicensing.provider.auth.UsernamePasswordAuthentication; 18 | 19 | /** 20 | */ 21 | public abstract class AbstractRestProvider implements RestProvider { 22 | 23 | private Authentication authentication; 24 | 25 | private RestProvider.Configuration configuration; 26 | 27 | @Override 28 | public RestProvider authenticate(final Authentication authentication) { 29 | this.authentication = authentication; 30 | return this; 31 | } 32 | 33 | @Override 34 | public RestProvider authenticate(final String username, final String password) { 35 | authentication = new UsernamePasswordAuthentication(username, password); 36 | return this; 37 | } 38 | 39 | @Override 40 | public RestProvider authenticate(final String token) { 41 | authentication = new TokenAuthentication(token); 42 | return this; 43 | } 44 | 45 | protected Authentication getAuthentication() { 46 | return authentication; 47 | } 48 | 49 | @Override 50 | public void configure(final RestProvider.Configuration configuration) { 51 | this.configuration = configuration; 52 | } 53 | 54 | protected RestProvider.Configuration getConfiguration() { 55 | return configuration; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicenseeConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import com.labs64.netlicensing.domain.Constants; 16 | import com.labs64.netlicensing.domain.entity.Licensee; 17 | import com.labs64.netlicensing.domain.entity.impl.LicenseeImpl; 18 | import com.labs64.netlicensing.domain.entity.impl.ProductImpl; 19 | import com.labs64.netlicensing.exception.ConversionException; 20 | import com.labs64.netlicensing.schema.SchemaFunction; 21 | import com.labs64.netlicensing.schema.context.Item; 22 | import com.labs64.netlicensing.schema.context.Property; 23 | 24 | /** 25 | * Convert {@link Item} entity into {@link Licensee} object. 26 | */ 27 | public class ItemToLicenseeConverter extends ItemToEntityBaseConverter { 28 | 29 | @Override 30 | public Licensee convert(final Item source) throws ConversionException { 31 | final Licensee target = super.convert(source); 32 | 33 | // Custom properties 34 | for (final Property property : source.getProperty()) { 35 | if (!LicenseeImpl.getReservedProps().contains(property.getName())) { 36 | target.getProperties().put(property.getName(), property.getValue()); 37 | } 38 | } 39 | 40 | target.setProduct(new ProductImpl()); 41 | target.getProduct().setNumber( 42 | SchemaFunction.propertyByName(source.getProperty(), Constants.Product.PRODUCT_NUMBER).getValue()); 43 | 44 | return target; 45 | } 46 | 47 | @Override 48 | public Licensee newTarget() { 49 | return new LicenseeImpl(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Page.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * A page is a sub-list of a list of objects. It allows gain information about the position of it in the containing 19 | * entire list. 20 | * 21 | * @param 22 | */ 23 | public interface Page extends Iterable { 24 | 25 | /** 26 | * Returns the number of the current page. Is always non-negative. 27 | * 28 | * @return the number of the current page. 29 | */ 30 | int getPageNumber(); 31 | 32 | /** 33 | * Returns the number of elements on the page. 34 | * 35 | * @return the number of elements on the page. 36 | */ 37 | int getItemsNumber(); 38 | 39 | /** 40 | * Returns the number of total pages. 41 | * 42 | * @return the number of total pages 43 | */ 44 | int getTotalPages(); 45 | 46 | /** 47 | * Returns the total amount of elements. 48 | * 49 | * @return the total amount of elements 50 | */ 51 | long getTotalItems(); 52 | 53 | /** 54 | * Returns if there is a next page exists. 55 | * 56 | * @return true if there is a next page exists, otherwise false. 57 | */ 58 | boolean hasNext(); 59 | 60 | /** 61 | * Return container content. 62 | * 63 | * @return container content 64 | */ 65 | List getContent(); 66 | 67 | /** 68 | * Returns if there is a content exists. 69 | * 70 | * @return true if there is a content exists, otherwise false 71 | */ 72 | boolean hasContent(); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/RestResponse.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.provider; 14 | 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | //import jakarta.ws.rs.core.MultivaluedHashMap; 21 | //import jakarta.ws.rs.core.MultivaluedMap; 22 | 23 | /** 24 | * Contains info about response together with response entity. 25 | * 26 | * @param 27 | * type of response entity 28 | */ 29 | public class RestResponse { 30 | 31 | private int statusCode; 32 | 33 | private Map> headers; 34 | 35 | private T entity; 36 | 37 | public int getStatusCode() { 38 | return this.statusCode; 39 | } 40 | 41 | public void setStatusCode(final int statusCode) { 42 | this.statusCode = statusCode; 43 | } 44 | 45 | public Map> getHeaders() { 46 | return this.headers; 47 | } 48 | 49 | public void setHeaders(Map> headers) { 50 | this.headers = new HashMap<>(); 51 | headers.forEach((header, values) -> { 52 | List this_values; 53 | if (!this.headers.containsKey(header)) { 54 | this_values = new ArrayList<>(); 55 | this.headers.put(header, this_values); 56 | } else { 57 | this_values = this.headers.get(header); 58 | } 59 | values.forEach(value -> this_values.add(value)); 60 | }); 61 | } 62 | 63 | public T getEntity() { 64 | return this.entity; 65 | } 66 | 67 | public void setEntity(final T entity) { 68 | this.entity = entity; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicenseTypePropertiesConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import com.labs64.netlicensing.domain.Constants; 16 | import com.labs64.netlicensing.domain.vo.LicenseTypeProperties; 17 | import com.labs64.netlicensing.exception.ConversionException; 18 | import com.labs64.netlicensing.schema.SchemaFunction; 19 | import com.labs64.netlicensing.schema.context.Item; 20 | 21 | /** 22 | * Converts {@link Item} entity into an implementation of {@link LicenseTypeProperties} interface. 23 | */ 24 | public class ItemToLicenseTypePropertiesConverter implements Converter { 25 | 26 | @Override 27 | public LicenseTypeProperties convert(final Item source) throws ConversionException { 28 | if (!Constants.Utility.LICENSE_TYPE.equals(source.getType())) { 29 | final String sourceType = (source.getType() != null) ? source.getType() : ""; 30 | throw new ConversionException(String.format("Wrong item type '%s', expected '%s'.", sourceType, 31 | Constants.Utility.LICENSE_TYPE)); 32 | } 33 | 34 | final String name = SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue(); 35 | return new LicenseTypePropertiesImpl(name); 36 | } 37 | 38 | private static class LicenseTypePropertiesImpl implements LicenseTypeProperties { 39 | 40 | private final String name; 41 | 42 | public LicenseTypePropertiesImpl(final String name) { 43 | this.name = name; 44 | } 45 | 46 | @Override 47 | public String getName() { 48 | return this.name; 49 | } 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/ProductModule.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.util.Collection; 16 | import java.util.Map; 17 | 18 | /** 19 | * Product module entity used internally by NetLicensing. 20 | *

21 | * Properties visible via NetLicensing API: 22 | *

23 | * number - Unique number (across all products of a vendor) that identifies the product module. Vendor can assign 24 | * this number when creating a product module or let NetLicensing generate one. Read-only after creation of the first 25 | * licensee for the product. 26 | *

27 | * active - If set to false, the product module is disabled. Licensees can not obtain any new licenses for this 28 | * product module. 29 | *

30 | * name - Product module name that is visible to the end customers in NetLicensing Shop. 31 | *

32 | * licensingModel - Licensing model applied to this product module. Defines what license templates can be 33 | * configured for the product module and how licenses for this product module are processed during validation. 34 | */ 35 | public interface ProductModule extends BaseEntity { 36 | 37 | // Methods for working with properties 38 | 39 | String getName(); 40 | 41 | void setName(String name); 42 | 43 | String getLicensingModel(); 44 | 45 | void setLicensingModel(String licensingModel); 46 | 47 | // Methods for working with custom properties 48 | 49 | @Deprecated 50 | Map getProductModuleProperties(); 51 | 52 | // Methods for interacting with other entities 53 | 54 | Product getProduct(); 55 | 56 | void setProduct(Product product); 57 | 58 | Collection getLicenseTemplates(); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToLicensingModelPropertiesConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import com.labs64.netlicensing.domain.Constants; 16 | import com.labs64.netlicensing.domain.vo.LicensingModelProperties; 17 | import com.labs64.netlicensing.exception.ConversionException; 18 | import com.labs64.netlicensing.schema.SchemaFunction; 19 | import com.labs64.netlicensing.schema.context.Item; 20 | 21 | /** 22 | * Converts {@link Item} entity into an implementation of {@link LicensingModelProperties} interface. 23 | */ 24 | public class ItemToLicensingModelPropertiesConverter implements Converter { 25 | 26 | @Override 27 | public LicensingModelProperties convert(final Item source) throws ConversionException { 28 | if (!Constants.Utility.LICENSING_MODEL_PROPERTIES.equals(source.getType())) { 29 | final String sourceType = (source.getType() != null) ? source.getType() : ""; 30 | throw new ConversionException(String.format("Wrong item type '%s', expected '%s'.", sourceType, 31 | Constants.Utility.LICENSING_MODEL_PROPERTIES)); 32 | } 33 | 34 | final String name = SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue(); 35 | return new LicensingModelPropertiesImpl(name); 36 | } 37 | 38 | private static class LicensingModelPropertiesImpl implements LicensingModelProperties { 39 | 40 | private final String name; 41 | 42 | public LicensingModelPropertiesImpl(final String name) { 43 | this.name = name; 44 | } 45 | 46 | @Override 47 | public String getName() { 48 | return this.name; 49 | } 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/exception/ServiceException.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.exception; 14 | 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | //import jakarta.ws.rs.core.MultivaluedHashMap; 19 | //import jakarta.ws.rs.core.MultivaluedMap; 20 | //import jakarta.ws.rs.core.Response; 21 | 22 | import com.labs64.netlicensing.schema.SchemaFunction; 23 | import com.labs64.netlicensing.schema.context.Netlicensing; 24 | 25 | /** 26 | * ServiceException is thrown when error response is received from the service. 27 | */ 28 | public class ServiceException extends NetLicensingException { 29 | 30 | private static final long serialVersionUID = 5253993578845477398L; 31 | 32 | private final int statusCode; 33 | private final Map> headers; 34 | private final Netlicensing errorResponse; 35 | 36 | /** 37 | * Construct a ServiceException with the service error response object. 38 | * 39 | * @param status 40 | * response status 41 | * @param headers 42 | * response headers 43 | * @param errorResponse 44 | * the service response containing the error info. 45 | */ 46 | public ServiceException(final int statusCode, final Map> headers, final Netlicensing errorResponse) { 47 | super(SchemaFunction.infosToMessage(errorResponse)); 48 | this.statusCode = statusCode; 49 | this.headers = headers; 50 | this.errorResponse = errorResponse; 51 | } 52 | 53 | public int getStatusCode() { 54 | return statusCode; 55 | } 56 | 57 | public Map> getHeaders() { 58 | return headers; 59 | } 60 | 61 | public Netlicensing getErrorResponse() { 62 | return errorResponse; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-license-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | LC001-TEST 8 | true 9 | TimeVolume license 10 | 10.00 11 | EUR 12 | false 13 | L001-TEST 14 | LT001-TEST 15 | 30 16 | LC001-PARENT 17 | 2014-07-07T21:30:45.574Z 18 | 19 | 20 | LC002-TEST 21 | false 22 | Test License 2 23 | 13.00 24 | EUR 25 | false 26 | L001-TEST 27 | LT001-TEST 28 | 30 29 | LC002-PARENT 30 | 2014-07-07T08:10:12.449Z 31 | 32 | 33 | LC003-TEST 34 | true 35 | Test License 3 36 | 15.00 37 | EUR 38 | false 39 | L002-TEST 40 | LT002-TEST 41 | 42 | 43 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-bundle-obtain.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | L001-TEST 8 | true 9 | TimeVolume license 10 | 10.00 11 | EUR 12 | false 13 | LE001-TEST 14 | LT001-TEST 15 | 30 16 | LC001-PARENT 17 | 2014-07-07T21:30:45.574Z 18 | 19 | 20 | L002-TEST 21 | false 22 | Test License 2 23 | 13.00 24 | EUR 25 | false 26 | LE001-TEST 27 | LT001-TEST 28 | 30 29 | LC002-PARENT 30 | 2014-07-07T08:10:12.449Z 31 | 32 | 33 | L003-TEST 34 | true 35 | Test License 3 36 | 15.00 37 | EUR 38 | false 39 | LE001-TEST 40 | LT001-TEST 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-transaction-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | TR001TEST 8 | true 9 | CLOSED 10 | AUTO_LICENSE_UPDATE 11 | 2014-07-08T13:24:02.843Z 12 | 2014-07-08T13:24:02.843Z 13 | true 14 | 1 15 | 19 16 | GROSS 17 | 18 | 19 | TR002TEST 20 | true 21 | PENDING 22 | AUTO_LICENSEE_CREATE 23 | 2014-07-08T13:24:02.824Z 24 | 2014-07-08T13:24:02.824Z 25 | true 26 | 1 27 | 19 28 | GROSS 29 | 30 | 31 | TR003TEST 32 | true 33 | CANCELLED 34 | AUTO_PRODUCT_DELETE 35 | 2014-06-20T23:28:05.571Z 36 | 2014-06-20T23:28:05.571Z 37 | true 38 | 1 39 | 19 40 | GROSS 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToProductModuleConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import com.labs64.netlicensing.domain.Constants; 16 | import com.labs64.netlicensing.domain.entity.ProductModule; 17 | import com.labs64.netlicensing.domain.entity.impl.ProductImpl; 18 | import com.labs64.netlicensing.domain.entity.impl.ProductModuleImpl; 19 | import com.labs64.netlicensing.exception.ConversionException; 20 | import com.labs64.netlicensing.schema.SchemaFunction; 21 | import com.labs64.netlicensing.schema.context.Item; 22 | import com.labs64.netlicensing.schema.context.Property; 23 | 24 | /** 25 | * Convert {@link Item} entity into {@link ProductModule} object. 26 | */ 27 | public class ItemToProductModuleConverter extends ItemToEntityBaseConverter { 28 | 29 | @Override 30 | public ProductModule convert(final Item source) throws ConversionException { 31 | final ProductModule target = super.convert(source); 32 | 33 | target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue()); 34 | target.setLicensingModel(SchemaFunction.propertyByName(source.getProperty(), 35 | Constants.ProductModule.LICENSING_MODEL).getValue()); 36 | 37 | target.setProduct(new ProductImpl()); 38 | target.getProduct().setNumber( 39 | SchemaFunction.propertyByName(source.getProperty(), Constants.Product.PRODUCT_NUMBER).getValue()); 40 | 41 | // Custom properties 42 | for (final Property property : source.getProperty()) { 43 | if (!ProductModuleImpl.getReservedProps().contains(property.getName())) { 44 | target.getProperties().put(property.getName(), property.getValue()); 45 | } 46 | } 47 | 48 | return target; 49 | } 50 | 51 | @Override 52 | public ProductModule newTarget() { 53 | return new ProductModuleImpl(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/XMLDSigValidatorCustom.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.util; 2 | 3 | import java.security.Key; 4 | 5 | import javax.annotation.Nonnull; 6 | import javax.xml.crypto.KeySelector; 7 | import javax.xml.crypto.dsig.XMLSignature; 8 | import javax.xml.crypto.dsig.XMLSignatureException; 9 | 10 | import org.w3c.dom.Document; 11 | import org.w3c.dom.Element; 12 | import org.w3c.dom.NodeList; 13 | 14 | import com.helger.commons.ValueEnforcer; 15 | import com.helger.xmldsig.XMLDSigSetup; 16 | import com.helger.xmldsig.XMLDSigValidationResult; 17 | import com.helger.xmldsig.XMLDSigValidator; 18 | 19 | public class XMLDSigValidatorCustom { 20 | 21 | private XMLDSigValidatorCustom() { 22 | } 23 | 24 | /** 25 | * Verify whether Document contains XML signature. 26 | * @param aDoc document to be verified 27 | * @return true if Document contains XML signature 28 | */ 29 | public static boolean containsSignature(@Nonnull final Document aDoc) { 30 | return XMLDSigValidator.containsSignature(aDoc); 31 | } 32 | 33 | /** 34 | * Validate XML (imline) signature. 35 | * @param aDoc Document containing inline sign certificate 36 | * @return XMLDSig validation result 37 | * @throws XMLSignatureException 38 | */ 39 | public static XMLDSigValidationResult validateSignature(@Nonnull final Document aDoc) 40 | throws XMLSignatureException { 41 | return validateSignature(aDoc, null); 42 | } 43 | 44 | /** 45 | * Validate XML (detached) signature. 46 | * @param aDoc Document signature 47 | * @return XMLDSig validation result 48 | * @throws XMLSignatureException 49 | */ 50 | public static XMLDSigValidationResult validateSignature(@Nonnull final Document aDoc, final Key aKey) 51 | throws XMLSignatureException { 52 | ValueEnforcer.notNull(aDoc, "Document"); 53 | 54 | // Find Signature element. 55 | final NodeList aSignatureNL = aDoc.getElementsByTagNameNS(XMLSignature.XMLNS, XMLDSigSetup.ELEMENT_SIGNATURE); 56 | if (aSignatureNL.getLength() != 1) { 57 | throw new IllegalArgumentException("Cannot find exactly one Signature element."); 58 | } 59 | final Element aSignatureElement = (Element) aSignatureNL.item(0); 60 | 61 | if (aKey == null) { 62 | return XMLDSigValidator.validateSignature(aDoc, aSignatureElement); 63 | } else { 64 | return XMLDSigValidator.validateSignature(aDoc, aSignatureElement, KeySelector.singletonKeySelector(aKey)); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/LicenseeImpl.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity.impl; 14 | 15 | import java.util.ArrayList; 16 | import java.util.Collection; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | import com.labs64.netlicensing.domain.Constants; 21 | import com.labs64.netlicensing.domain.entity.License; 22 | import com.labs64.netlicensing.domain.entity.Licensee; 23 | import com.labs64.netlicensing.domain.entity.Product; 24 | 25 | /** 26 | * Default implementation of {@link com.labs64.netlicensing.domain.entity.Licensee}. 27 | */ 28 | public class LicenseeImpl extends BaseEntityImpl implements Licensee { 29 | 30 | private static final long serialVersionUID = 2704374141788131247L; 31 | 32 | private Product product; 33 | 34 | private Collection licenses; 35 | 36 | /** 37 | * @see BaseEntityImpl#getReservedProps() 38 | */ 39 | public static List getReservedProps() { 40 | final List reserved = BaseEntityImpl.getReservedProps(); 41 | reserved.add(Constants.Product.PRODUCT_NUMBER); // maps to 'product' 42 | reserved.add(Constants.IN_USE); 43 | reserved.add(Constants.Vendor.VENDOR_NUMBER); // used by shop, therefore disallowed for user 44 | return reserved; 45 | } 46 | 47 | @Override 48 | public Product getProduct() { 49 | return product; 50 | } 51 | 52 | @Override 53 | public void setProduct(final Product product) { 54 | product.getLicensees().add(this); 55 | this.product = product; 56 | } 57 | 58 | @Override 59 | public Collection getLicenses() { 60 | if (licenses == null) { 61 | licenses = new ArrayList(); 62 | } 63 | return licenses; 64 | } 65 | 66 | public void setLicenses(final Collection licenses) { 67 | this.licenses = licenses; 68 | } 69 | 70 | @Override 71 | public Map getLicenseeProperties() { 72 | return getProperties(); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToTokenConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import com.labs64.netlicensing.domain.Constants; 16 | import com.labs64.netlicensing.domain.entity.Token; 17 | import com.labs64.netlicensing.domain.entity.impl.TokenImpl; 18 | import com.labs64.netlicensing.domain.vo.TokenType; 19 | import com.labs64.netlicensing.exception.ConversionException; 20 | import com.labs64.netlicensing.schema.SchemaFunction; 21 | import com.labs64.netlicensing.schema.context.Item; 22 | import com.labs64.netlicensing.schema.context.Property; 23 | import com.labs64.netlicensing.util.DateUtils; 24 | 25 | /** 26 | * Convert {@link Item} entity into {@link Token} object. 27 | */ 28 | public class ItemToTokenConverter extends ItemToEntityBaseConverter { 29 | 30 | @Override 31 | public Token convert(final Item source) throws ConversionException { 32 | final Token target = super.convert(source); 33 | 34 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Token.EXPIRATION_TIME).getValue() != null) { 35 | target.setExpirationTime(DateUtils.parseDate(SchemaFunction.propertyByName( 36 | source.getProperty(), Constants.Token.EXPIRATION_TIME).getValue()).getTime()); 37 | } 38 | 39 | target.setTokenType(TokenType.parseString(SchemaFunction.propertyByName(source.getProperty(), 40 | Constants.Token.TOKEN_TYPE).getValue())); 41 | target.setVendorNumber(SchemaFunction.propertyByName(source.getProperty(), 42 | Constants.Token.TOKEN_PROP_VENDORNUMBER).getValue()); 43 | 44 | // Custom properties 45 | for (final Property property : source.getProperty()) { 46 | if (!TokenImpl.getReservedProps().contains(property.getName())) { 47 | target.getProperties().put(property.getName(), property.getValue()); 48 | } 49 | } 50 | 51 | return target; 52 | } 53 | 54 | @Override 55 | public Token newTarget() { 56 | return new TokenImpl(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToCountryConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import jakarta.xml.bind.DatatypeConverter; 16 | 17 | import com.labs64.netlicensing.domain.Constants; 18 | import com.labs64.netlicensing.domain.entity.Country; 19 | import com.labs64.netlicensing.domain.entity.impl.CountryImpl; 20 | import com.labs64.netlicensing.exception.ConversionException; 21 | import com.labs64.netlicensing.schema.SchemaFunction; 22 | import com.labs64.netlicensing.schema.context.Item; 23 | 24 | /** 25 | * Convert {@link Item} entity into {@link Country} object. 26 | */ 27 | public class ItemToCountryConverter extends ItemToEntityBaseConverter { 28 | 29 | @Override 30 | public Country convert(final Item source) throws ConversionException { 31 | final Country target = super.convert(source); 32 | 33 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.CODE).getValue() != null) { 34 | target.setCode(SchemaFunction.propertyByName(source.getProperty(), Constants.Country.CODE).getValue()); 35 | } 36 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.NAME).getValue() != null) { 37 | target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.Country.NAME).getValue()); 38 | } 39 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.VAT_PERCENT).getValue() != null) { 40 | target.setVatPercent(DatatypeConverter.parseDecimal( 41 | SchemaFunction.propertyByName(source.getProperty(), Constants.Country.VAT_PERCENT).getValue())); 42 | } 43 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.Country.IS_EU).getValue() != null) { 44 | target.setIsEu(Boolean 45 | .valueOf(SchemaFunction.propertyByName(source.getProperty(), Constants.Country.IS_EU).getValue())); 46 | } 47 | return target; 48 | } 49 | 50 | @Override 51 | public Country newTarget() { 52 | return new CountryImpl(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/JAXBUtils.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.util; 14 | 15 | import java.io.ByteArrayInputStream; 16 | import java.io.ByteArrayOutputStream; 17 | import java.io.InputStream; 18 | 19 | import jakarta.xml.bind.JAXBContext; 20 | import jakarta.xml.bind.JAXBElement; 21 | import jakarta.xml.bind.JAXBException; 22 | import jakarta.xml.bind.Marshaller; 23 | import jakarta.xml.bind.Unmarshaller; 24 | import javax.xml.transform.stream.StreamSource; 25 | 26 | /** 27 | */ 28 | public final class JAXBUtils { 29 | 30 | public static T readObject(final String resource, final Class expectedType) throws JAXBException { 31 | return readObjectFromInputStream(JAXBUtils.class.getClassLoader().getResourceAsStream(resource), expectedType); 32 | } 33 | 34 | public static T readObjectFromString(final String content, final Class expectedType) throws JAXBException { 35 | return readObjectFromInputStream(new ByteArrayInputStream(content.getBytes()), expectedType); 36 | } 37 | 38 | public static T readObjectFromInputStream(final InputStream inputStream, final Class expectedType) throws JAXBException { 39 | final JAXBContext jaxbContext = JAXBContext.newInstance(expectedType); 40 | final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 41 | final JAXBElement element = unmarshaller.unmarshal(new StreamSource(inputStream), expectedType); 42 | return element.getValue(); 43 | } 44 | 45 | public static String xmlEntityToString(final T entity) { 46 | try { 47 | final JAXBContext jaxbContext = JAXBContext.newInstance(entity.getClass()); 48 | final Marshaller marshaller = jaxbContext.createMarshaller(); 49 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 50 | final ByteArrayOutputStream out = new ByteArrayOutputStream(); 51 | marshaller.marshal(entity, out); 52 | return out.toString(); 53 | } catch (final JAXBException e) { 54 | throw new RuntimeException("Cannot convert object to string.", e); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Composition.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | import java.io.Serializable; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | import java.util.Map.Entry; 19 | 20 | public class Composition implements Serializable { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | private Map properties; 25 | 26 | private String value; 27 | 28 | public Composition() { // list 29 | value = null; 30 | } 31 | 32 | public Composition(final String value) { // property value 33 | this.value = value; 34 | } 35 | 36 | public Map getProperties() { 37 | if (properties == null) { 38 | properties = new HashMap(); 39 | } 40 | return properties; 41 | } 42 | 43 | public String getValue() { 44 | return value; 45 | } 46 | 47 | public void setValue(final String value) { 48 | this.value = value; 49 | } 50 | 51 | public void put(final String key, final String value) { 52 | getProperties().put(key, new Composition(value)); 53 | } 54 | 55 | public void put(final String key, final Composition value) { 56 | getProperties().put(key, value); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | final StringBuilder sb = new StringBuilder(); 62 | if (value == null) { 63 | sb.append("{"); 64 | if (properties == null) { 65 | sb.append(""); 66 | } else { 67 | boolean first = true; 68 | for (final Entry prop : properties.entrySet()) { 69 | if (first) { 70 | first = false; 71 | } else { 72 | sb.append(", "); 73 | } 74 | sb.append(prop.getKey()).append("=").append(prop.getValue()); 75 | } 76 | } 77 | sb.append("}"); 78 | } else { 79 | sb.append(value); 80 | } 81 | return sb.toString(); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/java/com/labs64/netlicensing/service/NetLicensingServiceTest.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.service; 14 | 15 | import jakarta.ws.rs.GET; 16 | import com.labs64.netlicensing.provider.HttpMethod; 17 | import jakarta.ws.rs.Path; 18 | import jakarta.ws.rs.core.Response; 19 | 20 | import org.junit.jupiter.api.BeforeAll; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import com.labs64.netlicensing.domain.vo.Context; 24 | import com.labs64.netlicensing.exception.RestException; 25 | import com.labs64.netlicensing.schema.context.ObjectFactory; 26 | 27 | import static org.junit.jupiter.api.Assertions.assertThrows; 28 | 29 | /** 30 | * Common integration tests for {@link NetLicensingService}. 31 | */ 32 | public class NetLicensingServiceTest extends BaseServiceTest { 33 | 34 | // *** NLIC Tests *** 35 | 36 | private static Context context; 37 | 38 | @BeforeAll 39 | public static void setup() { 40 | context = createContext(); 41 | } 42 | 43 | @Test 44 | public void testNotExistingService() throws Exception { 45 | assertThrows(RestException.class, () -> { 46 | NetLicensingService.getInstance().request(context, HttpMethod.GET, "non-existing-service", null, null); 47 | }); 48 | } 49 | 50 | @Test 51 | public void testUnsupportedStatusCode() throws Exception { 52 | assertThrows(RestException.class, () -> { 53 | NetLicensingService.getInstance().request(context, HttpMethod.GET, "unsupported-status-code", null, null); 54 | }); 55 | } 56 | 57 | // *** NLIC test mock resource *** 58 | 59 | @Override 60 | protected java.lang.Class getResourceClass() { 61 | return NLICResource.class; 62 | } 63 | 64 | @Path(REST_API_PATH) 65 | public static class NLICResource { 66 | 67 | private final ObjectFactory objectFactory = new ObjectFactory(); 68 | 69 | @Path("unsupported-status-code") 70 | @GET 71 | public Response getUnsupportedStatusCode() { 72 | return Response.status(Response.Status.PARTIAL_CONTENT) 73 | .entity(objectFactory.createNetlicensing()) 74 | .build(); 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/demo/NetLicensingClientDemo.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.demo; 14 | 15 | import org.apache.commons.cli.CommandLine; 16 | import org.apache.commons.cli.CommandLineParser; 17 | import org.apache.commons.cli.DefaultParser; 18 | import org.apache.commons.cli.HelpFormatter; 19 | import org.apache.commons.cli.Options; 20 | import org.apache.commons.cli.ParseException; 21 | 22 | import com.labs64.netlicensing.examples.NetLicensingExample; 23 | 24 | public class NetLicensingClientDemo { 25 | 26 | public static void main(final String[] args) { 27 | final Options options = new Options(); 28 | options.addOption("l", false, "list available examples"); 29 | options.addOption("r", true, "run specified example"); 30 | 31 | final CommandLineParser parser = new DefaultParser(); 32 | CommandLine cmd; 33 | try { 34 | cmd = parser.parse(options, args); 35 | } catch (final ParseException e) { 36 | final HelpFormatter formatter = new HelpFormatter(); 37 | formatter.printHelp("java -jar netlicensing-client-demo.jar

27 | * Properties visible via NetLicensing API: 28 | *

29 | * number - Unique number (across all products of a vendor) that identifies the transaction. This number is 30 | * always generated by NetLicensing. 31 | *

32 | * active - always true for transactions 33 | *

34 | * status - see {@link TransactionStatus} 35 | *

36 | * source - see {@link TransactionSource} 37 | *

38 | * grandTotal - grand total for SHOP transaction (see source). 39 | *

40 | * discount - discount for SHOP transaction (see source). 41 | *

42 | * currency - specifies currency for money fields (grandTotal and discount). Check data types to discover which 43 | * currencies are supported. 44 | */ 45 | public interface Transaction extends BaseEntity { 46 | 47 | // Methods for working with properties 48 | 49 | TransactionStatus getStatus(); 50 | 51 | void setStatus(TransactionStatus status); 52 | 53 | TransactionSource getSource(); 54 | 55 | void setSource(TransactionSource source); 56 | 57 | BigDecimal getGrandTotal(); 58 | 59 | void setGrandTotal(BigDecimal grandTotal); 60 | 61 | BigDecimal getDiscount(); 62 | 63 | void setDiscount(BigDecimal discount); 64 | 65 | Currency getCurrency(); 66 | 67 | void setCurrency(Currency currency); 68 | 69 | Date getDateCreated(); 70 | 71 | void setDateCreated(Date dateCreated); 72 | 73 | Date getDateClosed(); 74 | 75 | void setDateClosed(Date dateClosed); 76 | 77 | List getLicenseTransactionJoins(); 78 | 79 | void setLicenseTransactionJoins(List licenseTransactionJoins); 80 | 81 | // Methods for working with custom properties 82 | 83 | @Deprecated 84 | Map getTransactionProperties(); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Product.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.util.Collection; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | /** 20 | * NetLicensing Product entity. 21 | *

22 | * Properties visible via NetLicensing API: 23 | *

24 | * number - Unique number that identifies the product. Vendor can assign this number when creating a product or 25 | * let NetLicensing generate one. Read-only after creation of the first licensee for the product. 26 | *

27 | * active - If set to false, the product is disabled. No new licensees can be registered for the product, 28 | * existing licensees can not obtain new licenses. 29 | *

30 | * name - Product name. Together with the version identifies the product for the end customer. 31 | *

32 | * version - Product version. Convenience parameter, additional to the product name. 33 | *

34 | * licenseeAutoCreate - If set to 'true', non-existing licensees will be created at first validation attempt. 35 | *

36 | * description - Product description. Optional. 37 | *

38 | * licensingInfo - Licensing information. Optional. 39 | *

40 | * Arbitrary additional user properties of string type may be associated with each product. The name of user property 41 | * must not be equal to any of the fixed property names listed above and must not be id. 42 | */ 43 | public interface Product extends BaseEntity { 44 | 45 | // Methods for working with properties 46 | 47 | String getName(); 48 | 49 | void setName(String name); 50 | 51 | String getVersion(); 52 | 53 | void setVersion(String version); 54 | 55 | Boolean getLicenseeAutoCreate(); 56 | 57 | void setLicenseeAutoCreate(Boolean licenseeAutoCreate); 58 | 59 | String getDescription(); 60 | 61 | void setDescription(String description); 62 | 63 | String getLicensingInfo(); 64 | 65 | void setLicensingInfo(String licensingInfo); 66 | 67 | // Methods for working with custom properties 68 | 69 | @Deprecated 70 | Map getProductProperties(); 71 | 72 | // Methods for interacting with other entities 73 | 74 | Collection getProductModules(); 75 | 76 | Collection getLicensees(); 77 | 78 | List getProductDiscounts(); 79 | 80 | void addDiscount(ProductDiscount discount); 81 | } 82 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToBundleConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import java.util.Arrays; 16 | 17 | import com.labs64.netlicensing.domain.Constants; 18 | import com.labs64.netlicensing.domain.entity.Bundle; 19 | import com.labs64.netlicensing.domain.entity.impl.BundleImpl; 20 | import com.labs64.netlicensing.domain.entity.impl.LicenseTemplateImpl; 21 | import com.labs64.netlicensing.domain.vo.Currency; 22 | import com.labs64.netlicensing.domain.vo.Money; 23 | import com.labs64.netlicensing.exception.ConversionException; 24 | import com.labs64.netlicensing.schema.SchemaFunction; 25 | import com.labs64.netlicensing.schema.context.Item; 26 | import com.labs64.netlicensing.schema.context.Property; 27 | 28 | /** 29 | * Convert {@link Item} entity into {@link Bundle} object. 30 | */ 31 | public class ItemToBundleConverter extends ItemToEntityBaseConverter { 32 | 33 | @Override 34 | public Bundle convert(final Item source) throws ConversionException { 35 | final Bundle target = super.convert(source); 36 | 37 | target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue()); 38 | target.setDescription(SchemaFunction.propertyByName(source.getProperty(), Constants.Bundle.DESCRIPTION).getValue()); 39 | if (SchemaFunction.propertyByName(source.getProperty(), Constants.PRICE).getValue() != null) { 40 | final Money price = convertPrice(source.getProperty(), Constants.PRICE); 41 | target.setPrice(price.getAmount()); 42 | target.setCurrency(Currency.valueOf(price.getCurrencyCode())); 43 | } 44 | 45 | final String licenseTemplateNumbers = SchemaFunction.propertyByName(source.getProperty(), Constants.Bundle.LICENSE_TEMPLATE_NUMBERS).getValue(); 46 | 47 | if (licenseTemplateNumbers != null) { 48 | target.setLicenseTemplateNumbers(Arrays.asList(licenseTemplateNumbers.split(","))); 49 | } 50 | 51 | // Custom properties 52 | for (final Property property : source.getProperty()) { 53 | if (!LicenseTemplateImpl.getReservedProps().contains(property.getName())) { 54 | target.getProperties().put(property.getName(), property.getValue()); 55 | } 56 | } 57 | 58 | return target; 59 | } 60 | 61 | @Override 62 | public Bundle newTarget() { 63 | return new BundleImpl(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NetLicensingClient/src/test/resources/mock/netlicensing-licensetemplate-list.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | LT001-TEST 8 | true 9 | Feature License Template 10 | FEATURE 11 | 10.00 12 | EUR 13 | false 14 | false 15 | false 16 | PM001-TEST 17 | Test Product Module 18 | true 19 | 20 | 21 | LT002-TEST 22 | true 23 | Time Volume License Template 24 | TIMEVOLUME 25 | 10.00 26 | EUR 27 | false 28 | false 29 | false 30 | PM001-TEST 31 | Test Product Module 32 | true 33 | 30 34 | 35 | 36 | EAAVFLO01-DEMO 37 | true 38 | 3 sessions floating 39 | FLOATING 40 | 50.00 41 | EUR 42 | false 43 | false 44 | false 45 | MAAVFLO-DEMO 46 | Module licensed under Floating LM 47 | true 48 | 3 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Money.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | import java.math.BigDecimal; 16 | 17 | import jakarta.xml.bind.DatatypeConverter; 18 | 19 | import org.apache.commons.lang3.StringUtils; 20 | 21 | import com.labs64.netlicensing.domain.Constants; 22 | 23 | /** 24 | * Holds amount of money with associated currency. 25 | *

26 | * Consider more comprehensive implementation using one of: 27 | *

    28 | *
  • http://joda-money.sourceforge.net/
  • 29 | *
  • http://java.net/projects/javamoney
  • 30 | *
31 | */ 32 | public class Money { 33 | 34 | private BigDecimal amount; 35 | 36 | private String currencyCode; 37 | 38 | public BigDecimal getAmount() { 39 | return amount; 40 | } 41 | 42 | public void setAmount(final BigDecimal amount) { 43 | this.amount = amount; 44 | } 45 | 46 | public String getCurrencyCode() { 47 | return currencyCode; 48 | } 49 | 50 | public void setCurrencyCode(final String currencyCode) { 51 | this.currencyCode = currencyCode; 52 | } 53 | 54 | public static Money convertPrice(final String rawPrice, final String rawCurrency) { 55 | final Money target = new Money(); 56 | if (StringUtils.isNotBlank(rawPrice)) { 57 | try { 58 | target.setAmount(DatatypeConverter.parseDecimal(rawPrice)); 59 | } catch (final NumberFormatException e) { 60 | throw new IllegalArgumentException("'" + Constants.PRICE 61 | + "' format is not correct, expected '0.00' format."); 62 | } 63 | if (StringUtils.isNotBlank(rawCurrency)) { 64 | if (Currency.parseValueSafe(rawCurrency) == null) { 65 | throw new IllegalArgumentException("Unsupported currency."); 66 | } 67 | target.setCurrencyCode(rawCurrency); 68 | } else { 69 | throw new IllegalArgumentException("'" + Constants.PRICE + "' field must be accompanied with the '" 70 | + Constants.CURRENCY + "' field."); 71 | } 72 | } else { // 'price' is not provided 73 | if (StringUtils.isNotBlank(rawCurrency)) { 74 | throw new IllegalArgumentException("'" + Constants.CURRENCY + "' field can not be used without the '" 75 | + Constants.PRICE + "' field."); 76 | } 77 | } 78 | return target; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToEntityBaseConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import java.util.List; 16 | 17 | import com.labs64.netlicensing.domain.Constants; 18 | import com.labs64.netlicensing.domain.entity.BaseEntity; 19 | import com.labs64.netlicensing.domain.vo.Money; 20 | import com.labs64.netlicensing.exception.ConversionException; 21 | import com.labs64.netlicensing.schema.SchemaFunction; 22 | import com.labs64.netlicensing.schema.context.Item; 23 | import com.labs64.netlicensing.schema.context.Property; 24 | 25 | /** 26 | * Convert {@link Item} entity into {@link BaseEntity} object. 27 | */ 28 | abstract class ItemToEntityBaseConverter implements Converter { 29 | 30 | protected abstract T newTarget(); 31 | 32 | @Override 33 | public T convert(final Item source) throws ConversionException { 34 | final T target = newTarget(); 35 | 36 | final String entityClass = target.getClass().getInterfaces()[0].getSimpleName(); 37 | if (!entityClass.equals(source.getType())) { 38 | final String sourceType = (source.getType() != null) ? source.getType() : ""; 39 | throw new ConversionException( 40 | String.format("Wrong item type '%s', expected '%s'.", sourceType, entityClass)); 41 | } 42 | 43 | target.setActive(Boolean.parseBoolean( 44 | SchemaFunction.propertyByName(source.getProperty(), Constants.ACTIVE, Boolean.FALSE.toString()) 45 | .getValue())); 46 | target.setNumber(SchemaFunction.propertyByName(source.getProperty(), Constants.NUMBER).getValue()); 47 | 48 | return target; 49 | } 50 | 51 | /** 52 | * Converts price with currency from NetLicensing XML representation to the internal Money value. 53 | * 54 | * @param source 55 | * - collection of properties from NetLicensing XML 56 | * @param priceProperty 57 | * - the property name holding price value, currency always assumed in Constants.CURRENCY 58 | * @return converted money object 59 | */ 60 | static Money convertPrice(final List source, final String priceProperty) { 61 | final String rawPrice = SchemaFunction.propertyByName(source, priceProperty).getValue(); 62 | final String rawCurrency = SchemaFunction.propertyByName(source, Constants.CURRENCY).getValue(); 63 | return Money.convertPrice(rawPrice, rawCurrency); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/LicenseType.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | public enum LicenseType { 16 | 17 | /** 18 | * licenseType: feature. 19 | */ 20 | FEATURE("FEATURE"), 21 | 22 | /** 23 | * licenseType: TimeVolume. 24 | */ 25 | TIMEVOLUME("TIMEVOLUME"), 26 | 27 | /** 28 | * licenseType: TimeVolume. 29 | */ 30 | FLOATING("FLOATING"), 31 | 32 | /** 33 | * licenseType: Quantity. 34 | */ 35 | QUANTITY("QUANTITY"); 36 | 37 | private final String value; 38 | 39 | /** 40 | * Instantiates a new license type. 41 | * 42 | * @param licenseTypeValue 43 | * licenseType value 44 | */ 45 | LicenseType(final String licenseTypeValue) { 46 | value = licenseTypeValue; 47 | } 48 | 49 | /** 50 | * Get enum value. 51 | * 52 | * @return enum value 53 | */ 54 | public String value() { 55 | return value; 56 | } 57 | 58 | /* 59 | * (non-Javadoc) 60 | * 61 | * @see java.lang.Enum#toString() 62 | */ 63 | @Override 64 | public String toString() { 65 | return value; 66 | } 67 | 68 | /** 69 | * Parse license type value to {@link LicenseType} enum. 70 | * 71 | * @param value 72 | * licenseType value 73 | * @return {@link LicenseType} enum object or throws {@link IllegalArgumentException} if no corresponding 74 | * {@link LicenseType} enum object found 75 | */ 76 | public static LicenseType parseValue(final String value) { 77 | for (final LicenseType licenseType : LicenseType.values()) { 78 | if (licenseType.value.equalsIgnoreCase(value)) { 79 | return licenseType; 80 | } 81 | } 82 | throw new IllegalArgumentException(value); 83 | } 84 | 85 | /** 86 | * Parse license type value to {@link LicenseType} enum, nothrow version. 87 | * 88 | * @param value 89 | * licenseType value as string 90 | * @return {@link LicenseType} enum object or {@code null} if argument doesn't match any of the enum values 91 | */ 92 | public static LicenseType parseValueSafe(final String value) { 93 | try { 94 | return parseValue(value); 95 | } catch (final IllegalArgumentException e) { 96 | return null; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /.github/workflows/netlicensing-client-release.yml: -------------------------------------------------------------------------------- 1 | # This workflow will release the project 2 | 3 | name: NetLicensing Client - Release 4 | 5 | on: 6 | workflow_dispatch: 7 | inputs: 8 | release-version: 9 | required: true 10 | description: The release version X.Y.Z 11 | 12 | jobs: 13 | release: 14 | name: Release ${{ github.event.inputs.release-version }} / Java ${{ matrix.java-version }} 15 | runs-on: self-hosted 16 | env: 17 | RELEASE_WORK_DIR: checkout-for-release 18 | container: maven:3-eclipse-temurin-17 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | java-version: [11, 17] 23 | include: 24 | - java-version: 11 25 | jdk-suffix: 26 | - java-version: 17 27 | jdk-suffix: -jdk17 28 | 29 | steps: 30 | - name: Install required tooling 31 | # Specific to maven:3-amazoncorretto-17-al2023 image 32 | # run: yum install -y --allowerasing git gnupg2 33 | # Specific to maven:3-eclipse-temurin-17 image 34 | run: | 35 | apt-get update 36 | apt-get install -y ssh gnupg2 37 | 38 | - name: Checkout the sources 39 | uses: actions/checkout@v4 40 | with: 41 | path: ${{ env.RELEASE_WORK_DIR }} 42 | ssh-key: '${{ secrets.REPO_SSH_KEY }}' 43 | 44 | # Relies on actions/checkout with 'ssh-key' parameter. 45 | - name: Prepare git config 46 | run: | 47 | cd $RELEASE_WORK_DIR 48 | git config user.name "GitHub Actions Bot" 49 | git config user.email "netlicensing@labs64.com" 50 | 51 | - name: Prepare maven settings.xml 52 | run: | 53 | mkdir -p ~/.m2 54 | cat << EOF >~/.m2/settings.xml 55 | 57 | 58 | 59 | ossrh 60 | ${{ secrets.OSS_USER }} 61 | ${{ secrets.OSS_PASS }} 62 | 63 | 64 | 65 | EOF 66 | 67 | - name: Import GPG key 68 | run: echo "${{ secrets.GPG_KEY }}" | base64 -d | gpg --pinentry-mode loopback --passphrase "${{ secrets.GPG_KEY_PASS }}" --import 69 | 70 | - name: Calculate branch suffix 71 | run: | 72 | BRANCH_SUFFIX=${{ matrix.jdk-suffix }} 73 | echo "Branch suffix: '$BRANCH_SUFFIX'" 74 | echo "BRANCH_SUFFIX=$BRANCH_SUFFIX" >> "$GITHUB_ENV" 75 | 76 | - name: Release to Maven Central staging 77 | run: | 78 | cd $RELEASE_WORK_DIR 79 | mvn -s ~/.m2/settings.xml -B \ 80 | clean deploy scm:tag \ 81 | -P release \ 82 | -Drevision=${{ github.event.inputs.release-version }} \ 83 | -Dsha1=$BRANCH_SUFFIX \ 84 | -Dchangelist= \ 85 | -Djava.version=${{ matrix.java-version }} \ 86 | -Dmessage="Release ${{ github.event.inputs.release-version }}" \ 87 | -Dgpg.passphrase=${{ secrets.GPG_KEY_PASS }} 88 | -------------------------------------------------------------------------------- /NetLicensingClient-demo/src/main/java/com/labs64/netlicensing/examples/OfflineValidation.java: -------------------------------------------------------------------------------- 1 | package com.labs64.netlicensing.examples; 2 | 3 | import java.io.IOException; 4 | import java.io.StringReader; 5 | 6 | import jakarta.xml.bind.JAXBContext; 7 | import jakarta.xml.bind.JAXBException; 8 | import jakarta.xml.bind.Unmarshaller; 9 | 10 | import com.labs64.netlicensing.domain.vo.Context; 11 | import com.labs64.netlicensing.domain.vo.MetaInfo; 12 | import com.labs64.netlicensing.domain.vo.ValidationResult; 13 | import com.labs64.netlicensing.exception.NetLicensingException; 14 | import com.labs64.netlicensing.schema.context.Netlicensing; 15 | import com.labs64.netlicensing.service.ValidationService; 16 | import com.labs64.netlicensing.utils.ConsoleWriter; 17 | import com.labs64.netlicensing.utils.TestHelpers; 18 | 19 | /** 20 | * Demonstrates how to work with offline validation file. 21 | *

22 | * This example uses pre-generated validation file and key. In a real-world application you'll need to do the following 23 | * steps in order to obtain your own files: 24 | *

25 | *
    26 | *
  • Create NetLicensing configuration for your product and add the customer
  • 27 | *
  • Generate key pair
  • 28 | *
  • Create NetLicensing API key with private key
  • 29 | *
  • Download offline validation file using UI or API
  • 30 | *
  • Use your public key and the validation file from above with this code
  • 31 | *
32 | *

33 | * Your application should take care of storing the public key securely, loading it from the file here is merely for 34 | * demonstration purposes. 35 | *

36 | */ 37 | public class OfflineValidation implements NetLicensingExample { 38 | 39 | @Override 40 | public void execute() { 41 | final ConsoleWriter out = new ConsoleWriter(); 42 | try { 43 | // 1. Create context, for offline validation you only need to provide the public key. 44 | final String publicKey = TestHelpers.loadFileContent("rsa_public.pem"); 45 | final Context context = new Context(); 46 | context.setPublicKey(publicKey); 47 | 48 | // 2. Read the validation file as 'Netlicensing' object. 49 | final String offlineValidation = TestHelpers.loadFileContent("Isb-DEMO.xml"); 50 | final JAXBContext jaxbContext = JAXBContext.newInstance(Netlicensing.class); 51 | final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 52 | final StringReader reader = new StringReader(offlineValidation); 53 | final Netlicensing validationFile = (Netlicensing) jaxbUnmarshaller.unmarshal(reader); 54 | 55 | // 3. Validate. ValidationResult is same as if validation would be executed against the 56 | // NetLicensing service online. 57 | final MetaInfo meta = new MetaInfo(); 58 | final ValidationResult validationResult = ValidationService.validateOffline(context, validationFile, meta); 59 | 60 | out.writeObject("Validation result (Offline / signed):", validationResult); 61 | 62 | } catch (final JAXBException | NetLicensingException | IOException e) { 63 | out.writeException("Failure:", e); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/provider/RestProvider.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.provider; 14 | 15 | import java.util.Map; 16 | 17 | import com.labs64.netlicensing.exception.RestException; 18 | import com.labs64.netlicensing.provider.auth.Authentication; 19 | 20 | /** 21 | */ 22 | public interface RestProvider { 23 | 24 | public interface Configuration { 25 | 26 | String getUserAgent(); 27 | 28 | boolean isLoggingEnabled(); 29 | 30 | } 31 | 32 | /** 33 | * Helper method for performing REST requests with optional REST parameter map. 34 | *

35 | * This method has a long list of parameters. It is only intended for internal use. 36 | * 37 | * @param method 38 | * the HTTP method to be used, i.e. GET, PUT, POST. 39 | * @param urlTemplate 40 | * the REST URL urlTemplate. 41 | * @param request 42 | * optional: The request body to be sent to the server. May be null. 43 | * @param responseType 44 | * optional: expected response type. In case no responseType body is expected, responseType may be null. 45 | * @param queryParams 46 | * optional: The REST query parameters values. May be null. 47 | * @param 48 | * type of the request entity 49 | * @param 50 | * type of the responseType entity 51 | * @return the responseType entity received from the server, or null if responseType is null. 52 | */ 53 | RestResponse call(String method, String urlTemplate, REQ request, Class responseType, 54 | Map queryParams) throws RestException; 55 | 56 | /** 57 | * @param username 58 | * username used for authentication 59 | * @param password 60 | * password used for authentication 61 | * @return authenticated RESTful provider 62 | */ 63 | RestProvider authenticate(String username, String password); 64 | 65 | /** 66 | * @param token 67 | * token used for authentication 68 | * @return authenticated RESTful provider 69 | */ 70 | RestProvider authenticate(String token); 71 | 72 | /** 73 | * @param authentication 74 | * {@link Authentication} object 75 | * @return authenticated RESTful provider 76 | */ 77 | RestProvider authenticate(Authentication authentication); 78 | 79 | /** 80 | * @param configuration 81 | * {@link Configuration} configuration to use for the provider 82 | */ 83 | void configure(Configuration configuration); 84 | 85 | } 86 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/util/CheckUtils.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.util; 14 | 15 | import com.labs64.netlicensing.exception.MalformedArgumentsException; 16 | 17 | /** 18 | * Common utilities for precondition checking. 19 | */ 20 | public class CheckUtils { 21 | 22 | /** 23 | * Ensures that an object reference is not null. 24 | * 25 | * @param object 26 | * object to check 27 | * @param msg 28 | * exception message 29 | * @throws MalformedArgumentsException 30 | * if object is null 31 | */ 32 | private static void notNull(final Object object, final String msg) throws MalformedArgumentsException { 33 | if (object == null) { 34 | throw new MalformedArgumentsException(msg); 35 | } 36 | } 37 | 38 | /** 39 | * Ensures that a string is not null or empty. 40 | * 41 | * @param string 42 | * string to check 43 | * @param msg 44 | * exception message 45 | * @throws MalformedArgumentsException 46 | * if string is null or empty 47 | */ 48 | private static void notEmpty(final String string, final String msg) throws MalformedArgumentsException { 49 | if (string == null || string.length() == 0) { 50 | throw new MalformedArgumentsException(msg); 51 | } 52 | } 53 | 54 | /** 55 | * Ensures that an object reference passed as a parameter to the calling method is not null. 56 | * 57 | * @param parameter 58 | * param to check 59 | * @param parameterName 60 | * name of the parameter 61 | * @throws MalformedArgumentsException 62 | * if parameter is null 63 | */ 64 | public static void paramNotNull(final Object parameter, final String parameterName) 65 | throws MalformedArgumentsException { 66 | notNull(parameter, String.format("Parameter '%s' cannot be null", parameterName)); 67 | } 68 | 69 | /** 70 | * Ensures that a string passed as a parameter to the calling method is not null or empty. 71 | * 72 | * @param parameter 73 | * param to check 74 | * @param parameterName 75 | * name of the parameter 76 | * @throws MalformedArgumentsException 77 | * if parameter is null or empty 78 | */ 79 | public static void paramNotEmpty(final String parameter, final String parameterName) 80 | throws MalformedArgumentsException { 81 | notEmpty(parameter, String.format("Parameter '%s' cannot be null or empty string", parameterName)); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/schema/converter/ItemToNotificationConverter.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.schema.converter; 14 | 15 | import java.util.Arrays; 16 | import java.util.Set; 17 | import java.util.stream.Collectors; 18 | 19 | import com.labs64.netlicensing.domain.Constants; 20 | import com.labs64.netlicensing.domain.entity.Notification; 21 | import com.labs64.netlicensing.domain.entity.Product; 22 | import com.labs64.netlicensing.domain.entity.impl.NotificationImpl; 23 | import com.labs64.netlicensing.domain.vo.Event; 24 | import com.labs64.netlicensing.domain.vo.NotificationProtocol; 25 | import com.labs64.netlicensing.exception.ConversionException; 26 | import com.labs64.netlicensing.schema.SchemaFunction; 27 | import com.labs64.netlicensing.schema.context.Item; 28 | import com.labs64.netlicensing.schema.context.Property; 29 | 30 | /** 31 | * Convert {@link Item} entity into {@link Product} object. 32 | */ 33 | public class ItemToNotificationConverter extends ItemToEntityBaseConverter { 34 | 35 | @Override 36 | public Notification convert(final Item source) throws ConversionException { 37 | final Notification target = super.convert(source); 38 | 39 | target.setName(SchemaFunction.propertyByName(source.getProperty(), Constants.NAME).getValue()); 40 | 41 | final Set events = Arrays 42 | .stream(SchemaFunction.propertyByName(source.getProperty(), Constants.Notification.EVENTS).getValue().split(",")) 43 | .map(Event::parseString) 44 | .collect(Collectors.toSet()); 45 | 46 | target.setEvents(events); 47 | target.setProtocol(NotificationProtocol.parseString(SchemaFunction.propertyByName(source.getProperty(), Constants.Notification.PROTOCOL).getValue())); 48 | 49 | final String endpoint = SchemaFunction.propertyByName(source.getProperty(), Constants.Notification.ENDPOINT).getValue(); 50 | 51 | if (endpoint != null) { 52 | target.addProperty(Constants.Notification.ENDPOINT, endpoint); 53 | } 54 | 55 | target.setPayload(SchemaFunction.propertyByName(source.getProperty(), Constants.Notification.PAYLOAD).getValue()); 56 | 57 | // Custom properties 58 | for (final Property property : source.getProperty()) { 59 | if (!NotificationImpl.getReservedProps().contains(property.getName())) { 60 | target.addProperty(property.getName(), property.getValue()); 61 | } 62 | } 63 | 64 | return target; 65 | } 66 | 67 | @Override 68 | public Notification newTarget() { 69 | return new NotificationImpl(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/TokenImpl.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity.impl; 14 | 15 | import java.util.Date; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | import com.labs64.netlicensing.domain.Constants; 20 | import com.labs64.netlicensing.domain.entity.Token; 21 | import com.labs64.netlicensing.domain.vo.ITokenType; 22 | 23 | /** 24 | * Default implementation of {@link com.labs64.netlicensing.domain.entity.Token}. 25 | */ 26 | public class TokenImpl extends BaseEntityImpl implements Token { 27 | 28 | private static final long serialVersionUID = 6688976030475491351L; 29 | 30 | private String vendorNumber; 31 | 32 | private Date expirationTime; 33 | 34 | private ITokenType tokenType; 35 | 36 | /** 37 | * @see BaseEntityImpl#getReservedProps() 38 | */ 39 | public static List getReservedProps() { 40 | final List reserved = BaseEntityImpl.getReservedProps(); 41 | reserved.add(Constants.Token.EXPIRATION_TIME); 42 | reserved.add(Constants.Token.TOKEN_TYPE); 43 | return reserved; 44 | } 45 | 46 | @Override 47 | public String getVendorNumber() { 48 | return vendorNumber; 49 | } 50 | 51 | @Override 52 | public void setVendorNumber(final String vendorNumber) { 53 | this.vendorNumber = vendorNumber; 54 | } 55 | 56 | @Override 57 | public Date getExpirationTime() { 58 | if (expirationTime == null) { 59 | return null; 60 | } else { 61 | return new Date(expirationTime.getTime()); 62 | } 63 | } 64 | 65 | @Override 66 | public void setExpirationTime(final Date expirationTime) { 67 | if (expirationTime == null) { 68 | this.expirationTime = null; 69 | } else { 70 | this.expirationTime = new Date(expirationTime.getTime()); 71 | } 72 | } 73 | 74 | @Override 75 | public ITokenType getTokenType() { 76 | return tokenType; 77 | } 78 | 79 | @Override 80 | public void setTokenType(final ITokenType tokenType) { 81 | this.tokenType = tokenType; 82 | } 83 | 84 | @Override 85 | public Map getTokenProperties() { 86 | return getProperties(); 87 | } 88 | 89 | @Override 90 | public Map asMap() { 91 | final Map map = super.asMap(); 92 | map.put(Constants.Token.EXPIRATION_TIME, getExpirationTime()); 93 | map.put(Constants.Token.TOKEN_TYPE, getTokenType()); 94 | map.put(Constants.Token.TOKEN_PROP_VENDORNUMBER, getVendorNumber()); 95 | return map; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/Context.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.vo; 14 | 15 | import com.labs64.netlicensing.domain.Constants; 16 | 17 | /** 18 | * Provides calling context for the NetLicensing API calls. 19 | *

20 | * The Context object may differ depending on the level at which NetLicensing API is called. 21 | *

22 | * For the internal Java NetLicensing API the Context provides information about the targeted Vendor. 23 | */ 24 | public class Context extends GenericContext { 25 | 26 | private String publicKey; 27 | 28 | public Context() { 29 | super(String.class); 30 | } 31 | 32 | public Context setBaseUrl(final String baseUrl) { 33 | return (Context) this.setValue(Constants.BASE_URL, baseUrl); 34 | } 35 | 36 | public String getBaseUrl() { 37 | return getValue(Constants.BASE_URL); 38 | } 39 | 40 | public Context setUsername(final String username) { 41 | return (Context) this.setValue(Constants.USERNAME, username); 42 | } 43 | 44 | public String getUsername() { 45 | return getValue(Constants.USERNAME); 46 | } 47 | 48 | public Context setPassword(final String password) { 49 | return (Context) this.setValue(Constants.PASSWORD, password); 50 | } 51 | 52 | public String getPassword() { 53 | return getValue(Constants.PASSWORD); 54 | } 55 | 56 | public Context setApiKey(final String apiKey) { 57 | return (Context) this.setValue(Constants.Token.API_KEY, apiKey); 58 | } 59 | 60 | public String getApiKey() { 61 | return getValue(Constants.Token.API_KEY); 62 | } 63 | 64 | public Context setSecurityMode(final SecurityMode securityMode) { 65 | return (Context) this.setValue(Constants.SECURITY_MODE, securityMode.toString()); 66 | } 67 | 68 | public SecurityMode getSecurityMode() { 69 | final String securityMode = getValue(Constants.SECURITY_MODE); 70 | return securityMode != null ? SecurityMode.valueOf(securityMode) : null; 71 | } 72 | 73 | public Context setVendorNumber(final String vendorNumber) { 74 | return (Context) this.setValue(Constants.Vendor.VENDOR_NUMBER, vendorNumber); 75 | } 76 | 77 | public String getVendorNumber() { 78 | return getValue(Constants.Vendor.VENDOR_NUMBER); 79 | } 80 | 81 | /** 82 | * Add public key to be used for validate signed NetLicensing response. 83 | * 84 | * @param publicKey 85 | * client publicKey. 86 | */ 87 | public void setPublicKey(final String publicKey) { 88 | this.publicKey = publicKey; 89 | } 90 | 91 | public String getPublicKey() { 92 | return publicKey; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/License.java: -------------------------------------------------------------------------------- 1 | /* Licensed under the Apache License, Version 2.0 (the "License"); 2 | * you may not use this file except in compliance with the License. 3 | * You may obtain a copy of the License at 4 | * 5 | * https://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | package com.labs64.netlicensing.domain.entity; 14 | 15 | import java.math.BigDecimal; 16 | import java.util.Map; 17 | 18 | import com.labs64.netlicensing.domain.vo.Currency; 19 | 20 | /** 21 | * License entity used internally by NetLicensing. 22 | *

23 | * Properties visible via NetLicensing API: 24 | *

25 | * number - Unique number (across all products/licensees of a vendor) that identifies the license. Vendor can 26 | * assign this number when creating a license or let NetLicensing generate one. Read-only after corresponding creation 27 | * transaction status is set to closed. 28 | *

29 | * name - Name for the licensed item. Set from license template on creation, if not specified explicitly. 30 | *

31 | * active - If set to false, the license is disabled. License can be re-enabled, but as long as it is disabled, 32 | * the license is excluded from the validation process. 33 | *

34 | * price - price for the license. If more than 0, it must always be accompanied by the currency specification. 35 | * Read-only, set from license template on creation. 36 | *

37 | * currency - specifies currency for the license price. Check data types to discover which currencies are 38 | * supported. Read-only, set from license template on creation. 39 | *

40 | * hidden - If set to true, this license is not shown in NetLicensing Shop as purchased license. Set from license 41 | * template on creation, if not specified explicitly. 42 | *

43 | * Arbitrary additional user properties of string type may be associated with each license. The name of user property 44 | * must not be equal to any of the fixed property names listed above and must be none of id, licenseeNumber, 45 | * licenseTemplateNumber. See {@link com.labs64.netlicensing.schema.context.Property} for details. 46 | */ 47 | public interface License extends BaseEntity { 48 | 49 | // Methods for working with properties 50 | 51 | String getName(); 52 | 53 | void setName(String name); 54 | 55 | BigDecimal getPrice(); 56 | 57 | void setPrice(BigDecimal price); 58 | 59 | Currency getCurrency(); 60 | 61 | void setCurrency(Currency currency); 62 | 63 | Boolean getHidden(); 64 | 65 | void setHidden(Boolean hidden); 66 | 67 | // Methods for working with custom properties 68 | 69 | @Deprecated 70 | Map getLicenseProperties(); 71 | 72 | // Methods for interacting with other entities 73 | 74 | Licensee getLicensee(); 75 | 76 | void setLicensee(Licensee licensee); 77 | 78 | LicenseTemplate getLicenseTemplate(); 79 | 80 | void setLicenseTemplate(LicenseTemplate licenseTemplate); 81 | } 82 | --------------------------------------------------------------------------------