usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [4/5] usergrid git commit: Make sure the validTo and validFrom string formats are GMT timezone. Add filename to the certInfo object.
Date Tue, 12 Jan 2016 21:15:38 GMT
Make sure the validTo and validFrom string formats are GMT timezone.  Add filename to the certInfo
object.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/61c57c28
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/61c57c28
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/61c57c28

Branch: refs/heads/master
Commit: 61c57c286e2694b5cb50ecdf3f4e60c263ad7f75
Parents: bc68332
Author: Michael Russo <michaelarusso@gmail.com>
Authored: Tue Jan 12 09:15:05 2016 -0800
Committer: Michael Russo <michaelarusso@gmail.com>
Committed: Tue Jan 12 09:15:05 2016 -0800

----------------------------------------------------------------------
 .../notifiers/NotifierResource.java             | 25 ++++++++++++--------
 .../notifiers/NotifiersResource.java            | 14 ++++++++++-
 .../usergrid/rest/utils/CertificateUtils.java   | 14 +++++++----
 3 files changed, 37 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/61c57c28/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
index 637f0a5..21d3d73 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
@@ -69,8 +69,8 @@ public class NotifierResource extends ServiceResource {
             logger.debug("NotifierResource.executeMultiPartPut");
         }
 
-        String certInfo = getValueOrNull(multiPart, "certInfo");
-        if (certInfo != null){
+        String certInfoParam = getValueOrNull(multiPart, "certInfo");
+        if (certInfoParam != null){
             throw new IllegalArgumentException("Cannot create or update with certInfo parameter.
 It is derived.");
         }
 
@@ -80,7 +80,9 @@ public class NotifierResource extends ServiceResource {
 
         InputStream is = null;
         Map<String, Object> certAttributes = null;
+        String filename = null;
         if (multiPart.getField("p12Certificate") != null) {
+            filename = multiPart.getField("p12Certificate").getContentDisposition().getFileName();
             is = multiPart.getField("p12Certificate").getEntityAs(InputStream.class);
             certAttributes = CertificateUtils.getCertAtrributes(is, certPassword);
         }else{
@@ -92,26 +94,29 @@ public class NotifierResource extends ServiceResource {
             throw new IllegalArgumentException("p12Certificate is expired");
         }
 
-        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put("name", name);
-        properties.put("provider", provider);
-        properties.put("environment", "production");
-        properties.put("certificatePassword", certPassword);
+        HashMap<String, Object> certProps = new LinkedHashMap<String, Object>();
+        certProps.put("name", name);
+        certProps.put("provider", provider);
+        certProps.put("environment", "production");
+        certProps.put("certificatePassword", certPassword);
         if (is != null) {
             byte[] certBytes = IOUtils.toByteArray(is);
-            properties.put("p12Certificate", certBytes);
+            certProps.put("p12Certificate", certBytes);
             is.close();
         }
+        HashMap<String, Object> certInfo = new LinkedHashMap<String, Object>();
         if (certAttributes != null){
-            properties.put("certInfo", certAttributes);
+            certInfo.put("filename", filename);
+            certInfo.put("details", certAttributes);
         }
+        certProps.put("certInfo", certInfo);
 
 
         ApiResponse response = createApiResponse();
         response.setAction("put");
         response.setApplication(services.getApplication());
         response.setParams(ui.getQueryParameters());
-        ServicePayload payload = getPayload(properties);
+        ServicePayload payload = getPayload(certProps);
         executeServiceRequest(ui, response, ServiceAction.PUT, payload);
 
         return response;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/61c57c28/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
index 77dab9b..bd02c35 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
@@ -114,6 +114,11 @@ public class NotifiersResource extends ServiceResource {
             logger.debug("Notifiers.executeMultiPartPost");
         }
 
+        String certInfoParam = getValueOrNull(multiPart, "certInfo");
+        if (certInfoParam != null){
+            throw new IllegalArgumentException("Cannot create or update with certInfo parameter.
 It is derived.");
+        }
+
         String name =         getValueOrNull(multiPart, "name");
         String provider =     getValueOrNull(multiPart, "provider");
         String environment =  getValueOrNull(multiPart, "environment");
@@ -121,7 +126,9 @@ public class NotifiersResource extends ServiceResource {
 
         InputStream is = null;
         Map<String, Object> certAttributes = null;
+        String filename = null;
         if (multiPart.getField("p12Certificate") != null) {
+            filename = multiPart.getField("p12Certificate").getContentDisposition().getFileName();
             is = multiPart.getField("p12Certificate").getEntityAs(InputStream.class);
             certAttributes = CertificateUtils.getCertAtrributes(is, certPassword);
         }else{
@@ -133,7 +140,9 @@ public class NotifiersResource extends ServiceResource {
             throw new IllegalArgumentException("p12Certificate is expired.");
         }
 
+
         HashMap<String, Object> certProps = new LinkedHashMap<String, Object>();
+
         certProps.put("name", name);
         certProps.put("provider", provider);
         certProps.put("environment", environment);
@@ -142,9 +151,12 @@ public class NotifiersResource extends ServiceResource {
             byte[] certBytes = IOUtils.toByteArray(is);
             certProps.put("p12Certificate", certBytes);
         }
+        HashMap<String, Object> certInfo = new LinkedHashMap<String, Object>();
         if (certAttributes != null){
-            certProps.put("certInfo", certAttributes);
+            certInfo.put("filename", filename);
+            certInfo.put("details", certAttributes);
         }
+        certProps.put("certInfo", certInfo);
 
         ApiResponse response = createApiResponse();
         response.setAction("post");

http://git-wip-us.apache.org/repos/asf/usergrid/blob/61c57c28/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CertificateUtils.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CertificateUtils.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CertificateUtils.java
index 3ee786b..6f4be92 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CertificateUtils.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/utils/CertificateUtils.java
@@ -22,13 +22,13 @@ import org.slf4j.LoggerFactory;
 import java.io.InputStream;
 import java.security.KeyStore;
 import java.security.cert.X509Certificate;
+import java.text.SimpleDateFormat;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.SimpleTimeZone;
+
 
-/**
- * Created by michaelarusso on 1/11/16.
- */
 public class CertificateUtils {
 
     private static final Logger logger = LoggerFactory.getLogger(CertificateUtils.class);
@@ -41,6 +41,10 @@ public class CertificateUtils {
             certPassword = ""; // if there is no password, pass in empty string
         }
 
+        SimpleDateFormat dateFormat = new SimpleDateFormat();
+        dateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
+        dateFormat.applyPattern("EEE dd MMM yyyy HH:mm:ss z"); // GMT String format
+
         Map<String,Object> attributes = new HashMap<>(1);
         try{
             KeyStore p12 = KeyStore.getInstance("pkcs12");
@@ -50,9 +54,9 @@ public class CertificateUtils {
                 String alias = (String) aliases.nextElement();
                 X509Certificate cert = (X509Certificate) p12.getCertificate(alias);
                 attributes.put("subject", cert.getSubjectDN().toString());
-                attributes.put("validFrom", cert.getNotBefore());
+                attributes.put("validFrom", dateFormat.format(cert.getNotBefore()));
                 attributes.put("validFromTimestamp", cert.getNotBefore().getTime());
-                attributes.put("validTo", cert.getNotAfter());
+                attributes.put("validTo", dateFormat.format(cert.getNotAfter()));
                 attributes.put("validToTimestamp", cert.getNotAfter().getTime());
                 attributes.put("issuer", cert.getIssuerDN().toString());
                 attributes.put("subjectAlternativeNames", cert.getSubjectAlternativeNames());


Mime
View raw message