<commit_before>/*
 * Copyright (C) 2005-2015 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */

package net.java.truelicense.core;

import net.java.truelicense.core.auth.Authentication;
import net.java.truelicense.core.crypto.Encryption;
import net.java.truelicense.core.io.Source;
import net.java.truelicense.core.io.Store;
import net.java.truelicense.core.util.Builder;
import net.java.truelicense.core.util.Injection;
import net.java.truelicense.obfuscate.Obfuscate;
import net.java.truelicense.obfuscate.ObfuscatedString;

import javax.annotation.CheckForNull;
import java.io.File;

/**
 * A derived context for license consumer applications.
 * Use this context to configure a {@link LicenseConsumerManager} with the
 * required parameters.
 * For a demonstration of this API, please use the TrueLicense Maven Archetype
 * to generate a sample project - even if you don't use Maven to build your
 * software product.
 * <p>
 * Applications have no need to implement this interface and should not do so
 * because it may be subject to expansion in future versions.
 *
 * @author <NAME>
 */
public interface LicenseConsumerContext
extends LicenseApplicationContext {

    /**
     * Configures a license consumer manager
     * for use with regular license keys.
     * <p>
     * The returned manager assumes that it has exclusive access to the given
     * store and can use it to
     * {@linkplain LicenseConsumerManager#install install} and
     * {@linkplain LicenseConsumerManager#uninstall uninstall} a license key.
     *
     * @param  authentication the authentication for regular license keys.
     * @param  encryption the encryption.
     * @param  store the store for the regular license key.
     * @return A license consumer manager for use with regular license keys.
     * @throws IllegalArgumentException if the authentication parameters define
     *         a private key password.
     */
    LicenseConsumerManager manager(Authentication authentication, Encryption encryption, Store store);

    /**
     * Configures a license consumer manager
     * for use with auto-generated free trial period (FTP) license keys.
     * <p>
     * The returned manager assumes that it has exclusive access to the given
     * secret store and can use it to automatically install an FTP license key
     * when calling {@link LicenseConsumerManager#verify} or
     * {@link LicenseConsumerManager#view}.
     * Calls to the methods {@link LicenseConsumerManager#install} and
     * {@link LicenseConsumerManager#uninstall} get forwarded to the parent
     * manager.
     * <p>
     * <strong>
     * NOTE THAT THE SECRET STORE MUST BE HIDDEN OR OTHERWISE PROTECTED SO THAT
     * USERS CANNOT JUST DELETE THE INSTALLED LICENSE KEY TO MAKE THEM ELIGIBLE
     * FOR A NEW FTP AGAIN!
     * </strong>
     *
     * @param  parent the parent manager.
     * @param  authentication the authentication for FTP license keys.
     *         This has to be created with {@link #ftpKeyStore}.
     * @param  encryption the nullable encryption.
     *         If this is {@code null}, then it will get inherited from the
     *         parent manager.
     * @param  secret the secret store for the FTP license key.
     * @param  days the FTP in days (the 24 hour equivalent).
     *         A minimum of one day is required.
     * @return A license consumer manager for use with FTP license keys.
     * @throws IllegalArgumentException if the authentication parameters define
     *         no private key password or if the FTP is less than one day.
     */
    LicenseConsumerManager ftpManager(LicenseConsumerManager parent, Authentication authentication, @CheckForNull Encryption encryption, Store secret, int days);

    /**
     * Configures a chained license consumer manager
     * for use with regular license keys.
     * Use this method to unlock application features based on the purchased
     * license key.
     * For best results, the two managers need to have different authentication
     * parameters.
     * The returned manager should then get used to verify acces to a sub set
     * of the features which are controlled by the parent manager.
     * <p>
     * The returned manager assumes that it has exclusive access to the given
     * store and can use it to
     * {@linkplain LicenseConsumerManager#install install} and
     * {@linkplain LicenseConsumerManager#uninstall uninstall} a license key.
     * <p>
     * All life cycle methods first try to use the parent manager.
     * If this fails for any reason then they try to use the returned manager.
     *
     * @param  parent the parent manager.
     * @param  authentication the authentication for regular license keys.
     * @param  encryption the encryption.
     *         If this is {@code null}, then it will get inherited from the
     *         parent manager.
     * @param  store the secret store for the FTP license key.
     * @return A license consumer manager for use with FTP license keys.
     * @throws IllegalArgumentException if the authentication parameters define
     *         a private key password.
     */
    LicenseConsumerManager chainedManager(LicenseConsumerManager parent, Authentication authentication, @CheckForNull Encryption encryption, Store store);

    /**
     * Configures a key store based authentication
     * for use with regular license keys.
     * <p>
     * The provided strings should be computed on demand from an obfuscated
     * form, e.g. by annotating a constant string value with the
     * &#64;{@link Obfuscate} annotation and processing it with the TrueLicense
     * Maven Plugin.
     *
     * @param source the nullable source for the key store.
     *        May be {@code null} if and only if the key store type does not
     *        require loading from an input stream.
     * @param storeType the nullable type of the key store,
     *                  e.g. {@code "JCEKS"} or {@code "JKS"}.
     *                  If this is {@code null}, then the value computed by the
     *                  expression
     *                  <code>{@link #context()}.{@link LicenseManagementContext#storeType() storeType()}</code>
     *                  is used instead.
     *                  Otherwise, you need to make sure that the store type is
     *                  supported by a security provider on all platforms - see
     *                  <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html">Java Cryptography Architeture Sun Providers Documentation</a>.
     * @param storePassword the password for verifying the integrity of the
     *                      key store.
     * @param alias the alias of the trusted certificate entry in the key
     *        store.
     * @return A key store based authentication
     *         for use with regular license keys.
     */
    Authentication keyStore(@CheckForNull Source source, @CheckForNull String storeType, ObfuscatedString storePassword, String alias);

    /**
     * Configures a key store based authentication
     * for use with auto-generated free trial period (FTP) license keys.
     * <p>
     * The provided strings should be computed on demand from an obfuscated
     * form, e.g. by annotating a constant string value with the
     * &#64;{@link Obfuscate} annotation and processing it with the TrueLicense
     * Maven Plugin.
     *
     * @param source the nullable source for the key store.
     *               May be {@code null} if and only if the key store type
     *               does not require loading from an input stream.
     * @param storeType the nullable type of the key store,
     *                  e.g. {@code "JCEKS"} or {@code "JKS"}.
     *                  If this is {@code null}, then the value computed by
     *                  the expression
     *                  <code>{@link #context()}.{@link LicenseManagementContext#storeType() storeType()}</code>
     *                  is used instead.
     *                  Otherwise, you need to make sure that the store type
     *                  is supported by a security provider on all platforms -
     *                  see
     *                  <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html">Java Cryptography Architeture Sun Providers Documentation</a>.
     * @param storePassword the password for verifying the integrity of the
     *                      key store.
     * @param alias the alias of the private key entry in the key store.
     * @param keyPassword the nullable password for accessing the private key
     *                    in the key entry.
     *                    If this is {@code null} or empty, then the
     *                    {@code storePassword} is used instead.
     * @return A key store based authentication
     *         for use with FTP license keys.
     * @throws IllegalArgumentException if a password is considered to be too
     *         weak.
     */
    Authentication ftpKeyStore(@CheckForNull Source source, @CheckForNull String storeType, ObfuscatedString storePassword, String alias, @CheckForNull ObfuscatedString keyPassword);

    /**
     * Returns a builder for a
     * {@linkplain LicenseConsumerManager license consumer manager}.
     * Call its {@link ManagerBuilder#build} method to obtain a configured
     * license consumer manager.
     */
    ManagerBuilder manager();

    /**
     * A builder for
     * {@linkplain LicenseConsumerManager license consumer managers}.<commit_msg>Resolves #TRUELICENSE-131 .<commit_after>/*
 * Copyright (C) 2005-2015 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */

package net.java.truelicense.core;

import net.java.truelicense.core.auth.Authentication;
import net.java.truelicense.core.crypto.Encryption;
import net.java.truelicense.core.io.Source;
import net.java.truelicense.core.io.Store;
import net.java.truelicense.core.util.Builder;
import net.java.truelicense.core.util.Injection;
import net.java.truelicense.obfuscate.Obfuscate;
import net.java.truelicense.obfuscate.ObfuscatedString;

import javax.annotation.CheckForNull;
import java.io.File;

/**
 * A derived context for license consumer applications.
 * Use this context to configure a {@link LicenseConsumerManager} with the
 * required parameters.
 * For a demonstration of this API, please use the TrueLicense Maven Archetype
 * to generate a sample project - even if you don't use Maven to build your
 * software product.
 * <p>
 * Applications have no need to implement this interface and should not do so
 * because it may be subject to expansion in future versions.
 *
 * @author <NAME>
 */
public interface LicenseConsumerContext
extends LicenseApplicationContext {

    /**
     * Configures a license consumer manager
     * for use with regular license keys.
     * <p>
     * The returned manager assumes that it has exclusive access to the given
     * store and can use it to
     * {@linkplain LicenseConsumerManager#install install} and
     * {@linkplain LicenseConsumerManager#uninstall uninstall} a license key.
     *
     * @param  authentication the authentication for regular license keys.
     * @param  encryption the encryption.
     * @param  store the store for the regular license key.
     * @return A license consumer manager for use with regular license keys.
     * @throws IllegalArgumentException if the authentication parameters define
     *         a private key password.
     * @deprecated since TrueLicense 2.5.0.
     *             This method will be removed from the public API in
     *             TrueLicense 3.0.0.
     */
    @Deprecated
    LicenseConsumerManager manager(Authentication authentication, Encryption encryption, Store store);

    /**
     * Configures a license consumer manager
     * for use with auto-generated free trial period (FTP) license keys.
     * <p>
     * The returned manager assumes that it has exclusive access to the given
     * secret store and can use it to automatically install an FTP license key
     * when calling {@link LicenseConsumerManager#verify} or
     * {@link LicenseConsumerManager#view}.
     * Calls to the methods {@link LicenseConsumerManager#install} and
     * {@link LicenseConsumerManager#uninstall} get forwarded to the parent
     * manager.
     * <p>
     * <strong>
     * NOTE THAT THE SECRET STORE MUST BE HIDDEN OR OTHERWISE PROTECTED SO THAT
     * USERS CANNOT JUST DELETE THE INSTALLED LICENSE KEY TO MAKE THEM ELIGIBLE
     * FOR A NEW FTP AGAIN!
     * </strong>
     *
     * @param  parent the parent manager.
     * @param  authentication the authentication for FTP license keys.
     *         This has to be created with {@link #ftpKeyStore}.
     * @param  encryption the nullable encryption.
     *         If this is {@code null}, then it will get inherited from the
     *         parent manager.
     * @param  secret the secret store for the FTP license key.
     * @param  days the FTP in days (the 24 hour equivalent).
     *         A minimum of one day is required.
     * @return A license consumer manager for use with FTP license keys.
     * @throws IllegalArgumentException if the authentication parameters define
     *         no private key password or if the FTP is less than one day.
     * @deprecated since TrueLicense 2.5.0.
     *             This method will be removed from the public API in
     *             TrueLicense 3.0.0.
     */
    @Deprecated
    LicenseConsumerManager ftpManager(LicenseConsumerManager parent, Authentication authentication, @CheckForNull Encryption encryption, Store secret, int days);

    /**
     * Configures a chained license consumer manager
     * for use with regular license keys.
     * Use this method to unlock application features based on the purchased
     * license key.
     * For best results, the two managers need to have different authentication
     * parameters.
     * The returned manager should then get used to verify acces to a sub set
     * of the features which are controlled by the parent manager.
     * <p>
     * The returned manager assumes that it has exclusive access to the given
     * store and can use it to
     * {@linkplain LicenseConsumerManager#install install} and
     * {@linkplain LicenseConsumerManager#uninstall uninstall} a license key.
     * <p>
     * All life cycle methods first try to use the parent manager.
     * If this fails for any reason then they try to use the returned manager.
     *
     * @param  parent the parent manager.
     * @param  authentication the authentication for regular license keys.
     * @param  encryption the encryption.
     *         If this is {@code null}, then it will get inherited from the
     *         parent manager.
     * @param  store the secret store for the FTP license key.
     * @return A license consumer manager for use with FTP license keys.
     * @throws IllegalArgumentException if the authentication parameters define
     *         a private key password.
     * @deprecated since TrueLicense 2.5.0.
     *             This method will be removed from the public API in
     *             TrueLicense 3.0.0.
     */
    @Deprecated
    LicenseConsumerManager chainedManager(LicenseConsumerManager parent, Authentication authentication, @CheckForNull Encryption encryption, Store store);

    /**
     * Configures a key store based authentication
     * for use with regular license keys.
     * <p>
     * The provided strings should be computed on demand from an obfuscated
     * form, e.g. by annotating a constant string value with the
     * &#64;{@link Obfuscate} annotation and processing it with the TrueLicense
     * Maven Plugin.
     *
     * @param source the nullable source for the key store.
     *        May be {@code null} if and only if the key store type does not
     *        require loading from an input stream.
     * @param storeType the nullable type of the key store,
     *                  e.g. {@code "JCEKS"} or {@code "JKS"}.
     *                  If this is {@code null}, then the value computed by the
     *                  expression
     *                  <code>{@link #context()}.{@link LicenseManagementContext#storeType() storeType()}</code>
     *                  is used instead.
     *                  Otherwise, you need to make sure that the store type is
     *                  supported by a security provider on all platforms - see
     *                  <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html">Java Cryptography Architeture Sun Providers Documentation</a>.
     * @param storePassword the password for verifying the integrity of the
     *                      key store.
     * @param alias the alias of the trusted certificate entry in the key
     *        store.
     * @return A key store based authentication
     *         for use with regular license keys.
     * @deprecated since TrueLicense 2.5.0.
     *             This method will be removed from the public API in
     *             TrueLicense 3.0.0.
     */
    @Deprecated
    Authentication keyStore(@CheckForNull Source source, @CheckForNull String storeType, ObfuscatedString storePassword, String alias);

    /**
     * Configures a key store based authentication
     * for use with auto-generated free trial period (FTP) license keys.
     * <p>
     * The provided strings should be computed on demand from an obfuscated
     * form, e.g. by annotating a constant string value with the
     * &#64;{@link Obfuscate} annotation and processing it with the TrueLicense
     * Maven Plugin.
     *
     * @param source the nullable source for the key store.
     *               May be {@code null} if and only if the key store type
     *               does not require loading from an input stream.
     * @param storeType the nullable type of the key store,
     *                  e.g. {@code "JCEKS"} or {@code "JKS"}.
     *                  If this is {@code null}, then the value computed by
     *                  the expression
     *                  <code>{@link #context()}.{@link LicenseManagementContext#storeType() storeType()}</code>
     *                  is used instead.
     *                  Otherwise, you need to make sure that the store type
     *                  is supported by a security provider on all platforms -
     *                  see
     *                  <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/SunProviders.html">Java Cryptography Architeture Sun Providers Documentation</a>.
     * @param storePassword the password for verifying the integrity of the
     *                      key store.
     * @param alias the alias of the private key entry in the key store.
     * @param keyPassword the nullable password for accessing the private key
     *                    in the key entry.
     *                    If this is {@code null} or empty, then the
     *                    {@code storePassword} is used instead.
     * @return A key store based authentication
     *         for use with FTP license keys.
     * @throws IllegalArgumentException if a password is considered to be too
     *         weak.
     * @deprecated since TrueLicense 2.5.0.
     *             This method will be removed from the public API in
     *             TrueLicense 3.0.0.
     */
    @Deprecated
    Authentication ftpKeyStore(@CheckForNull Source source, @CheckForNull String storeType, ObfuscatedString storePassword, String alias, @CheckForNull ObfuscatedString keyPassword);

    /**
     * Returns a builder for a
     * {@linkplain LicenseConsumerManager license consumer manager}.
     * Call its {@link ManagerBuilder#build} method to obtain a configured
     * license consumer manager.
     */
    ManagerBuilder manager();

    /**
     * A builder for
     * {@linkplain LicenseConsumerManager license consumer managers}.
{'fraction_non_alphanumeric': 0.06613466334164589, 'fraction_numerical': 0.0032418952618453864, 'mean_word_length': 2.4847062912756344, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '683573', 'n_tokens_mistral': 5017, 'n_tokens_neox': 4896, 'n_words': 2178}