You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/12/22 16:35:44 UTC

[1/2] syncope git commit: [SYNCOPE-751] Implementation provided based on PDFBox

Repository: syncope
Updated Branches:
  refs/heads/master e5bb44d90 -> 2a75cf3b6


[SYNCOPE-751] Implementation provided based on PDFBox


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/3696cf25
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/3696cf25
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/3696cf25

Branch: refs/heads/master
Commit: 3696cf2559979e38dc30954873265d509fc2b24c
Parents: e5bb44d
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Tue Dec 22 16:28:19 2015 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Tue Dec 22 16:28:19 2015 +0100

----------------------------------------------------------------------
 client/console/pom.xml                          |   5 +
 .../client/console/commons/PreviewUtils.java    |  10 +-
 .../markup/html/form/BinaryFieldPanel.java      |   3 +-
 .../form/preview/AbstractBinaryPreviewer.java   |   3 -
 .../html/form/preview/BinaryCertPreviewer.java  |  10 +-
 .../html/form/preview/BinaryImagePreviewer.java |  15 +-
 .../html/form/preview/BinaryPDFPreviewer.java   | 147 +++++++++++++++++++
 .../html/form/preview/BinaryPDFPreviewer.html   |  37 +++++
 pom.xml                                         |   6 +
 9 files changed, 213 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/pom.xml
----------------------------------------------------------------------
diff --git a/client/console/pom.xml b/client/console/pom.xml
index 24f6288..5d3e658 100644
--- a/client/console/pom.xml
+++ b/client/console/pom.xml
@@ -95,6 +95,11 @@ under the License.
     </dependency>
 
     <dependency>
+      <groupId>org.apache.pdfbox</groupId>
+      <artifactId>pdfbox</artifactId>
+    </dependency>
+      
+    <dependency>
       <groupId>org.webjars</groupId>
       <artifactId>font-awesome</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java b/client/console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java
