Search in sources :

Example 11 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class FileSystemBookmarkStorageService method readBookmarkFolder.

/**
 * Reads a bookmark folder.
 *
 * @since 3.8.2
 */
private BookmarkFolder readBookmarkFolder(String filename) {
    RemoteFile spec = new RemoteFile("bookmarks", filename, 0);
    RemoteFile f = BEANS.get(IRemoteFileService.class).getRemoteFile(spec);
    if (f.exists()) {
        try {
            byte[] bytes = f.extractData();
            return SerializationUtility.createObjectSerializer().deserialize(bytes, BookmarkFolder.class);
        } catch (Exception t) {
            LOG.error("Could not deserialize bookmark folder", t);
        }
    }
    return null;
}
Also used : RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) IOException(java.io.IOException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) IRemoteFileService(org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService)

Example 12 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class HolidayCalendarService method getItems.

@Override
public Set<? extends ICalendarItem> getItems(RemoteFile spec, Date minDate, Date maxDate) {
    // load new items
    HolidayCalendarItemParser p = null;
    String key = spec.getPath();
    synchronized (m_holidayXmlCache) {
        p = m_holidayXmlCache.get(key);
        if (p == null) {
            try {
                RemoteFile f = BEANS.get(IRemoteFileService.class).getRemoteFile(spec);
                if (f != null) {
                    p = new HolidayCalendarItemParser(f.getDecompressedInputStream(), spec.getPath());
                    m_holidayXmlCache.put(key, p);
                }
            } catch (Exception e) {
                LOG.warn("parsing remote file: {}", spec, e);
            }
        }
    }
    final Set<? extends ICalendarItem> result;
    if (p != null) {
        result = p.getItems(NlsLocale.get(), minDate, maxDate);
    } else {
        result = CollectionUtility.hashSet();
    }
    return result;
}
Also used : HolidayCalendarItemParser(org.eclipse.scout.rt.shared.services.common.calendar.HolidayCalendarItemParser) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) IRemoteFileService(org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService)

Example 13 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class GlobalTrustManager method getTrustedCertificates.

protected X509Certificate[] getTrustedCertificates() throws IOException, CertificateException {
    FilenameFilter certFilter = new FilenameFilter() {

        @Override
        public boolean accept(File file, String name) {
            return (name.toLowerCase().endsWith(".der"));
        }
    };
    List<X509Certificate> trustedCerts = null;
    try {
        RemoteFile[] certRemoteFiles = BEANS.get(IRemoteFileService.class).getRemoteFiles(PATH_CERTS, certFilter, null);
        if (certRemoteFiles.length == 0) {
            LOG.warn("No certificates to trust in folder '{}' could be found.", PATH_CERTS);
        }
        trustedCerts = installTrustedCertificates(certRemoteFiles);
    } catch (RuntimeException e) {
        LOG.error("Could not access folder '{}' to import trusted certificates.", PATH_CERTS, e);
    }
    return trustedCerts == null ? new X509Certificate[] {} : trustedCerts.toArray(new X509Certificate[trustedCerts.size()]);
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) X509Certificate(java.security.cert.X509Certificate) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) IRemoteFileService(org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService)

Example 14 with RemoteFile

use of org.eclipse.scout.rt.shared.services.common.file.RemoteFile in project scout.rt by eclipse.

the class GlobalTrustManager method installTrustedCertificates.

protected List<X509Certificate> installTrustedCertificates(RemoteFile[] certRemoteFiles) {
    List<X509Certificate> trustedCerts = new LinkedList<X509Certificate>();
    for (RemoteFile certRemoteFile : certRemoteFiles) {
        try {
            LOG.info("Trusted certificate '{}' found.", certRemoteFile.getName());
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            certRemoteFile.writeData(os);
            X509Certificate cert = readX509Cert(new ByteArrayInputStream(os.toByteArray()));
            trustedCerts.add(cert);
            LOG.info("Trusted certificate '{}' successfully installed.", certRemoteFile.getName());
        } catch (Exception e) {
            LOG.info("Failed to install trusted certificate '{}'.", certRemoteFile.getName(), e);
        }
    }
    return trustedCerts;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) X509Certificate(java.security.cert.X509Certificate) LinkedList(java.util.LinkedList) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)14 IOException (java.io.IOException)9 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)9 File (java.io.File)7 IRemoteFileService (org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService)7 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 X509Certificate (java.security.cert.X509Certificate)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FilenameFilter (java.io.FilenameFilter)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1