Search in sources :

Example 1 with LicenseException

use of org.alfresco.service.license.LicenseException in project alfresco-repository by Alfresco.

the class RepositoryDescriptorDAOImpl method updateLicenseKey.

@Override
public void updateLicenseKey(final byte[] key) {
    try {
        final NodeRef descriptorRef = getDescriptorNodeRef(true);
        if (descriptorRef == null) {
            // Should not get this as 'true' was used.
            throw new LicenseException("Failed to find system descriptor");
        }
        if (key == null) {
            this.nodeService.setProperty(descriptorRef, ContentModel.PROP_SYS_VERSION_EDITION, null);
        } else {
            final ContentWriter writer = this.contentService.getWriter(descriptorRef, ContentModel.PROP_SYS_VERSION_EDITION, true);
            final InputStream is = new ByteArrayInputStream(key);
            writer.setMimetype(MimetypeMap.MIMETYPE_BINARY);
            writer.putContent(is);
        }
    } catch (final RuntimeException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("getLicenseKey: ", e);
        }
        throw new LicenseException("Failed to save license", e);
    } catch (final Error e) {
        if (logger.isDebugEnabled()) {
            logger.debug("getLicenseKey: ", e);
        }
        throw e;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) LicenseException(org.alfresco.service.license.LicenseException) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 2 with LicenseException

use of org.alfresco.service.license.LicenseException in project alfresco-repository by Alfresco.

the class RepositoryDescriptorDAOImpl method getLicenseKey.

@Override
public byte[] getLicenseKey() {
    byte[] key = null;
    try {
        final NodeRef descriptorRef = getDescriptorNodeRef(true);
        if (descriptorRef == null) {
            // Should not get this as 'true' was used.
            throw new LicenseException("Failed to find system descriptor");
        }
        if (logger.isDebugEnabled()) {
            logger.debug("getLicenseKey: descriptorRef=" + descriptorRef);
        }
        final ContentReader reader = this.contentService.getReader(descriptorRef, ContentModel.PROP_SYS_VERSION_EDITION);
        boolean exists = reader != null && reader.exists();
        if (exists) {
            ByteArrayOutputStream os = null;
            try {
                os = new ByteArrayOutputStream();
                reader.getContent(os);
                key = os.toByteArray();
            } finally {
                if (os != null) {
                    try {
                        os.close();
                    } catch (IOException ignore) {
                        // We have more to worry about if we ever get here.
                        logger.debug("getLicenseKey: Error closing ByteArrayOutputStream", ignore);
                    }
                }
            }
        } else {
            if (logger.isDebugEnabled()) {
                // reader should never be null. An exception is thrown by getReader if it is.
                logger.debug("getLicenseKey: reader " + (reader == null ? "is null" : " file does " + (exists ? "" : "NOT ") + "exist"));
            }
        }
    } catch (final LicenseException e) {
        throw e;
    } catch (final RuntimeException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("getLicenseKey: ", e);
        }
        throw new LicenseException("Failed to load license", e);
    } catch (final Error e) {
        if (logger.isDebugEnabled()) {
            logger.debug("getLicenseKey: ", e);
        }
        throw e;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("getLicenseKey: key " + (key == null ? "is null" : "length=" + key.length));
    }
    return key;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) LicenseException(org.alfresco.service.license.LicenseException) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with LicenseException

use of org.alfresco.service.license.LicenseException in project alfresco-repository by Alfresco.

the class DescriptorServiceImpl method bootstrap.

private void bootstrap() {
    logger.debug("onBootstrap");
    // We force write mode
    RetryingTransactionHelper helper = transactionService.getRetryingTransactionHelper();
    helper.setForceWritable(true);
    // create the initial installed descriptor
    RetryingTransactionCallback<Descriptor> getDescriptorCallback = new RetryingTransactionCallback<Descriptor>() {

        public Descriptor execute() {
            return installedRepoDescriptorDAO.getDescriptor();
        }
    };
    Descriptor installed = helper.doInTransaction(getDescriptorCallback, false, false);
    if (installed != null) {
        installedRepoDescriptor = installed;
    } else {
        installedRepoDescriptor = new UnknownDescriptor();
    }
    /*
         *  Initialize license service if on classpath.  
         *  If no class exists a dummy license service is used.
         *  Make the LicenseService available in the context.
         */
    licenseService = (LicenseService) constructSpecialService("org.alfresco.enterprise.license.LicenseComponent");
    if (licenseService == null) {
        // No license server code - install a dummy license service instead
        licenseService = new NOOPLicenseService();
    }
    ApplicationContext applicationContext = getApplicationContext();
    if (applicationContext instanceof ConfigurableApplicationContext) {
        ((ConfigurableApplicationContext) applicationContext).getBeanFactory().registerSingleton("licenseService", licenseService);
    }
    // Register HeartBeat with LicenseService
    licenseService.registerOnLicenseChange((LicenseChangeHandler) hbDataCollectorService);
    // Now listen for future license changes
    licenseService.registerOnLicenseChange(this);
    try {
        // Verify license has side effect of loading any new licenses
        licenseService.verifyLicense();
    } catch (LicenseException e) {
    // Swallow Licence Exception Here
    // Don't log error: It'll be reported by other means
    }
    ;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) LicenseException(org.alfresco.service.license.LicenseException) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) Descriptor(org.alfresco.service.descriptor.Descriptor) LicenseDescriptor(org.alfresco.service.license.LicenseDescriptor)

Aggregations

LicenseException (org.alfresco.service.license.LicenseException)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 Descriptor (org.alfresco.service.descriptor.Descriptor)1 LicenseDescriptor (org.alfresco.service.license.LicenseDescriptor)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1