index ae2661d..2cb08cf 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/commons/PreviewUtils.java
@@ -55,21 +55,19 @@ public final class PreviewUtils {
     }
 
     public AbstractBinaryPreviewer getPreviewer(final String mimeType) {
-
         if (StringUtils.isBlank(mimeType)) {
             return null;
         }
 
-        final Class<? extends AbstractBinaryPreviewer> previewer
-                = classPathScanImplementationLookup.getPreviewerClass(mimeType);
-
+        Class<? extends AbstractBinaryPreviewer> previewer =
+                classPathScanImplementationLookup.getPreviewerClass(mimeType);
         try {
             return previewer == null
                     ? null
                     : getConstructorIfAvailable(previewer, String.class, String.class).
                     newInstance(new Object[] { "previewer", mimeType });
-        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException 
-                | InvocationTargetException ex) {
+        } catch (InstantiationException | IllegalAccessException 
+                | IllegalArgumentException | InvocationTargetException e) {
             return null;
         }
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/BinaryFieldPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/BinaryFieldPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/BinaryFieldPanel.java
index 31c3ef7..481cb43 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/BinaryFieldPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/BinaryFieldPanel.java
@@ -151,8 +151,7 @@ public class BinaryFieldPanel extends FieldPanel<String> {
         config.showRemove(false);
         config.showPreview(false);
 
-        fileUpload = new BootstrapFileInputField("fileUpload",
-                new ListModel<FileUpload>(new ArrayList<FileUpload>()), config);
+        fileUpload = new BootstrapFileInputField("fileUpload", new ListModel<>(new ArrayList<FileUpload>()), config);
         fileUpload.setOutputMarkupId(true);
 
         fileUpload.add(new AjaxFormSubmitBehavior(Constants.ON_CHANGE) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java
index 97bb2f3..796c825 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/AbstractBinaryPreviewer.java
@@ -26,9 +26,6 @@ import org.slf4j.LoggerFactory;
 
 public abstract class AbstractBinaryPreviewer extends Panel {
 
-    /**
-     * Logger.
-     */
     protected static final Logger LOG = LoggerFactory.getLogger(AbstractBinaryPreviewer.class);
 
     private static final long serialVersionUID = -2482706463911903025L;

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java
index f7b3831..778c16b 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryCertPreviewer.java
@@ -44,20 +44,20 @@ public class BinaryCertPreviewer extends AbstractBinaryPreviewer {
 
     @Override
     public Component preview(final byte[] uploadedBytes) {
-        final Label commonNameLabel = new Label("certCommonName", new Model<String>());
+        Label commonNameLabel = new Label("certCommonName", new Model<String>());
         if (uploadedBytes.length == 0) {
             LOG.info("Enpty certificate");
             return commonNameLabel;
         }
 
-        final ByteArrayInputStream certificateStream = new ByteArrayInputStream(uploadedBytes);
+        ByteArrayInputStream certificateStream = new ByteArrayInputStream(uploadedBytes);
         try {
-            final X509Certificate certificate = (X509Certificate) CertificateFactory.getInstance("X.509").
+            X509Certificate certificate = (X509Certificate) CertificateFactory.getInstance("X.509").
                     generateCertificate(certificateStream);
 
-            final StringBuilder commonNameBuilder = new StringBuilder("cn=");
+            StringBuilder commonNameBuilder = new StringBuilder("cn=");
 
-            final LdapName ldapName = new LdapName(certificate.getIssuerDN().getName());
+            LdapName ldapName = new LdapName(certificate.getIssuerDN().getName());
 
             for (Rdn rdn : ldapName.getRdns()) {
                 if ("CN".equalsIgnoreCase(rdn.getType())) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java
index dc198ea..2468cc1 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryImagePreviewer.java
@@ -38,14 +38,15 @@ public class BinaryImagePreviewer extends AbstractBinaryPreviewer {
 
     @Override
     public Component preview(final byte[] uploadedBytes) {
-        return this.add(new NonCachingImage("previewImage", new ThumbnailImageResource(new DynamicImageResource() {
+        return this.addOrReplace(
+                new NonCachingImage("previewImage", new ThumbnailImageResource(new DynamicImageResource() {
 
-            private static final long serialVersionUID = 923201517955737928L;
+                    private static final long serialVersionUID = 923201517955737928L;
 
-            @Override
-            protected byte[] getImageData(final IResource.Attributes attributes) {
-                return uploadedBytes;
-            }
-        }, IMG_SIZE)));
+                    @Override
+                    protected byte[] getImageData(final IResource.Attributes attributes) {
+                        return uploadedBytes;
+                    }
+                }, IMG_SIZE)));
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java
new file mode 100644
index 0000000..ed7b777
--- /dev/null
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.console.wicket.markup.html.form.preview;
+
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.List;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.syncope.client.console.annotations.BinaryPreview;
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.image.NonCachingImage;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.request.resource.DynamicImageResource;
+import org.apache.wicket.request.resource.IResource;
+import org.apache.wicket.util.io.IOUtils;
+import org.apache.wicket.util.time.Time;
+
+@BinaryPreview(mimeTypes = { "application/pdf" })
+public class BinaryPDFPreviewer extends AbstractBinaryPreviewer {
+
+    private static final long serialVersionUID = -6606409541566687016L;
+
+    private static final int IMG_SIZE = 300;
+
+    private static final int RESOLUTION = 96;
+
+    private static final int IMAGE_TYPE = BufferedImage.TYPE_INT_RGB;
+
+    private transient BufferedImage firstPage;
+
+    public BinaryPDFPreviewer(final String id, final String mimeType) {
+        super(id, mimeType);
+    }
+
+    @Override
+    public Component preview(final byte[] uploadedBytes) {
+        firstPage = null;
+
+        PDDocument document = null;
+        try {
+            document = PDDocument.load(new ByteArrayInputStream(uploadedBytes));
+            if (document.isEncrypted()) {
+                LOG.info("Document is encrypted, no preview is possible");
+            } else {
+                @SuppressWarnings("unchecked")
+                List<PDPage> pages = document.getDocumentCatalog().getAllPages();
+                firstPage = pages.get(0).convertToImage(IMAGE_TYPE, RESOLUTION);
+            }
+        } catch (IOException e) {
+            LOG.error("While generating thumbnail from first page", e);
+        } finally {
+            IOUtils.closeQuietly(document);
+        }
+
+        Fragment fragment;
+        if (firstPage == null) {
+            fragment = new Fragment("preview", "noPreviewFragment", this);
+        } else {
+            fragment = new Fragment("preview", "previewFragment", this);
+            fragment.add(new NonCachingImage("previewImage", new ThumbnailImageResource(firstPage)));
+        }
+
+        WebMarkupContainer previewContainer = new WebMarkupContainer("previewContainer");
+        previewContainer.setOutputMarkupId(true);
+        previewContainer.add(fragment);
+        return this.addOrReplace(previewContainer);
+    }
+
+    private static class ThumbnailImageResource extends DynamicImageResource implements Serializable {
+
+        private static final long serialVersionUID = 923201517955737928L;
+
+        private final transient BufferedImage image;
+
+        private transient byte[] thumbnail;
+
+        ThumbnailImageResource(final BufferedImage image) {
+            this.image = image;
+        }
+
+        @Override
+        protected byte[] getImageData(final IResource.Attributes attributes) {
+            if (thumbnail == null) {
+                thumbnail = toImageData(getScaledImageInstance());
+                setLastModifiedTime(Time.now());
+            }
+            return thumbnail;
+        }
+
+        private BufferedImage getScaledImageInstance() {
+            int originalWidth = image.getWidth();
+            int originalHeight = image.getHeight();
+
+            if ((originalWidth > IMG_SIZE) || (originalHeight > IMG_SIZE)) {
+                final int newWidth;
+                final int newHeight;
+
+                if (originalWidth > originalHeight) {
+                    newWidth = IMG_SIZE;
+                    newHeight = (IMG_SIZE * originalHeight) / originalWidth;
+                } else {
+                    newWidth = (IMG_SIZE * originalWidth) / originalHeight;
+                    newHeight = IMG_SIZE;
+                }
+
+                // http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html
+                BufferedImage dimg = new BufferedImage(newWidth, newHeight, image.getType());
+                Graphics2D g = dimg.createGraphics();
+                try {
+                    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+                            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+                    g.drawImage(image, 0, 0, newWidth, newHeight, 0, 0, originalWidth,
+                            originalHeight, null);
+                } finally {
+                    g.dispose();
+                }
+
+                return dimg;
+            }
+
+            // no need for resizing
+            return image;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.html
----------------------------------------------------------------------
diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.html b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.html
new file mode 100644
index 0000000..6b4cee1
--- /dev/null
+++ b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/form/preview/BinaryPDFPreviewer.html
@@ -0,0 +1,37 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+  <head><title></title></head>
+  <body>
+    <wicket:extend>
+      <div wicket:id="previewContainer">
+        <span wicket:id="preview"/>
+      </div>
+
+      <wicket:fragment wicket:id="previewFragment">
+        <div><img wicket:id = "previewImage"/></div>
+      </wicket:fragment>
+      <wicket:fragment wicket:id="noPreviewFragment">
+        <div style="padding: 8px 0px 1px 10px">
+          <i class=" glyphicon glyphicon-paperclip fa-2x" title="Preview not available" alt="Default preview icon"></i>
+        </div>
+      </wicket:fragment>
+    </wicket:extend>
+  </body>
+</html>

http://git-wip-us.apache.org/repos/asf/syncope/blob/3696cf25/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index bc9df36..7bd9ad8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -952,6 +952,12 @@ under the License.
       </dependency>
       
       <dependency>
+        <groupId>org.apache.pdfbox</groupId>
+        <artifactId>pdfbox</artifactId>
+        <version>1.8.10</version>
+      </dependency>
+      
+      <dependency>
         <groupId>org.webjars</groupId>
         <artifactId>jquery</artifactId>
         <version>${jquery.version}</version>


[2/2] syncope git commit: Upgrading ApacheDS

Posted by il...@apache.org.
Upgrading ApacheDS


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/2a75cf3b
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/2a75cf3b
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/2a75cf3b

Branch: refs/heads/master
Commit: 2a75cf3b64b6b7f0876620b207ad3a977adaf865
Parents: 3696cf2
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Tue Dec 22 16:35:36 2015 +0100
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Tue Dec 22 16:35:36 2015 +0100

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/2a75cf3b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7bd9ad8..74cb919 100644
--- a/pom.xml
+++ b/pom.xml
@@ -734,7 +734,7 @@ under the License.
       <dependency>
         <groupId>org.apache.directory.server</groupId>
         <artifactId>apacheds-all</artifactId>
-        <version>2.0.0-M20</version>
+        <version>2.0.0-M21</version>
       </dependency>
       
       <dependency>