├── README.md ├── data-ingestion-demo-war ├── src │ └── main │ │ ├── resources │ │ ├── validation.properties │ │ └── DemoSchema.xsd │ │ ├── webapp │ │ ├── WEB-INF │ │ │ ├── successFile.jsp │ │ │ ├── ok.jsp │ │ │ ├── error.jsp │ │ │ ├── file.jsp │ │ │ ├── errorData.jsp │ │ │ ├── web.xml │ │ │ └── mvc-dispatcher-servlet.xml │ │ ├── index.jsp │ │ └── fileUpload.html │ │ └── java │ │ └── com │ │ └── jason │ │ └── example │ │ ├── controller │ │ ├── DemoCache.java │ │ ├── DemoFileUploadController.java │ │ └── DemoSeekController.java │ │ └── model │ │ ├── package-info.java │ │ ├── Movie.java │ │ ├── Localized.java │ │ ├── ObjectInfos.java │ │ ├── ObjectFactory.java │ │ ├── Lang.java │ │ └── ObjectInfo.java ├── doc │ ├── Data_ingestion.docx │ └── demo.xml └── pom.xml ├── SpringPattern ├── guide.docx ├── src │ ├── main │ │ └── java │ │ │ ├── com │ │ │ └── jason │ │ │ │ └── pattern │ │ │ │ ├── ploicy │ │ │ │ ├── PolicyIF.java │ │ │ │ ├── Policy1.java │ │ │ │ ├── Policy2.java │ │ │ │ └── Policy3.java │ │ │ │ └── OperatorClass.java │ │ │ └── applicationContext.xml │ └── applicationContext.xml └── pom.xml └── java-license-jar ├── doc ├── java_license_guide.docx └── ~$va_license_guide.docx ├── src └── main │ ├── resources │ ├── certfile.cer │ ├── license.lic │ ├── PublicCerts.store │ ├── PrivateKeys.keystore │ ├── verifyparam.properties │ └── createparam.properties │ └── java │ └── zlicense │ ├── util │ ├── HardWareUtils.java │ ├── LicenseCheckModel.java │ └── ListNets.java │ ├── de │ └── schlichtherle │ │ ├── license │ │ ├── Policy.java.bak │ │ ├── CipherParam.java │ │ ├── LicenseContent.java.bak │ │ ├── LicenseNotary.java.bak │ │ ├── LicenseCreator.java │ │ ├── LicenseVerifier.java │ │ ├── LicenseContentException.java │ │ ├── DefaultCipherParam.java │ │ ├── LicenseParam.java │ │ ├── KeyStoreParam.java │ │ ├── IllegalPasswordException.java │ │ ├── LicenseNotaryException.java │ │ ├── NoLicenseInstalledException.java │ │ ├── DefaultKeyStoreParam.java │ │ ├── Policy.java │ │ ├── DefaultLicenseParam.java │ │ ├── LocalKeyStoreParam.java │ │ ├── AbstractKeyStoreParam.java │ │ ├── Resources.properties │ │ ├── CipherParam.java.bak │ │ ├── LicenseCreator.java.bak │ │ ├── Resources_de.properties │ │ ├── DefaultKeyStoreParam.java.bak │ │ ├── DefaultLicenseParam.java.bak │ │ ├── Resources.java │ │ ├── AbstractKeyStoreParam.java.bak │ │ ├── LicenseContentBeanInfo.java │ │ ├── PrivacyGuard.java │ │ ├── LicenseNotary.java │ │ ├── LicenseContent.java │ │ ├── LocalLicenseManager.java │ │ ├── PrivacyGuard.java.bak │ │ └── LicenseManager.java │ │ ├── xml │ │ ├── PersistenceService.java.bak │ │ ├── GenericCertificateNotLockedException.java │ │ ├── XMLConstants.java │ │ ├── GenericCertificateIntegrityException.java │ │ ├── PersistenceServiceException.java │ │ ├── GenericCertificateIsLockedException.java │ │ ├── package-info.java │ │ ├── PersistenceService.java │ │ └── GenericCertificate.java │ │ └── util │ │ └── ObfuscatedString.java │ ├── create │ ├── licenseCreateTest.java │ ├── LicenseManagerHolder.java │ └── CreateLicense.java │ └── verify │ ├── licenseVerifyTest.java │ ├── LicenseManagerHolder.java │ ├── RequestVerifyLicense.java │ └── VerifyLicense.java └── pom.xml /README.md: -------------------------------------------------------------------------------- 1 | # JavaSpringSurmmary 2 | JavaSpringSurmmary 3 | -------------------------------------------------------------------------------- /data-ingestion-demo-war/src/main/resources/validation.properties: -------------------------------------------------------------------------------- 1 | valid.file= Please select a file! -------------------------------------------------------------------------------- /SpringPattern/guide.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/SpringPattern/guide.docx -------------------------------------------------------------------------------- /java-license-jar/doc/java_license_guide.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/doc/java_license_guide.docx -------------------------------------------------------------------------------- /java-license-jar/doc/~$va_license_guide.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/doc/~$va_license_guide.docx -------------------------------------------------------------------------------- /data-ingestion-demo-war/doc/Data_ingestion.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/data-ingestion-demo-war/doc/Data_ingestion.docx -------------------------------------------------------------------------------- /java-license-jar/src/main/resources/certfile.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/resources/certfile.cer -------------------------------------------------------------------------------- /java-license-jar/src/main/resources/license.lic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/resources/license.lic -------------------------------------------------------------------------------- /java-license-jar/src/main/resources/PublicCerts.store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/resources/PublicCerts.store -------------------------------------------------------------------------------- /java-license-jar/src/main/resources/PrivateKeys.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/resources/PrivateKeys.keystore -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/util/HardWareUtils.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/java/zlicense/util/HardWareUtils.java -------------------------------------------------------------------------------- /SpringPattern/src/main/java/com/jason/pattern/ploicy/PolicyIF.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package com.jason.pattern.ploicy; 4 | 5 | public interface PolicyIF { 6 | public void excute(String parameter); 7 | } 8 | -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/de/schlichtherle/license/Policy.java.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/Policy.java.bak -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/de/schlichtherle/license/CipherParam.java: -------------------------------------------------------------------------------- 1 | package zlicense.de.schlichtherle.license; 2 | 3 | public abstract interface CipherParam 4 | { 5 | public abstract String getKeyPwd(); 6 | } 7 | -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/de/schlichtherle/license/LicenseContent.java.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/LicenseContent.java.bak -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/de/schlichtherle/license/LicenseNotary.java.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/LicenseNotary.java.bak -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/de/schlichtherle/xml/PersistenceService.java.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jingshauizh/JavaSpringSurmmary/HEAD/java-license-jar/src/main/java/zlicense/de/schlichtherle/xml/PersistenceService.java.bak -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/de/schlichtherle/xml/GenericCertificateNotLockedException.java: -------------------------------------------------------------------------------- 1 | package zlicense.de.schlichtherle.xml; 2 | 3 | public class GenericCertificateNotLockedException 4 | extends IllegalStateException 5 | {} 6 | -------------------------------------------------------------------------------- /data-ingestion-demo-war/src/main/webapp/WEB-INF/successFile.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 2 | 3 |
4 |en
11 | en
25 | zh
31 | 17 | * Note: To protect your application against reverse engineering 18 | * and thus reduce the risk to compromise the privacy of your passwords, 19 | * it is highly recommended to obfuscate all JAR files which contain class 20 | * files that implement this interface with a tool like 21 | * ProGuard. 22 | * 23 | * @author Christian Schlichtherle 24 | * @version $Id$ 25 | */ 26 | public interface CipherParam { 27 | 28 | /** 29 | * Returns the password used to generate a secret key for 30 | * encryption/decryption of license keys. 31 | * - {@code null} is never returned. 32 | *
33 | * Note that the {@link Policy} class provides additional constraints 34 | * for the returned password. 35 | * 36 | * @see Policy#checkPwd(String) 37 | */ 38 | String getKeyPwd(); 39 | } 40 | -------------------------------------------------------------------------------- /java-license-jar/src/main/java/zlicense/de/schlichtherle/license/LicenseCreator.java.bak: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005-2012 Schlichtherle IT Services 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * which accompanies this distribution, and is available at 7 | * http://www.eclipse.org/legal/epl-v10.html 8 | */ 9 | package de.schlichtherle.license; 10 | 11 | import java.rmi.Remote; 12 | 13 | /** 14 | * Provides remote license creation services. 15 | * 16 | * @author Christian Schlichtherle 17 | * @version $Id$ 18 | */ 19 | public interface LicenseCreator extends Remote { 20 | 21 | /** 22 | * Initializes and validates the license content, creates a new signed 23 | * license certificate for it and compresses, encrypts and returns it 24 | * as a license key. 25 | *
26 | * As a side effect, the given license {@code content} may be initialized
27 | * with some reasonable defaults unless the respective properties have
28 | * already been set.
29 | *
30 | * @param content The license content
31 | * - may not be {@code null}.
32 | *
33 | * @return The license key
34 | * - {@code null} is never returned.
35 | *
36 | * @throws Exception An instance of a subclass of this class for various
37 | * reasons.
38 | * Note that you should always use
39 | * {@link Throwable#getLocalizedMessage()} to get a (possibly
40 | * localized) meaningful detail message.
41 | */
42 | byte[] create(LicenseContent content) throws Exception;
43 | }
44 |
--------------------------------------------------------------------------------
/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/Resources_de.properties:
--------------------------------------------------------------------------------
1 |
2 | fileFilter.description=Lizenz f\u00FCr {0}
3 |
4 | exc.noLicenseInstalled=Es ist kein Lizenz-Zertifikat installiert f\u00FCr {0}.
5 |
6 | exc.jceSetupError=Es scheint, dass die Java Cryptogaphy Extension (JCE) nicht installiert oder defekt ist - bitte (re)installieren Sie sie\!
7 |
8 | exc.consumerAmountIsNotPositive=Lizenz-Verbraucheranzahl ist nicht positiv\!
9 |
10 | exc.consumerTypeIsNull=Lizenz-Verbrauchertyp ist null\!
11 |
12 | exc.licenseHasExpired=Lizenz-Zertifikat ist abgelaufen\!
13 |
14 | exc.licenseIsNotYetValid=Lizenz-Zertifikat ist noch nicht g\u00FCltig\!
15 |
16 | exc.issuedIsNull=Lizenz-Ausstellungsdatum ist null\!
17 |
18 | exc.issuerIsNull=Lizenz-Herausgeber ist null\!
19 |
20 | exc.holderIsNull=Lizenz-Inhaber ist null\!
21 |
22 | exc.invalidSubject=Ung\u00FCltiger Lizenzierungsgegenstand\!
23 |
24 | exc.privateKeyOrPwdIsNotAllowed=Aus Sicherheitsgr\u00FCnden ist es einer Kundenapplikation nicht erlaubt, private Schl\u00FCssel oder Passw\u00F6rter f\u00FCr private Schl\u00FCssel in einem Java keystore bereitzustellen\!
25 |
26 | exc.noKeyPwd=Kein Passwort f\u00FCr Schl\u00FCsseleintrag '{0}' angegeben\!
27 |
28 | exc.noCertificateEntry=Zertifikat oder Alias '{0}' existieren nicht im keystore\!
29 |
30 | exc.noKeyEntry=Privater Schl\u00FCssel oder Alias '{0}' existieren nicht im keystore\!
31 |
32 | exc.consumerTypeIsNotUser=Lizenz-Verbrauchertyp ist nicht "User"\!
33 |
34 | exc.consumerAmountIsNotOne=Lizenz-Verbraucheranzahl ist ungleich eins\!
35 |
36 | exc.policy.IllegalPwd=Das Pa\u00DFwort entspricht nicht der voreingestellten Richtlinie\: Mindestens sechs Zeichen bestehend aus Buchstaben und Ziffern\!
37 |
38 | user=Anonymer Benutzer
39 |
--------------------------------------------------------------------------------
/data-ingestion-demo-war/src/main/resources/DemoSchema.xsd:
--------------------------------------------------------------------------------
1 |
2 |
Java class for Movie complex type. 20 | * 21 | *
The following schema fragment specifies the expected content contained within this class. 22 | * 23 | *
24 | * <complexType name="Movie">
25 | * <complexContent>
26 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
27 | * <sequence>
28 | * <element name="object-Infos" type="{http://www.example.org/DemoSchema}ObjectInfos" minOccurs="0"/>
29 | * </sequence>
30 | * </restriction>
31 | * </complexContent>
32 | * </complexType>
33 | *
34 | *
35 | *
36 | */
37 | @XmlAccessorType(XmlAccessType.FIELD)
38 | @XmlType(name = "Movie", propOrder = {
39 | "objectInfos"
40 | })
41 | @XmlRootElement
42 | public class Movie {
43 |
44 | @XmlElement(name = "object-Infos")
45 | protected ObjectInfos objectInfos;
46 |
47 | /**
48 | * Gets the value of the objectInfos property.
49 | *
50 | * @return
51 | * possible object is
52 | * {@link ObjectInfos }
53 | *
54 | */
55 | public ObjectInfos getObjectInfos() {
56 | return objectInfos;
57 | }
58 |
59 | /**
60 | * Sets the value of the objectInfos property.
61 | *
62 | * @param value
63 | * allowed object is
64 | * {@link ObjectInfos }
65 | *
66 | */
67 | public void setObjectInfos(ObjectInfos value) {
68 | this.objectInfos = value;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/DefaultLicenseParam.java.bak:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2005-2012 Schlichtherle IT Services
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | */
9 | package de.schlichtherle.license;
10 |
11 | import java.util.prefs.Preferences;
12 |
13 | /**
14 | * This is a convenience class implementing the {@link LicenseParam} interface.
15 | *
16 | * @author Christian Schlichtherle
17 | * @version $Id$
18 | */
19 | public class DefaultLicenseParam implements LicenseParam {
20 |
21 | private final String subject;
22 | private final Preferences preferences;
23 | private final KeyStoreParam keyStoreParam;
24 | private final CipherParam cipherParam;
25 |
26 | /**
27 | * Creates a new instance of DefaultLicenseParam.
28 | *
29 | * @param subject The licensing subject
30 | * to be returned by {@link #getSubject()}.
31 | * @param preferences The preferences node used to store the license key
32 | * to be returned by {@link #getPreferences()}.
33 | * @param keyStoreParam The key store parameters
34 | * to be returned by {@link #getKeyStoreParam()}.
35 | * @param cipherParam The cipher parameters
36 | * to be returned by {@link #getCipherParam()}.
37 | */
38 | public DefaultLicenseParam(
39 | String subject,
40 | Preferences preferences,
41 | KeyStoreParam keyStoreParam,
42 | CipherParam cipherParam) {
43 | this.subject = subject;
44 | this.preferences = preferences;
45 | this.keyStoreParam = keyStoreParam;
46 | this.cipherParam = cipherParam;
47 | }
48 |
49 | public String getSubject() {
50 | return subject;
51 | }
52 |
53 | public Preferences getPreferences() {
54 | return preferences;
55 | }
56 |
57 | public KeyStoreParam getKeyStoreParam() {
58 | return keyStoreParam;
59 | }
60 |
61 | public CipherParam getCipherParam() {
62 | return cipherParam;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/Resources.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2005-2012 Schlichtherle IT Services
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | */
9 | package zlicense.de.schlichtherle.license;
10 |
11 | import java.text.MessageFormat;
12 | import java.util.ResourceBundle;
13 |
14 | import zlicense.de.schlichtherle.util.ObfuscatedString;
15 |
16 | /**
17 | * Looks up the resources for this package in a Resource Bundle.
18 | * Provided for comfort.
19 | *
20 | * @author Christian Schlichtherle
21 | * @version $Id$
22 | */
23 | class Resources {
24 |
25 | private static final String CLASS_NAME = new ObfuscatedString(new long[] {
26 | 0x54087D071FCE4840L, 0x50F993D8A5287E71L, 0x3B4F078A163B6812L,
27 | 0xE97B3E32094E2DB9L, 0x5C18E921228781ECL, 0xDF350057733EC2A7L
28 | }).toString(); /* => "de.schlichtherle.license.Resources" */
29 |
30 | private static final ResourceBundle resources
31 | = ResourceBundle.getBundle(CLASS_NAME);
32 |
33 | /**
34 | * Looks up a string resource identified by {@code key} in
35 | * {@code resources}.
36 | */
37 | public static String getString(String key) {
38 | return resources.getString(key);
39 | }
40 |
41 | /**
42 | * Looks up a string resource identified by {@code key} in
43 | * {@code resources} and formats it as a message using
44 | * {@code MessageFormat.format} with the given {@code arguments}.
45 | */
46 | public static String getString(String key, Object[] arguments) {
47 | return MessageFormat.format(getString(key), arguments);
48 | }
49 |
50 | /**
51 | * Looks up a string resource identified by {@code key} in
52 | * {@code resources} and formats it as a message using
53 | * {@code MessageFormat.format} with the given singular {@code argument}.
54 | */
55 | public static String getString(String key, Object argument) {
56 | return MessageFormat.format(getString(key), new Object[] { argument });
57 | }
58 |
59 | /** You cannot instantiate this class. */
60 | protected Resources() { }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/data-ingestion-demo-war/src/main/java/com/jason/example/model/Localized.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2015.02.03 at 03:41:20 PM CST
6 | //
7 |
8 |
9 | package com.jason.example.model;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 | import javax.xml.bind.annotation.XmlAccessType;
14 | import javax.xml.bind.annotation.XmlAccessorType;
15 | import javax.xml.bind.annotation.XmlElement;
16 | import javax.xml.bind.annotation.XmlType;
17 |
18 |
19 | /**
20 | * Java class for Localized complex type. 21 | * 22 | *
The following schema fragment specifies the expected content contained within this class. 23 | * 24 | *
25 | * <complexType name="Localized">
26 | * <complexContent>
27 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
28 | * <sequence>
29 | * <element name="lang" type="{http://www.example.org/DemoSchema}Lang" maxOccurs="unbounded" minOccurs="0"/>
30 | * </sequence>
31 | * </restriction>
32 | * </complexContent>
33 | * </complexType>
34 | *
35 | *
36 | *
37 | */
38 | @XmlAccessorType(XmlAccessType.FIELD)
39 | @XmlType(name = "Localized", propOrder = {
40 | "lang"
41 | })
42 | public class Localized {
43 |
44 | @XmlElement(nillable = true)
45 | protected List
51 | * This accessor method returns a reference to the live list,
52 | * not a snapshot. Therefore any modification you make to the
53 | * returned list will be present inside the JAXB object.
54 | * This is why there is not a set method for the lang property.
55 | *
56 | *
57 | * For example, to add a new item, do as follows: 58 | *
59 | * getLang().add(newItem); 60 | *61 | * 62 | * 63 | *
64 | * Objects of the following type(s) are allowed in the list
65 | * {@link Lang }
66 | *
67 | *
68 | */
69 | public List Java class for ObjectInfos complex type.
21 | *
22 | * The following schema fragment specifies the expected content contained within this class.
23 | *
24 | *
51 | * This accessor method returns a reference to the live list,
52 | * not a snapshot. Therefore any modification you make to the
53 | * returned list will be present inside the JAXB object.
54 | * This is why there is not a
57 | * For example, to add a new item, do as follows:
58 | *
64 | * Objects of the following type(s) are allowed in the list
65 | * {@link ObjectInfo }
66 | *
67 | *
68 | */
69 | public List An ObjectFactory allows you to programatically
22 | * construct new instances of the Java representation
23 | * for XML content. The Java representation of XML
24 | * content can consist of schema derived interfaces
25 | * and classes representing the binding of schema
26 | * type definitions, element declarations and model
27 | * groups. Factory methods for each of these are
28 | * provided in this class.
29 | *
30 | */
31 | @XmlRegistry
32 | public class ObjectFactory {
33 |
34 | private final static QName _Movie_QNAME = new QName("http://www.example.org/DemoSchema", "movie");
35 |
36 | /**
37 | * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.jason.example.model
38 | *
39 | */
40 | public ObjectFactory() {
41 | }
42 |
43 | /**
44 | * Create an instance of {@link Movie }
45 | *
46 | */
47 | public Movie createMovie() {
48 | return new Movie();
49 | }
50 |
51 | /**
52 | * Create an instance of {@link Lang }
53 | *
54 | */
55 | public Lang createLang() {
56 | return new Lang();
57 | }
58 |
59 | /**
60 | * Create an instance of {@link ObjectInfo }
61 | *
62 | */
63 | public ObjectInfo createObjectInfo() {
64 | return new ObjectInfo();
65 | }
66 |
67 | /**
68 | * Create an instance of {@link Localized }
69 | *
70 | */
71 | public Localized createLocalized() {
72 | return new Localized();
73 | }
74 |
75 | /**
76 | * Create an instance of {@link ObjectInfos }
77 | *
78 | */
79 | public ObjectInfos createObjectInfos() {
80 | return new ObjectInfos();
81 | }
82 |
83 | /**
84 | * Create an instance of {@link JAXBElement }{@code <}{@link Movie }{@code >}}
85 | *
86 | */
87 | @XmlElementDecl(namespace = "http://www.example.org/DemoSchema", name = "movie")
88 | public JAXBElement Java class for Lang complex type.
19 | *
20 | * The following schema fragment specifies the expected content contained within this class.
21 | *
22 | * Java class for ObjectInfo complex type.
19 | *
20 | * The following schema fragment specifies the expected content contained within this class.
21 | *
22 | *
49 | * This class is designed to be thread safe.
50 | *
51 | * @author Christian Schlichtherle
52 | */
53 | public class LocalLicenseManager extends zlicense.de.schlichtherle.license.LicenseManager {
54 | /** The timeout for the license content cache. */
55 | private static final long TIMEOUT = 30 * 60 * 1000; // half an hour
56 |
57 | /** The key in the preferences used to store the license key. */
58 | private static final String PREFERENCES_KEY
59 | = new ObfuscatedString(new long[] {
60 | 0xD65FA96737AE2CB5L, 0xE804D1A38CF9A413L
61 | }).toString(); /* => "license" */
62 |
63 | /**
64 | * The suffix for files which hold license certificates.
65 | */
66 | public static final String LICENSE_SUFFIX
67 | = new ObfuscatedString(new long[] {
68 | 0x97187B3A07E79CEEL, 0x469144B7E0D475E2L
69 | }).toString(); /* => ".lic" - must be lowercase! */
70 | static {
71 | assert LICENSE_SUFFIX.equals(LICENSE_SUFFIX.toLowerCase()); // paranoid
72 | }
73 |
74 | private static final String PARAM = LicenseNotary.PARAM;
75 |
76 | private static final String SUBJECT = new ObfuscatedString(new long[] {
77 | 0xA1CB7D9B4D5E81E4L, 0xD9500F23E58132B6L
78 | }).toString(); /* => "subject" */
79 |
80 | private static final String KEY_STORE_PARAM = new ObfuscatedString(new long[] {
81 | 0x449C8CDCBA1A80CEL, 0x6FEE3A101634D30BL, 0xD9D7B61A44A2606CL
82 | }).toString(); /* => "keyStoreParam" */
83 |
84 | private static final String CIPHER_PARAM = new ObfuscatedString(new long[] {
85 | 0xCD54DEE1845B54E4L, 0x1AC47C8C827054BCL, 0x16E53B3A590D62B6L
86 | }).toString(); /* => "cipherParam" */
87 |
88 | protected static final String CN = new ObfuscatedString(new long[] {
89 | 0x636F59E1FF007F64L, 0xAC9CE58690A43DD0L
90 | }).toString(); /* => "CN=" */
91 |
92 | private static final String CN_USER = CN + Resources.getString(
93 | new ObfuscatedString(new long[] {
94 | 0xF3BE4EA2CCDD7EADL, 0x5B6A9F59A1183108L
95 | }).toString()); /* => "user" */
96 |
97 | private static final String USER = new ObfuscatedString(new long[] {
98 | 0x9F89522C9F6F4A13L, 0xFFDB7A316241AC79L
99 | }).toString(); /* => "User" */
100 |
101 | private static final String SYSTEM = new ObfuscatedString(new long[] {
102 | 0xEC006BE1C1F75BD6L, 0x54D650CDD244774BL
103 | }).toString(); /* => "System" */
104 |
105 | private static final String EXC_INVALID_SUBJECT = new ObfuscatedString(new long[] {
106 | 0x8029CDF4E32A76ECL, 0x56FA623D9AEE8C1L, 0x99E7882A708663ACL,
107 | 0x5888C0D72E548FF4L
108 | }).toString(); /* => "exc.invalidSubject" */
109 |
110 | private static final String EXC_HOLDER_IS_NULL = new ObfuscatedString(new long[] {
111 | 0x6339FEFCDFD84427L, 0x57A2FA0735E47CBEL, 0xED1D06E6EED72950L
112 | }).toString(); /* => "exc.holderIsNull" */
113 |
114 | private static final String EXC_ISSUER_IS_NULL = new ObfuscatedString(new long[] {
115 | 0xD5E29AC879334756L, 0xF1F7421CD6A06536L, 0x5E086D6468FECBF2L
116 | }).toString(); /* => "exc.issuerIsNull" */
117 |
118 | private static final String EXC_ISSUED_IS_NULL = new ObfuscatedString(new long[] {
119 | 0xAB8FF89F2DA6C32CL, 0x2A089A9CA80D970EL, 0xCF15F8842FCCD9D5L
120 | }).toString(); /* => "exc.issuedIsNull" */
121 |
122 | private static final String EXC_LICENSE_IS_NOT_YET_VALID = new ObfuscatedString(new long[] {
123 | 0x4B6BB2804EE7DDB1L, 0xD0BB0A33A41543C5L, 0x5FCEC6DF3725CEE4L,
124 | 0xA165775BBD625344L
125 | }).toString(); /* => "exc.licenseIsNotYetValid" */
126 |
127 | private static final String EXC_LICENSE_HAS_EXPIRED = new ObfuscatedString(new long[] {
128 | 0xDE2B2A7ACD6DA6DL, 0x9EE12DDECB3D4C0DL, 0xB3CF760B522E8688L,
129 | 0x316BD3E92C17CC40L
130 | }).toString(); /* => "exc.licenseHasExpired" */
131 |
132 | private static final String EXC_CONSUMER_TYPE_IS_NULL = new ObfuscatedString(new long[] {
133 | 0xD29019F7B1D95C66L, 0xE859C44ACC3EB2FEL, 0xF041027C9003B031L,
134 | 0x27E84AD8870D6063L
135 | }).toString(); /* => "exc.consumerTypeIsNull" */
136 |
137 | private static final String EXC_CONSUMER_TYPE_IS_NOT_USER = new ObfuscatedString(new long[] {
138 | 0xCE99D49CE98D1E47L, 0x7A3BA300A7DFCEABL, 0x2D2E4B624AD7C4E0L,
139 | 0x2C86A28A075E71C6L, 0x79BCB920E5FB351DL
140 | }).toString(); /* => "exc.consumerTypeIsNotUser" */
141 |
142 | private static final String EXC_CONSUMER_AMOUNT_IS_NOT_ONE = new ObfuscatedString(new long[] {
143 | 0x5F20CBB98126BB0AL, 0xE8BB696B25D24011L, 0x435CC3AA7263BAE7L,
144 | 0x9DA3066F501717E4L, 0x62FFA4899FBBA3F8L
145 | }).toString(); /* => "exc.consumerAmountIsNotOne" */
146 |
147 | private static final String EXC_CONSUMER_AMOUNT_IS_NOT_POSITIVE = new ObfuscatedString(new long[] {
148 | 0xB14EB6259B4D7249L, 0xCD02F577511528D8L, 0x39B8CF1E258756DDL,
149 | 0x67488F05891DF916L, 0x4256DE0CFFF62DCAL
150 | }).toString(); /* => "exc.consumerAmountIsNotPositive" */
151 |
152 | private static final String FILE_FILTER_DESCRIPTION = new ObfuscatedString(new long[] {
153 | 0x2BDDE408C7B71604L, 0xDFCA7DA8912DE4C1L, 0xADA1FC1C1D5F1047L,
154 | 0xD08EAA6CCDC342F3L
155 | }).toString(); /* => "fileFilter.description" */
156 |
157 | private static final String FILE_FILTER_SUFFIX = new ObfuscatedString(new long[] {
158 | 0xA4BCC907D9FD1290L, 0x614A0A9015D3D8DDL
159 | }).toString(); /* => " (*.lic)" */
160 |
161 | /**
162 | * Returns midnight local time today.
163 | */
164 |
165 | private LicenseParam param; // initialized by setLicenseParam() - should be accessed via getLicenseParam() only!
166 |
167 | //
168 | // Data computed and cached from the license configuration parameters.
169 | //
170 |
171 | private LicenseNotary notary; // lazy initialized
172 |
173 | private PrivacyGuard guard; // lazy initialized
174 |
175 | /** The cached certificate of the current license key. */
176 | private GenericCertificate certificate; // lazy initialized
177 |
178 | /** The time when the certificate was last set. */
179 | private long certificateTime; // lazy initialized
180 |
181 | /** A suitable file filter for the subject of this license manager. */
182 | private FileFilter fileFilter; // lazy initialized
183 |
184 | /** The preferences node used to store the license key. */
185 | private Preferences preferences; // lazy initialized
186 | public LocalLicenseManager() throws URISyntaxException {
187 | super();
188 | // TODO Auto-generated constructor stub
189 | }
190 | public LocalLicenseManager(LicenseParam param)
191 | throws NullPointerException,
192 | IllegalPasswordException {
193 | setLicenseParam(param);
194 | }
195 | /**
196 | *
197 | */
198 | private static final long serialVersionUID = 1L;
199 |
200 | protected synchronized void validate(final LicenseContent content)
201 | throws LicenseContentException {
202 | final LicenseParam param = getLicenseParam();
203 | if (!param.getSubject().equals(content.getSubject()))
204 | throw new LicenseContentException(EXC_INVALID_SUBJECT);
205 | if (content.getHolder() == null)
206 | throw new LicenseContentException(EXC_HOLDER_IS_NULL);
207 | if (content.getIssuer() == null)
208 | throw new LicenseContentException(EXC_ISSUER_IS_NULL);
209 | if (content.getIssued() == null)
210 | throw new LicenseContentException(EXC_ISSUED_IS_NULL);
211 | final Date now = new Date();
212 | final Date notBefore = content.getNotBefore();
213 | if (notBefore != null && now.before(notBefore))
214 | throw new LicenseContentException(EXC_LICENSE_IS_NOT_YET_VALID);
215 | final Date notAfter = content.getNotAfter();
216 | // if (notAfter != null && now.after(notAfter))
217 | // throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);
218 | final String consumerType = content.getConsumerType();
219 | if (consumerType == null)
220 | throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NULL);
221 | final Preferences prefs = param.getPreferences();
222 | if (prefs != null && prefs.isUserNode()) {
223 | if (!USER.equalsIgnoreCase(consumerType))
224 | throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NOT_USER);
225 | if (content.getConsumerAmount() != 1)
226 | throw new LicenseContentException(EXC_CONSUMER_AMOUNT_IS_NOT_ONE);
227 | } else {
228 | if (content.getConsumerAmount() <= 0)
229 | throw new LicenseContentException(EXC_CONSUMER_AMOUNT_IS_NOT_POSITIVE);
230 | }
231 | }
232 | }
233 |
--------------------------------------------------------------------------------
/java-license-jar/src/main/java/zlicense/de/schlichtherle/xml/GenericCertificate.java:
--------------------------------------------------------------------------------
1 | package zlicense.de.schlichtherle.xml;
2 |
3 | import java.beans.PropertyChangeEvent;
4 | import java.beans.PropertyChangeListener;
5 | import java.beans.PropertyChangeSupport;
6 | import java.beans.PropertyVetoException;
7 | import java.beans.VetoableChangeListener;
8 | import java.beans.VetoableChangeSupport;
9 | import java.io.Serializable;
10 | import java.io.UnsupportedEncodingException;
11 | import java.security.InvalidKeyException;
12 | import java.security.PrivateKey;
13 | import java.security.PublicKey;
14 | import java.security.Signature;
15 | import java.security.SignatureException;
16 | import org.apache.commons.codec.binary.Base64;
17 |
18 | public final class GenericCertificate
19 | implements Serializable, XMLConstants
20 | {
21 | private static final String BASE64_CHARSET = "US-ASCII";
22 | private static final String SIGNATURE_ENCODING = "US-ASCII/Base64";
23 | private transient boolean locked;
24 | private String encoded;
25 | private String signature;
26 | private String signatureAlgorithm;
27 | private String signatureEncoding;
28 | private transient PropertyChangeSupport propertyChangeSupport;
29 | private transient VetoableChangeSupport vetoableChangeSupport;
30 |
31 | public GenericCertificate() {}
32 |
33 | public GenericCertificate(GenericCertificate paramGenericCertificate)
34 | {
35 | try
36 | {
37 | setEncoded(paramGenericCertificate.getEncoded());
38 | setSignature(paramGenericCertificate.getSignature());
39 | setSignatureAlgorithm(paramGenericCertificate.getSignatureAlgorithm());
40 | setSignatureEncoding(paramGenericCertificate.getSignatureEncoding());
41 | }
42 | catch (PropertyVetoException localPropertyVetoException)
43 | {
44 | throw new AssertionError(localPropertyVetoException);
45 | }
46 | }
47 |
48 | public final synchronized void sign(Object paramObject, PrivateKey paramPrivateKey, Signature paramSignature)
49 | throws NullPointerException, GenericCertificateIsLockedException, PropertyVetoException, PersistenceServiceException, InvalidKeyException
50 | {
51 | if (paramPrivateKey == null) {
52 | throw new NullPointerException("signingKey");
53 | }
54 | if (paramSignature == null) {
55 | throw new NullPointerException("signingEngine");
56 | }
57 | PropertyChangeEvent localPropertyChangeEvent = new PropertyChangeEvent(this, "locked", Boolean.valueOf(isLocked()), Boolean.TRUE);
58 | if (isLocked()) {
59 | throw new GenericCertificateIsLockedException(localPropertyChangeEvent);
60 | }
61 | fireVetoableChange(localPropertyChangeEvent);
62 | try
63 | {
64 | byte[] arrayOfByte1 = PersistenceService.store2ByteArray(paramObject);
65 | paramSignature.initSign(paramPrivateKey);
66 | paramSignature.update(arrayOfByte1);
67 | byte[] arrayOfByte2 = Base64.encodeBase64(paramSignature.sign());
68 | String str = new String(arrayOfByte2, 0, arrayOfByte2.length, "US-ASCII");
69 | setEncoded(new String(arrayOfByte1, "UTF-8"));
70 | setSignature(str);
71 | setSignatureAlgorithm(paramSignature.getAlgorithm());
72 | setSignatureEncoding("US-ASCII/Base64");
73 | }
74 | catch (UnsupportedEncodingException localUnsupportedEncodingException)
75 | {
76 | throw new AssertionError(localUnsupportedEncodingException);
77 | }
78 | catch (SignatureException localSignatureException)
79 | {
80 | throw new AssertionError(localSignatureException);
81 | }
82 | this.locked = true;
83 | firePropertyChange(localPropertyChangeEvent);
84 | }
85 |
86 | public final synchronized void verify(PublicKey paramPublicKey, Signature paramSignature)
87 | throws NullPointerException, GenericCertificateIsLockedException, PropertyVetoException, InvalidKeyException, SignatureException, GenericCertificateIntegrityException
88 | {
89 | if (paramPublicKey == null) {
90 | throw new NullPointerException("verificationKey");
91 | }
92 | if (paramSignature == null) {
93 | throw new NullPointerException("verificationEngine");
94 | }
95 | PropertyChangeEvent localPropertyChangeEvent = new PropertyChangeEvent(this, "locked", Boolean.valueOf(isLocked()), Boolean.TRUE);
96 | if (isLocked()) {
97 | throw new GenericCertificateIsLockedException(localPropertyChangeEvent);
98 | }
99 | fireVetoableChange(localPropertyChangeEvent);
100 | try
101 | {
102 | byte[] arrayOfByte1 = getEncoded().getBytes("UTF-8");
103 | paramSignature.initVerify(paramPublicKey);
104 | paramSignature.update(arrayOfByte1);
105 | byte[] arrayOfByte2 = Base64.decodeBase64(getSignature().getBytes("US-ASCII"));
106 | if (!paramSignature.verify(arrayOfByte2)) {
107 | throw new GenericCertificateIntegrityException();
108 | }
109 | setSignatureAlgorithm(paramSignature.getAlgorithm());
110 | setSignatureEncoding("US-ASCII/Base64");
111 | }
112 | catch (UnsupportedEncodingException localUnsupportedEncodingException)
113 | {
114 | throw new AssertionError(localUnsupportedEncodingException);
115 | }
116 | this.locked = true;
117 | firePropertyChange(localPropertyChangeEvent);
118 | }
119 |
120 | public final boolean isLocked()
121 | {
122 | return this.locked;
123 | }
124 |
125 | public Object getContent()
126 | throws GenericCertificateNotLockedException, PersistenceServiceException
127 | {
128 | if (!isLocked()) {
129 | throw new GenericCertificateNotLockedException();
130 | }
131 | return PersistenceService.load(getEncoded());
132 | }
133 |
134 | public final String getEncoded()
135 | {
136 | return this.encoded;
137 | }
138 |
139 | public synchronized void setEncoded(String paramString)
140 | throws GenericCertificateIsLockedException
141 | {
142 | if (paramString == null)
143 | {
144 | if (this.encoded != null) {}
145 | }
146 | else if (paramString.equals(this.encoded)) {
147 | return;
148 | }
149 | PropertyChangeEvent localPropertyChangeEvent = new PropertyChangeEvent(this, "encoded", getEncoded(), paramString);
150 | if (isLocked()) {
151 | throw new GenericCertificateIsLockedException(localPropertyChangeEvent);
152 | }
153 | this.encoded = paramString;
154 | firePropertyChange(localPropertyChangeEvent);
155 | }
156 |
157 | public final String getSignature()
158 | {
159 | return this.signature;
160 | }
161 |
162 | public synchronized void setSignature(String paramString)
163 | throws GenericCertificateIsLockedException
164 | {
165 | if (paramString == null)
166 | {
167 | if (this.signature != null) {}
168 | }
169 | else if (paramString.equals(this.signature)) {
170 | return;
171 | }
172 | PropertyChangeEvent localPropertyChangeEvent = new PropertyChangeEvent(this, "signature", getSignature(), paramString);
173 | if (isLocked()) {
174 | throw new GenericCertificateIsLockedException(localPropertyChangeEvent);
175 | }
176 | this.signature = paramString;
177 | firePropertyChange(localPropertyChangeEvent);
178 | }
179 |
180 | public final String getSignatureAlgorithm()
181 | {
182 | return this.signatureAlgorithm;
183 | }
184 |
185 | public synchronized void setSignatureAlgorithm(String paramString)
186 | throws GenericCertificateIsLockedException
187 | {
188 | if (paramString == null)
189 | {
190 | if (this.signatureAlgorithm != null) {}
191 | }
192 | else if (paramString.equals(this.signatureAlgorithm)) {
193 | return;
194 | }
195 | PropertyChangeEvent localPropertyChangeEvent = new PropertyChangeEvent(this, "signatureAlgorithm", getSignatureAlgorithm(), paramString);
196 | if (isLocked()) {
197 | throw new GenericCertificateIsLockedException(localPropertyChangeEvent);
198 | }
199 | this.signatureAlgorithm = paramString;
200 | firePropertyChange(localPropertyChangeEvent);
201 | }
202 |
203 | public final String getSignatureEncoding()
204 | {
205 | return this.signatureEncoding;
206 | }
207 |
208 | /**
209 | * @deprecated
210 | */
211 | public synchronized void setSignatureEncoding(String paramString)
212 | throws GenericCertificateIsLockedException
213 | {
214 | if (paramString == null)
215 | {
216 | if (this.signatureEncoding != null) {}
217 | }
218 | else if (paramString.equals(this.signatureEncoding)) {
219 | return;
220 | }
221 | PropertyChangeEvent localPropertyChangeEvent = new PropertyChangeEvent(this, "signatureEncoding", getSignatureEncoding(), paramString);
222 | if (isLocked()) {
223 | throw new GenericCertificateIsLockedException(localPropertyChangeEvent);
224 | }
225 | this.signatureEncoding = paramString;
226 | firePropertyChange(localPropertyChangeEvent);
227 | }
228 |
229 | public final synchronized void addVetoableChangeListener(VetoableChangeListener paramVetoableChangeListener)
230 | {
231 | if (this.vetoableChangeSupport == null) {
232 | this.vetoableChangeSupport = new VetoableChangeSupport(this);
233 | }
234 | this.vetoableChangeSupport.addVetoableChangeListener(paramVetoableChangeListener);
235 | }
236 |
237 | public final void removeVetoableChangeListener(VetoableChangeListener paramVetoableChangeListener)
238 | {
239 | if (this.vetoableChangeSupport == null) {
240 | return;
241 | }
242 | this.vetoableChangeSupport.removeVetoableChangeListener(paramVetoableChangeListener);
243 | }
244 |
245 | protected final void fireVetoableChange(PropertyChangeEvent paramPropertyChangeEvent)
246 | throws PropertyVetoException
247 | {
248 | if (this.vetoableChangeSupport == null) {
249 | return;
250 | }
251 | this.vetoableChangeSupport.fireVetoableChange(paramPropertyChangeEvent);
252 | }
253 |
254 | public final synchronized void addPropertyChangeListener(PropertyChangeListener paramPropertyChangeListener)
255 | {
256 | if (this.propertyChangeSupport == null) {
257 | this.propertyChangeSupport = new PropertyChangeSupport(this);
258 | }
259 | this.propertyChangeSupport.addPropertyChangeListener(paramPropertyChangeListener);
260 | }
261 |
262 | public final void removePropertyChangeListener(PropertyChangeListener paramPropertyChangeListener)
263 | {
264 | if (this.propertyChangeSupport == null) {
265 | return;
266 | }
267 | this.propertyChangeSupport.removePropertyChangeListener(paramPropertyChangeListener);
268 | }
269 |
270 | protected final void firePropertyChange(PropertyChangeEvent paramPropertyChangeEvent)
271 | {
272 | if (this.propertyChangeSupport == null) {
273 | return;
274 | }
275 | this.propertyChangeSupport.firePropertyChange(paramPropertyChangeEvent);
276 | }
277 | }
278 |
--------------------------------------------------------------------------------
/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/PrivacyGuard.java.bak:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2005-2012 Schlichtherle IT Services
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * which accompanies this distribution, and is available at
7 | * http://www.eclipse.org/legal/epl-v10.html
8 | */
9 | package de.schlichtherle.license;
10 |
11 | import de.schlichtherle.util.ObfuscatedString;
12 | import de.schlichtherle.xml.GenericCertificate;
13 | import de.schlichtherle.xml.PersistenceService;
14 | import de.schlichtherle.xml.PersistenceServiceException;
15 | import java.io.ByteArrayInputStream;
16 | import java.io.ByteArrayOutputStream;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.io.OutputStream;
20 | import java.security.InvalidAlgorithmParameterException;
21 | import java.security.InvalidKeyException;
22 | import java.security.NoSuchAlgorithmException;
23 | import java.security.spec.AlgorithmParameterSpec;
24 | import java.security.spec.InvalidKeySpecException;
25 | import java.security.spec.KeySpec;
26 | import java.util.zip.GZIPInputStream;
27 | import java.util.zip.GZIPOutputStream;
28 | import javax.crypto.Cipher;
29 | import javax.crypto.CipherOutputStream;
30 | import javax.crypto.NoSuchPaddingException;
31 | import javax.crypto.SecretKey;
32 | import javax.crypto.SecretKeyFactory;
33 | import javax.crypto.spec.PBEKeySpec;
34 | import javax.crypto.spec.PBEParameterSpec;
35 |
36 | /**
37 | * This class provides encoding and encryption services to provide long time
38 | * persistence for {@link GenericCertificate}s and protect the privacy of its
39 | * data.
40 | *
41 | * This class is not thread safe.
42 | *
43 | * @author Christian Schlichtherle
44 | * @version $Id$
45 | */
46 | public class PrivacyGuard {
47 |
48 | private static final String PBE_WITH_MD5_AND_DES = new ObfuscatedString(new long[] {
49 | 0x27B2E8783E47F1ABL, 0x45CF8AD4390DC9D8L, 0xAB320350966BC9BFL
50 | }).toString(); /* => "PBEWithMD5AndDES" */
51 |
52 | private CipherParam param; // initialized by setCipherParam() - should be accessed via getCipherParam() only!
53 |
54 | //
55 | // Data computed and cached from the cipher configuration parameters.
56 | //
57 |
58 | private Cipher cipher;
59 | private SecretKey key;
60 | private AlgorithmParameterSpec algoParamSpec;
61 |
62 | /**
63 | * Creates a new Privacy Guard.
64 | *
65 | * Warning: The guard created by this constructor is not
66 | * valid and cannot be used unless {@link #setCipherParam(CipherParam)}
67 | * is called!
68 | */
69 | protected PrivacyGuard() {
70 | }
71 |
72 | /**
73 | * Creates a new Privacy Guard.
74 | *
75 | * @param param The cipher configuration parameters
76 | * - may not be {@code null}.
77 | */
78 | public PrivacyGuard(CipherParam param) {
79 | setCipherParam0(param);
80 | }
81 |
82 | /**
83 | * Returns the cipher configuration parameters.
84 | */
85 | public CipherParam getCipherParam() {
86 | return param;
87 | }
88 |
89 | /**
90 | * Sets the cipher configuration parameters.
91 | * Calling this method resets the guard as if it had been
92 | * newly created.
93 | * Some plausibility checks are applied to the given parameter object
94 | * to ensure that it adheres to the contract of the parameter interfaces.
95 | *
96 | * @param param the cipher configuration parameters
97 | * - may not be {@code null}.
98 | * @throws NullPointerException if the given parameter object does not
99 | * obey the contract of its interface due to a {@code null}
100 | * pointer.
101 | * @throws IllegalPasswordException if any password in the parameter object
102 | * does not comply to the current policy.
103 | */
104 | public void setCipherParam(CipherParam param) {
105 | setCipherParam0(param);
106 | }
107 |
108 | private void setCipherParam0(CipherParam param) {
109 | // Check parameters to implement fail-fast behaviour.
110 | if (param == null)
111 | throw new NullPointerException(LicenseNotary.PARAM);
112 | Policy.getCurrent().checkPwd(param.getKeyPwd());
113 |
114 | this.param = param;
115 | cipher = null;
116 | key = null;
117 | algoParamSpec = null;
118 | }
119 |
120 | /**
121 | * Encodes, compresses and encrypts the given license certificate
122 | * and returns the result as a license key.
123 | * Please note that this method does not sign the certificate.
124 | *
125 | * @param certificate The license certificate
126 | * - may not be {@code null}.
127 | *
128 | * @return The license key
129 | * - {@code null} is never returned.
130 | *
131 | * @throws Exception An instance of a subclass of this class for various
132 | * reasons.
133 | * Note that you should always use
134 | * {@link Throwable#getLocalizedMessage()} to get a (possibly
135 | * localized) meaningful detail message.
136 | */
137 | public byte[] cert2key(final GenericCertificate certificate)
138 | throws Exception {
139 | // Encode the certificate and store it to a file.
140 | final ByteArrayOutputStream keyOut = new ByteArrayOutputStream();
141 | final OutputStream out = new GZIPOutputStream(
142 | new CipherOutputStream(
143 | keyOut,
144 | getCipher4Encryption()));
145 | try {
146 | PersistenceService.store(certificate, out);
147 | }
148 | catch (PersistenceServiceException cannotHappen) {
149 | throw new AssertionError(cannotHappen);
150 | }
151 | return keyOut.toByteArray();
152 | }
153 |
154 | /**
155 | * Decrypts, decompresses and decodes the given license key
156 | * and returns the result as a license certificate.
157 | * Please note that this method does not verify the certificate.
158 | *
159 | * @param key The license key to process
160 | * - may not be {@code null}.
161 | *
162 | * @return The license certificate
163 | * - {@code null} is never returned.
164 | *
165 | * @throws Exception An instance of a subclass of this class for various
166 | * reasons.
167 | * Note that you should always use
168 | * {@link Throwable#getLocalizedMessage()} to get a (possibly
169 | * localized) meaningful detail message.
170 | */
171 | public GenericCertificate key2cert(final byte[] key)
172 | throws Exception {
173 | final InputStream in = new GZIPInputStream(
174 | new ByteArrayInputStream(
175 | getCipher4Decryption().doFinal(key)));
176 | final GenericCertificate certificate;
177 | try {
178 | certificate = (GenericCertificate) PersistenceService.load(in);
179 | }
180 | finally {
181 | try { in.close(); }
182 | catch (IOException weDontCare) { }
183 | }
184 | return certificate;
185 | }
186 |
187 | /**
188 | * Returns a cipher object which is initialised for encryption
189 | * - {@code null} is never returned.
190 | *
191 | * @deprecated Experimental: Methods marked with this note have
192 | * been tested to be functional but may change or disappear
193 | * at will in one of the next releases because they are still
194 | * a topic for research on extended functionality.
195 | * Most likely the methods will prevail however and this note
196 | * will just vanish, so you may use them with a certain risk.
197 | */
198 | protected Cipher getCipher4Encryption() {
199 | Cipher cipher = getCipher();
200 | try {
201 | cipher.init(Cipher.ENCRYPT_MODE, key, algoParamSpec);
202 | }
203 | catch (InvalidKeyException cannotHappen) {
204 | throw new AssertionError(cannotHappen);
205 | }
206 | catch (InvalidAlgorithmParameterException cannotHappen) {
207 | throw new AssertionError(cannotHappen);
208 | }
209 |
210 | return cipher;
211 | }
212 |
213 | /**
214 | * Returns a cipher object which is initialised for decryption
215 | * - {@code null} is never returned.
216 | *
217 | * @deprecated Experimental: Methods marked with this note have
218 | * been tested to be functional but may change or disappear
219 | * at will in one of the next releases because they are still
220 | * a topic for research on extended functionality.
221 | * Most likely the methods will prevail however and this note
222 | * will just vanish, so you may use them with a certain risk.
223 | */
224 | protected Cipher getCipher4Decryption() {
225 | Cipher cipher = getCipher();
226 | try {
227 | cipher.init(Cipher.DECRYPT_MODE, key, algoParamSpec);
228 | }
229 | catch (InvalidKeyException cannotHappen) {
230 | throw new AssertionError(cannotHappen);
231 | }
232 | catch (InvalidAlgorithmParameterException cannotHappen) {
233 | throw new AssertionError(cannotHappen);
234 | }
235 |
236 | return cipher;
237 | }
238 |
239 | /**
240 | * Returns a cipher object which needs to be configured for encryption or
241 | * decryption
242 | * - {@code null} is never returned.
243 | *
244 | * @deprecated Experimental: Methods marked with this note have
245 | * been tested to be functional but may change or disappear
246 | * at will in one of the next releases because they are still
247 | * a topic for research on extended functionality.
248 | * Most likely the methods will prevail however and this note
249 | * will just vanish, so you may use them with a certain risk.
250 | */
251 | protected Cipher getCipher() {
252 | if (cipher != null)
253 | return cipher;
254 | algoParamSpec = new PBEParameterSpec(
255 | new byte[] {
256 | (byte)0xce, (byte)0xfb, (byte)0xde, (byte)0xac,
257 | (byte)0x05, (byte)0x02, (byte)0x19, (byte)0x71
258 | },
259 | 2005);
260 | try {
261 | KeySpec keySpec = new PBEKeySpec(getCipherParam().getKeyPwd().toCharArray());
262 | SecretKeyFactory keyFac = SecretKeyFactory.getInstance(PBE_WITH_MD5_AND_DES);
263 | key = keyFac.generateSecret(keySpec);
264 | cipher = Cipher.getInstance(PBE_WITH_MD5_AND_DES);
265 | } catch (NoSuchAlgorithmException cannotHappen) {
266 | throw new AssertionError(cannotHappen);
267 | } catch (InvalidKeySpecException cannotHappen) {
268 | throw new AssertionError(cannotHappen);
269 | } catch (NoSuchPaddingException cannotHappen) {
270 | throw new AssertionError(cannotHappen);
271 | }
272 | return cipher;
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/java-license-jar/src/main/java/zlicense/de/schlichtherle/license/LicenseManager.java:
--------------------------------------------------------------------------------
1 | package zlicense.de.schlichtherle.license;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.OutputStream;
9 | import java.net.SocketException;
10 | import java.util.Calendar;
11 | import java.util.Date;
12 | import java.util.prefs.Preferences;
13 |
14 | import javax.security.auth.x500.X500Principal;
15 | import javax.swing.filechooser.FileFilter;
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | import zlicense.de.schlichtherle.util.ObfuscatedString;
26 | import zlicense.de.schlichtherle.xml.GenericCertificate;
27 | import zlicense.util.LicenseCheckModel;
28 | import zlicense.util.ListNets;
29 |
30 |
31 |
32 | public class LicenseManager implements LicenseCreator, LicenseVerifier {
33 | private static final long TIMEOUT = 1800000L;
34 | private static final String PREFERENCES_KEY;
35 | public static final String LICENSE_SUFFIX;
36 | private static final String PARAM = LicenseNotary.PARAM;
37 | private static final String SUBJECT = new ObfuscatedString(new long[] {
38 | -6788193907359448604L, -2787711522493615434L }).toString();
39 | private static final String KEY_STORE_PARAM = new ObfuscatedString(
40 | new long[] { 4943981370588954830L, 8065447823433585419L,
41 | -2749528823549501332L }).toString();
42 | private static final String CIPHER_PARAM = new ObfuscatedString(new long[] {
43 | -3651048337721043740L, 1928803483347080380L, 1649789960289346230L })
44 | .toString();
45 | protected static final String CN = new ObfuscatedString(new long[] {
46 | 7165044359350484836L, -6008675436704023088L }).toString();
47 | private static final String CN_USER = CN
48 | + new ObfuscatedString(new long[] { -883182015789302099L,
49 | 6587252612286394632L }).toString();
50 | private static final String USER = new ObfuscatedString(new long[] {
51 | -6950934198262740461L, -10280221617836935L }).toString();
52 | private static final String SYSTEM = new ObfuscatedString(new long[] {
53 | -1441033263392531498L, 6113162389128247115L }).toString();
54 | private static final String EXC_INVALID_SUBJECT = new ObfuscatedString(
55 | new long[] { -9211605111142713620L, 391714365510707393L,
56 | -7356761750428556372L, 6379560902598103028L }).toString();
57 | private static final String EXC_HOLDER_IS_NULL = new ObfuscatedString(
58 | new long[] { 7150026245468079143L, 6314884536402738366L,
59 | -1360923923476698800L }).toString();
60 | private static final String EXC_ISSUER_IS_NULL = new ObfuscatedString(
61 | new long[] { -3034693013076752554L, -1011266899694033610L,
62 | 6775785917404597234L }).toString();
63 | private static final String EXC_ISSUED_IS_NULL = new ObfuscatedString(
64 | new long[] { -6084371209004858580L, 3028840747031697166L,
65 | -3524637886726219307L }).toString();
66 | private static final String EXC_LICENSE_IS_NOT_YET_VALID = new ObfuscatedString(
67 | new long[] { 5434633639502011825L, -3406117476263181371L,
68 | 6903673940810780388L, -6816911225052310716L }).toString();
69 | private static final String EXC_LICENSE_HAS_EXPIRED = new ObfuscatedString(
70 | new long[] { 1000558500458715757L, -6998261911041258483L,
71 | -5490039629745846648L, 3561172928787106880L }).toString();
72 | private static final String EXC_CONSUMER_TYPE_IS_NULL = new ObfuscatedString(
73 | new long[] { -3274088377466921882L, -1704115158449736962L,
74 | -1134622897105293263L, 2875630655915253859L }).toString();
75 | private static final String EXC_CONSUMER_TYPE_IS_NOT_USER = new ObfuscatedString(
76 | new long[] { -3559580260061340089L, 8807812719464926891L,
77 | 3255622466169980128L, 3208430498260873670L,
78 | 8772089725159421213L }).toString();
79 | private static final String EXC_CONSUMER_AMOUNT_IS_NOT_ONE = new ObfuscatedString(
80 | new long[] { 6854702630454082314L, -1676630527348424687L,
81 | 4853969635229547239L, -7087814313396201500L,
82 | 7133601245775504376L }).toString();
83 | private static final String EXC_CONSUMER_AMOUNT_IS_NOT_POSITIVE = new ObfuscatedString(
84 | new long[] { -5670394608177286583L, -3674104453170648872L,
85 | 4159301984262248157L, 7442355638167795990L,
86 | 4780252201915657674L }).toString();
87 | private static final String FILE_FILTER_DESCRIPTION = new ObfuscatedString(
88 | new long[] { 3160933239845492228L, -2320904495012387647L,
89 | -5935185636215549881L, -3418607682842311949L }).toString();
90 | private static final String FILE_FILTER_SUFFIX = new ObfuscatedString(
91 | new long[] { -6576160320308571504L, 7010427383913371869L })
92 | .toString();
93 | private LicenseParam param;
94 | private LicenseNotary notary;
95 | private PrivacyGuard guard;
96 | private GenericCertificate certificate;
97 | private long certificateTime;
98 | private FileFilter fileFilter;
99 | private Preferences preferences;
100 |
101 | protected static final Date midnight() {
102 | Calendar localCalendar = Calendar.getInstance();
103 | localCalendar.set(11, 0);
104 | localCalendar.set(12, 0);
105 | localCalendar.set(13, 0);
106 | localCalendar.set(14, 0);
107 | return localCalendar.getTime();
108 | }
109 |
110 | protected LicenseManager() {
111 | }
112 |
113 | public LicenseManager(LicenseParam paramLicenseParam)
114 | throws NullPointerException, IllegalPasswordException {
115 | setLicenseParam(paramLicenseParam);
116 | }
117 |
118 | public LicenseParam getLicenseParam() {
119 | return this.param;
120 | }
121 |
122 | public synchronized void setLicenseParam(LicenseParam paramLicenseParam)
123 | throws NullPointerException, IllegalPasswordException {
124 | if (paramLicenseParam == null) {
125 | throw new NullPointerException(PARAM);
126 | }
127 | if (paramLicenseParam.getSubject() == null) {
128 | throw new NullPointerException(SUBJECT);
129 | }
130 | if (paramLicenseParam.getKeyStoreParam() == null) {
131 | throw new NullPointerException(KEY_STORE_PARAM);
132 | }
133 | CipherParam localCipherParam = paramLicenseParam.getCipherParam();
134 | if (localCipherParam == null) {
135 | throw new NullPointerException(CIPHER_PARAM);
136 | }
137 | Policy.getCurrent().checkPwd(localCipherParam.getKeyPwd());
138 | this.param = paramLicenseParam;
139 | this.notary = null;
140 | this.certificate = null;
141 | this.certificateTime = 0L;
142 | this.fileFilter = null;
143 | this.preferences = null;
144 | }
145 |
146 | public final synchronized void store(LicenseContent paramLicenseContent,
147 | File paramFile) throws Exception {
148 | store(paramLicenseContent, getLicenseNotary(), paramFile);
149 | }
150 |
151 | /**
152 | * @deprecated
153 | */
154 | protected synchronized void store(LicenseContent paramLicenseContent,
155 | LicenseNotary paramLicenseNotary, File paramFile) throws Exception {
156 | storeLicenseKey(create(paramLicenseContent, paramLicenseNotary),
157 | paramFile);
158 | }
159 |
160 | public final synchronized byte[] create(LicenseContent paramLicenseContent)
161 | throws Exception {
162 | return create(paramLicenseContent, getLicenseNotary());
163 | }
164 |
165 | /**
166 | * @deprecated
167 | */
168 | protected synchronized byte[] create(LicenseContent paramLicenseContent,
169 | LicenseNotary paramLicenseNotary) throws Exception {
170 | initialize(paramLicenseContent);
171 | create_validate(paramLicenseContent);
172 | GenericCertificate localGenericCertificate = paramLicenseNotary
173 | .sign(paramLicenseContent);
174 | byte[] arrayOfByte = getPrivacyGuard()
175 | .cert2key(localGenericCertificate);
176 | return arrayOfByte;
177 | }
178 |
179 | public final synchronized LicenseContent install(File paramFile)
180 | throws Exception {
181 | return install(paramFile, getLicenseNotary());
182 | }
183 |
184 | /**
185 | * @deprecated
186 | */
187 | protected synchronized LicenseContent install(File paramFile,
188 | LicenseNotary paramLicenseNotary) throws Exception {
189 | return install(loadLicenseKey(paramFile), paramLicenseNotary);
190 | }
191 |
192 | /**
193 | * @deprecated
194 | */
195 | protected synchronized LicenseContent install(byte[] paramArrayOfByte,
196 | LicenseNotary paramLicenseNotary) throws Exception {
197 | GenericCertificate localGenericCertificate = getPrivacyGuard()
198 | .key2cert(paramArrayOfByte);
199 | paramLicenseNotary.verify(localGenericCertificate);
200 | LicenseContent localLicenseContent = (LicenseContent) localGenericCertificate
201 | .getContent();
202 | validate(localLicenseContent);
203 | setLicenseKey(paramArrayOfByte);
204 | setCertificate(localGenericCertificate);
205 | return localLicenseContent;
206 | }
207 |
208 | public final synchronized LicenseContent verify() throws Exception {
209 | return verify(getLicenseNotary());
210 | }
211 |
212 | /**
213 | * @deprecated
214 | */
215 | protected synchronized LicenseContent verify(
216 | LicenseNotary paramLicenseNotary) throws Exception {
217 | GenericCertificate localGenericCertificate = getCertificate();
218 | if (localGenericCertificate != null) {
219 | return (LicenseContent) localGenericCertificate.getContent();
220 | }
221 | byte[] arrayOfByte = getLicenseKey();
222 | if (arrayOfByte == null) {
223 | throw new NoLicenseInstalledException(getLicenseParam()
224 | .getSubject());
225 | }
226 | localGenericCertificate = getPrivacyGuard().key2cert(arrayOfByte);
227 | paramLicenseNotary.verify(localGenericCertificate);
228 | LicenseContent localLicenseContent = (LicenseContent) localGenericCertificate
229 | .getContent();
230 | validate(localLicenseContent);
231 | setCertificate(localGenericCertificate);
232 | return localLicenseContent;
233 | }
234 |
235 | public final synchronized LicenseContent verify(byte[] paramArrayOfByte)
236 | throws Exception {
237 | return verify(paramArrayOfByte, getLicenseNotary());
238 | }
239 |
240 | /**
241 | * @deprecated
242 | */
243 | protected synchronized LicenseContent verify(byte[] paramArrayOfByte,
244 | LicenseNotary paramLicenseNotary) throws Exception {
245 | GenericCertificate localGenericCertificate = getPrivacyGuard()
246 | .key2cert(paramArrayOfByte);
247 | paramLicenseNotary.verify(localGenericCertificate);
248 | LicenseContent localLicenseContent = (LicenseContent) localGenericCertificate
249 | .getContent();
250 | validate(localLicenseContent);
251 | return localLicenseContent;
252 | }
253 |
254 | public synchronized void uninstall() throws Exception {
255 | setLicenseKey(null);
256 | setCertificate(null);
257 | }
258 |
259 | protected synchronized void initialize(LicenseContent paramLicenseContent) {
260 | if (paramLicenseContent.getHolder() == null) {
261 | paramLicenseContent.setHolder(new X500Principal(CN_USER));
262 | }
263 | if (paramLicenseContent.getSubject() == null) {
264 | paramLicenseContent.setSubject(getLicenseParam().getSubject());
265 | }
266 | if (paramLicenseContent.getConsumerType() == null) {
267 | Preferences localPreferences = getLicenseParam().getPreferences();
268 | if (localPreferences != null) {
269 | if (localPreferences.isUserNode()) {
270 | paramLicenseContent.setConsumerType(USER);
271 | } else {
272 | paramLicenseContent.setConsumerType(SYSTEM);
273 | }
274 | paramLicenseContent.setConsumerAmount(1);
275 | }
276 | }
277 | if (paramLicenseContent.getIssuer() == null) {
278 | paramLicenseContent.setIssuer(new X500Principal(CN
279 | + getLicenseParam().getSubject()));
280 | }
281 | if (paramLicenseContent.getIssued() == null) {
282 | paramLicenseContent.setIssued(new Date());
283 | }
284 | if (paramLicenseContent.getNotBefore() == null) {
285 | paramLicenseContent.setNotBefore(midnight());
286 | }
287 | }
288 |
289 |
290 | protected synchronized void create_validate(LicenseContent paramLicenseContent)
291 | throws LicenseContentException {
292 | LicenseParam localLicenseParam = getLicenseParam();
293 | if (!localLicenseParam.getSubject().equals(
294 | paramLicenseContent.getSubject())) {
295 | throw new LicenseContentException(EXC_INVALID_SUBJECT);
296 | }
297 | if (paramLicenseContent.getHolder() == null) {
298 | throw new LicenseContentException(EXC_HOLDER_IS_NULL);
299 | }
300 | if (paramLicenseContent.getIssuer() == null) {
301 | throw new LicenseContentException(EXC_ISSUER_IS_NULL);
302 | }
303 | if (paramLicenseContent.getIssued() == null) {
304 | throw new LicenseContentException(EXC_ISSUED_IS_NULL);
305 | }
306 | Date localDate1 = new Date();
307 | Date localDate2 = paramLicenseContent.getNotBefore();
308 | if ((localDate2 != null) && (localDate1.before(localDate2))) {
309 | throw new LicenseContentException(EXC_LICENSE_IS_NOT_YET_VALID);
310 | }
311 | Date localDate3 = paramLicenseContent.getNotAfter();
312 | if ((localDate3 != null) && (localDate1.after(localDate3))) {
313 | throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);
314 | }
315 |
316 | String str = paramLicenseContent.getConsumerType();
317 | if (str == null) {
318 | throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NULL);
319 | }
320 | Preferences localPreferences = localLicenseParam.getPreferences();
321 | if ((localPreferences != null) && (localPreferences.isUserNode())) {
322 | if (!USER.equalsIgnoreCase(str)) {
323 | throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NOT_USER);
324 | }
325 | if (paramLicenseContent.getConsumerAmount() != 1) {
326 | throw new LicenseContentException(
327 | EXC_CONSUMER_AMOUNT_IS_NOT_ONE);
328 | }
329 | } else if (paramLicenseContent.getConsumerAmount() <= 0) {
330 | throw new LicenseContentException(
331 | EXC_CONSUMER_AMOUNT_IS_NOT_POSITIVE);
332 | }
333 | }
334 |
335 | protected synchronized void validate(LicenseContent paramLicenseContent)
336 | throws LicenseContentException {
337 | LicenseParam localLicenseParam = getLicenseParam();
338 | if (!localLicenseParam.getSubject().equals(
339 | paramLicenseContent.getSubject())) {
340 | throw new LicenseContentException(EXC_INVALID_SUBJECT);
341 | }
342 | if (paramLicenseContent.getHolder() == null) {
343 | throw new LicenseContentException(EXC_HOLDER_IS_NULL);
344 | }
345 | if (paramLicenseContent.getIssuer() == null) {
346 | throw new LicenseContentException(EXC_ISSUER_IS_NULL);
347 | }
348 | if (paramLicenseContent.getIssued() == null) {
349 | throw new LicenseContentException(EXC_ISSUED_IS_NULL);
350 | }
351 | Date localDate1 = new Date();
352 | Date localDate2 = paramLicenseContent.getNotBefore();
353 | if ((localDate2 != null) && (localDate1.before(localDate2))) {
354 | throw new LicenseContentException(EXC_LICENSE_IS_NOT_YET_VALID);
355 | }
356 | Date localDate3 = paramLicenseContent.getNotAfter();
357 | if ((localDate3 != null) && (localDate1.after(localDate3))) {
358 | throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);
359 | }
360 |
361 | LicenseCheckModel licenseCheckModel = (LicenseCheckModel)paramLicenseContent.getExtra();
362 | String macAddress = licenseCheckModel.getIpMacAddress();
363 |
364 | try {
365 | if (!ListNets.validateMacAddress(macAddress)) {
366 | throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);
367 | }
368 | } catch (SocketException e) {
369 | // TODO Auto-generated catch block
370 | throw new LicenseContentException(EXC_LICENSE_HAS_EXPIRED);
371 | }
372 |
373 |
374 | String str = paramLicenseContent.getConsumerType();
375 | if (str == null) {
376 | throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NULL);
377 | }
378 | Preferences localPreferences = localLicenseParam.getPreferences();
379 | if ((localPreferences != null) && (localPreferences.isUserNode())) {
380 | if (!USER.equalsIgnoreCase(str)) {
381 | throw new LicenseContentException(EXC_CONSUMER_TYPE_IS_NOT_USER);
382 | }
383 | if (paramLicenseContent.getConsumerAmount() != 1) {
384 | throw new LicenseContentException(
385 | EXC_CONSUMER_AMOUNT_IS_NOT_ONE);
386 | }
387 | } else if (paramLicenseContent.getConsumerAmount() <= 0) {
388 | throw new LicenseContentException(
389 | EXC_CONSUMER_AMOUNT_IS_NOT_POSITIVE);
390 | }
391 | }
392 |
393 | /**
394 | * @deprecated
395 | */
396 | protected GenericCertificate getCertificate() {
397 | if ((this.certificate != null)
398 | && (System.currentTimeMillis() < this.certificateTime + 1800000L)) {
399 | return this.certificate;
400 | }
401 | return null;
402 | }
403 |
404 | /**
405 | * @deprecated
406 | */
407 | protected synchronized void setCertificate(
408 | GenericCertificate paramGenericCertificate) {
409 | this.certificate = paramGenericCertificate;
410 | this.certificateTime = System.currentTimeMillis();
411 | }
412 |
413 | /**
414 | * @deprecated
415 | */
416 | protected byte[] getLicenseKey() {
417 | return getLicenseParam().getPreferences().getByteArray(PREFERENCES_KEY,
418 | null);
419 | }
420 |
421 | /**
422 | * @deprecated
423 | */
424 | protected synchronized void setLicenseKey(byte[] paramArrayOfByte) {
425 | Preferences localPreferences = getLicenseParam().getPreferences();
426 | if (paramArrayOfByte != null) {
427 | localPreferences.putByteArray(PREFERENCES_KEY, paramArrayOfByte);
428 | } else {
429 | localPreferences.remove(PREFERENCES_KEY);
430 | }
431 | }
432 |
433 | protected static void storeLicenseKey(byte[] paramArrayOfByte,
434 | File paramFile) throws IOException {
435 | FileOutputStream localFileOutputStream = new FileOutputStream(paramFile);
436 | try {
437 | localFileOutputStream.write(paramArrayOfByte);
438 | return;
439 | } finally {
440 | try {
441 | localFileOutputStream.close();
442 | } catch (IOException localIOException2) {
443 | }
444 | }
445 | }
446 |
447 | /*
448 | * protected static byte[] loadLicenseKey(File paramFile) throws IOException
449 | * { int i = Math.min((int)paramFile.length(), 1048576); FileInputStream
450 | * localFileInputStream = new FileInputStream(paramFile); arrayOfByte = new
451 | * byte[i]; try { localFileInputStream.read(arrayOfByte); return
452 | * arrayOfByte; } finally { try { localFileInputStream.close(); } catch
453 | * (IOException localIOException2) {} } }
454 | */
455 |
456 | protected static byte[] loadLicenseKey(final File keyFile)
457 | throws IOException {
458 | // Allow max 1MB size files and let the verifier detect a partial read
459 | final int size = Math.min((int) keyFile.length(), 1024 * 1024);
460 | final byte[] b = new byte[size];
461 | final InputStream in = new FileInputStream(keyFile);
462 | try {
463 | // Let the verifier detect a partial read as an error
464 | in.read(b);
465 | } finally {
466 | in.close();
467 | }
468 | return b;
469 | }
470 |
471 | protected synchronized LicenseNotary getLicenseNotary() {
472 | if (this.notary == null) {
473 | this.notary = new LicenseNotary(getLicenseParam()
474 | .getKeyStoreParam());
475 | }
476 | return this.notary;
477 | }
478 |
479 | protected synchronized PrivacyGuard getPrivacyGuard() {
480 | if (this.guard == null) {
481 | this.guard = new PrivacyGuard(getLicenseParam().getCipherParam());
482 | }
483 | return this.guard;
484 | }
485 |
486 | /*
487 | * public synchronized FileFilter getFileFilter() { if (this.fileFilter !=
488 | * null) { return this.fileFilter; } final String str =
489 | * Resources.getString(FILE_FILTER_DESCRIPTION,
490 | * getLicenseParam().getSubject()); if (File.separatorChar == '\\') {
491 | * this.fileFilter = new FileFilter() { private final String
492 | * val$description;
493 | *
494 | * public boolean accept(File paramAnonymousFile) { return
495 | * (paramAnonymousFile.isDirectory()) ||
496 | * (paramAnonymousFile.getPath().toLowerCase
497 | * ().endsWith(LicenseManager.LICENSE_SUFFIX)); }
498 | *
499 | * public String getDescription() { return str +
500 | * LicenseManager.FILE_FILTER_SUFFIX; } }; } else { this.fileFilter = new
501 | * FileFilter() { private final String val$description;
502 | *
503 | * public boolean accept(File paramAnonymousFile) { return
504 | * (paramAnonymousFile.isDirectory()) ||
505 | * (paramAnonymousFile.getPath().endsWith(LicenseManager.LICENSE_SUFFIX)); }
506 | *
507 | * public String getDescription() { return str +
508 | * LicenseManager.FILE_FILTER_SUFFIX; } }; } return this.fileFilter; }
509 | */
510 |
511 | public synchronized FileFilter getFileFilter() {
512 | if (fileFilter != null)
513 | return fileFilter;
514 | final String description = Resources.getString(FILE_FILTER_DESCRIPTION,
515 | getLicenseParam().getSubject());
516 | if (File.separatorChar == '\\') {
517 | fileFilter = new FileFilter() {
518 | public boolean accept(File f) {
519 | return f.isDirectory()
520 | || f.getPath().toLowerCase()
521 | .endsWith(LICENSE_SUFFIX);
522 | }
523 |
524 | public String getDescription() {
525 | return description + FILE_FILTER_SUFFIX;
526 | }
527 | };
528 | } else {
529 | fileFilter = new FileFilter() {
530 | public boolean accept(File f) {
531 | return f.isDirectory()
532 | || f.getPath().endsWith(LICENSE_SUFFIX);
533 | }
534 |
535 | public String getDescription() {
536 | return description + FILE_FILTER_SUFFIX;
537 | }
538 | };
539 | }
540 | return fileFilter;
541 | }
542 |
543 | static {
544 | PREFERENCES_KEY = new ObfuscatedString(new long[] {
545 | -2999492566024573771L, -1728025856628382701L }).toString();
546 | LICENSE_SUFFIX = new ObfuscatedString(new long[] {
547 | -7559156485370438418L, 5084921010819724770L }).toString();
548 | assert (LICENSE_SUFFIX.equals(LICENSE_SUFFIX.toLowerCase()));
549 | }
550 | }
551 |
--------------------------------------------------------------------------------
25 | * <complexType name="ObjectInfos">
26 | * <complexContent>
27 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
28 | * <sequence>
29 | * <element name="object-info" type="{http://www.example.org/DemoSchema}ObjectInfo" maxOccurs="unbounded" minOccurs="0"/>
30 | * </sequence>
31 | * </restriction>
32 | * </complexContent>
33 | * </complexType>
34 | *
35 | *
36 | *
37 | */
38 | @XmlAccessorType(XmlAccessType.FIELD)
39 | @XmlType(name = "ObjectInfos", propOrder = {
40 | "objectInfo"
41 | })
42 | public class ObjectInfos {
43 |
44 | @XmlElement(name = "object-info")
45 | protected Listset method for the objectInfo property.
55 | *
56 | *
59 | * getObjectInfo().add(newItem);
60 | *
61 | *
62 | *
63 | *
23 | * <complexType name="Lang">
24 | * <complexContent>
25 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26 | * <sequence>
27 | * <element name="code" type="{http://www.w3.org/2001/XMLSchema}string"/>
28 | * <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
29 | * <element name="attribute" type="{http://www.w3.org/2001/XMLSchema}string"/>
30 | * <element name="description" type="{http://www.w3.org/2001/XMLSchema}string"/>
31 | * </sequence>
32 | * </restriction>
33 | * </complexContent>
34 | * </complexType>
35 | *
36 | *
37 | *
38 | */
39 | @XmlAccessorType(XmlAccessType.FIELD)
40 | @XmlType(name = "Lang", propOrder = {
41 | "code",
42 | "name",
43 | "attribute",
44 | "description"
45 | })
46 | public class Lang {
47 |
48 | @XmlElement(required = true)
49 | protected String code;
50 | @XmlElement(required = true, nillable = true)
51 | protected String name;
52 | @XmlElement(required = true, nillable = true)
53 | protected String attribute;
54 | @XmlElement(required = true, nillable = true)
55 | protected String description;
56 |
57 | /**
58 | * Gets the value of the code property.
59 | *
60 | * @return
61 | * possible object is
62 | * {@link String }
63 | *
64 | */
65 | public String getCode() {
66 | return code;
67 | }
68 |
69 | /**
70 | * Sets the value of the code property.
71 | *
72 | * @param value
73 | * allowed object is
74 | * {@link String }
75 | *
76 | */
77 | public void setCode(String value) {
78 | this.code = value;
79 | }
80 |
81 | /**
82 | * Gets the value of the name property.
83 | *
84 | * @return
85 | * possible object is
86 | * {@link String }
87 | *
88 | */
89 | public String getName() {
90 | return name;
91 | }
92 |
93 | /**
94 | * Sets the value of the name property.
95 | *
96 | * @param value
97 | * allowed object is
98 | * {@link String }
99 | *
100 | */
101 | public void setName(String value) {
102 | this.name = value;
103 | }
104 |
105 | /**
106 | * Gets the value of the attribute property.
107 | *
108 | * @return
109 | * possible object is
110 | * {@link String }
111 | *
112 | */
113 | public String getAttribute() {
114 | return attribute;
115 | }
116 |
117 | /**
118 | * Sets the value of the attribute property.
119 | *
120 | * @param value
121 | * allowed object is
122 | * {@link String }
123 | *
124 | */
125 | public void setAttribute(String value) {
126 | this.attribute = value;
127 | }
128 |
129 | /**
130 | * Gets the value of the description property.
131 | *
132 | * @return
133 | * possible object is
134 | * {@link String }
135 | *
136 | */
137 | public String getDescription() {
138 | return description;
139 | }
140 |
141 | /**
142 | * Sets the value of the description property.
143 | *
144 | * @param value
145 | * allowed object is
146 | * {@link String }
147 | *
148 | */
149 | public void setDescription(String value) {
150 | this.description = value;
151 | }
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/data-ingestion-demo-war/src/main/java/com/jason/example/model/ObjectInfo.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2
3 | // See http://java.sun.com/xml/jaxb
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2015.02.03 at 03:41:20 PM CST
6 | //
7 |
8 |
9 | package com.jason.example.model;
10 |
11 | import javax.xml.bind.annotation.XmlAccessType;
12 | import javax.xml.bind.annotation.XmlAccessorType;
13 | import javax.xml.bind.annotation.XmlElement;
14 | import javax.xml.bind.annotation.XmlType;
15 |
16 |
17 | /**
18 | *
23 | * <complexType name="ObjectInfo">
24 | * <complexContent>
25 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26 | * <sequence>
27 | * <element name="id" type="{http://www.w3.org/2001/XMLSchema}string"/>
28 | * <element name="image-url" type="{http://www.w3.org/2001/XMLSchema}string"/>
29 | * <element name="priority" type="{http://www.w3.org/2001/XMLSchema}int"/>
30 | * <element name="localized" type="{http://www.example.org/DemoSchema}Localized"/>
31 | * </sequence>
32 | * </restriction>
33 | * </complexContent>
34 | * </complexType>
35 | *
36 | *
37 | *
38 | */
39 | @XmlAccessorType(XmlAccessType.FIELD)
40 | @XmlType(name = "ObjectInfo", propOrder = {
41 | "id",
42 | "imageUrl",
43 | "priority",
44 | "localized"
45 | })
46 | public class ObjectInfo {
47 |
48 | @XmlElement(required = true)
49 | protected String id;
50 | @XmlElement(name = "image-url", required = true, nillable = true)
51 | protected String imageUrl;
52 | @XmlElement(required = true, type = Integer.class, nillable = true)
53 | protected Integer priority;
54 | @XmlElement(required = true, nillable = true)
55 | protected Localized localized;
56 |
57 | /**
58 | * Gets the value of the id property.
59 | *
60 | * @return
61 | * possible object is
62 | * {@link String }
63 | *
64 | */
65 | public String getId() {
66 | return id;
67 | }
68 |
69 | /**
70 | * Sets the value of the id property.
71 | *
72 | * @param value
73 | * allowed object is
74 | * {@link String }
75 | *
76 | */
77 | public void setId(String value) {
78 | this.id = value;
79 | }
80 |
81 | /**
82 | * Gets the value of the imageUrl property.
83 | *
84 | * @return
85 | * possible object is
86 | * {@link String }
87 | *
88 | */
89 | public String getImageUrl() {
90 | return imageUrl;
91 | }
92 |
93 | /**
94 | * Sets the value of the imageUrl property.
95 | *
96 | * @param value
97 | * allowed object is
98 | * {@link String }
99 | *
100 | */
101 | public void setImageUrl(String value) {
102 | this.imageUrl = value;
103 | }
104 |
105 | /**
106 | * Gets the value of the priority property.
107 | *
108 | * @return
109 | * possible object is
110 | * {@link Integer }
111 | *
112 | */
113 | public Integer getPriority() {
114 | return priority;
115 | }
116 |
117 | /**
118 | * Sets the value of the priority property.
119 | *
120 | * @param value
121 | * allowed object is
122 | * {@link Integer }
123 | *
124 | */
125 | public void setPriority(Integer value) {
126 | this.priority = value;
127 | }
128 |
129 | /**
130 | * Gets the value of the localized property.
131 | *
132 | * @return
133 | * possible object is
134 | * {@link Localized }
135 | *
136 | */
137 | public Localized getLocalized() {
138 | return localized;
139 | }
140 |
141 | /**
142 | * Sets the value of the localized property.
143 | *
144 | * @param value
145 | * allowed object is
146 | * {@link Localized }
147 | *
148 | */
149 | public void setLocalized(Localized value) {
150 | this.localized = value;
151 | }
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/data-ingestion-demo-war/pom.xml:
--------------------------------------------------------------------------------
1 |