All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.java.truelicense.core.BasicLicenseInitialization Maven / Gradle / Ivy

Go to download

The TrueLicense Core module provides essential functionality for license management.

There is a newer version: 2.6.6
Show newest version
/*
 * Copyright (C) 2005-2013 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */
package net.java.truelicense.core;

import java.util.Date;
import javax.annotation.concurrent.Immutable;
import javax.security.auth.x500.X500Principal;
import static net.java.truelicense.core.Messages.*;
import net.java.truelicense.core.util.*;
import net.java.truelicense.obfuscate.Obfuscate;

/**
 * A basic license initialization.
 * 

* Note that this class is immutable. * Unless stated otherwise, all no-argument methods need to return consistent * objects so that caching them is not required. * A returned object is considered to be consistent if it compares * {@linkplain Object#equals(Object) equal} or at least behaves identical to * any previously returned object. * * @author Christian Schlichtherle */ @Immutable final class BasicLicenseInitialization implements LicenseInitialization, LicenseSubjectProvider, Clock { @Obfuscate private static final String DEFAULT_CONSUMER_TYPE = "User"; /** The canonical name prefix for X.500 principals. */ @Obfuscate private static final String CN_PREFIX = "CN="; /** The canonical name of an anonymous user. */ @Obfuscate static final String ANONYMOUS = "anonymous"; private final BasicLicenseManagementContext context; BasicLicenseInitialization(final BasicLicenseManagementContext context) { assert null != context; this.context = context; } /** Returns the basic license management context. */ BasicLicenseManagementContext context() { return context; } @Override public String subject() { return context().subject(); } @Override public Date now() { return context().now(); } /** * Initializes undefined properties of the given license with default * values. * * @param license the license to initialize. */ @Override public void initialize(final License license) { if (null == license.getConsumerType()) license.setConsumerType(DEFAULT_CONSUMER_TYPE); if (null == license.getHolder()) license.setHolder(new X500Principal(CN_PREFIX + message(ANONYMOUS))); if (null == license.getIssued()) license.setIssued(now()); // don't trust the system clock! if (null == license.getIssuer()) license.setIssuer(new X500Principal(CN_PREFIX + subject())); if (null == license.getSubject()) license.setSubject(subject()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy