[jboss-cvs] Picketbox SVN: r405 - in branches/embargo/4.0.16.Final-vault: security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/vault and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 16 15:11:52 EDT 2013


Author: pskopek
Date: 2013-04-16 15:11:51 -0400 (Tue, 16 Apr 2013)
New Revision: 405

Modified:
   branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/main/java/org/picketbox/util/KeyStoreUtil.java
   branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/vault/EncryptionUtilUnitTestCase.java
   branches/embargo/4.0.16.Final-vault/security-spi/common/src/main/java/org/jboss/security/PicketBoxMessages.java
Log:
adding keystore type support - fixing previous commit

Modified: branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/main/java/org/picketbox/util/KeyStoreUtil.java
===================================================================
--- branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/main/java/org/picketbox/util/KeyStoreUtil.java	2013-04-16 19:10:44 UTC (rev 404)
+++ branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/main/java/org/picketbox/util/KeyStoreUtil.java	2013-04-16 19:11:51 UTC (rev 405)
@@ -51,19 +51,20 @@
 {
    /**
     * Get the KeyStore
+    * @param keyStoreType or null for default
     * @param keyStoreFile
     * @param storePass
     * @return
     * @throws GeneralSecurityException
     * @throws IOException
     */
-   public static KeyStore getKeyStore(File keyStoreFile, char[] storePass) throws GeneralSecurityException, IOException
+   public static KeyStore getKeyStore(String keyStoreType, File keyStoreFile, char[] storePass) throws GeneralSecurityException, IOException
    {
       FileInputStream fis = null;
       try
       {
          fis = new FileInputStream(keyStoreFile);
-         return getKeyStore(fis, storePass);  
+         return getKeyStore(keyStoreType, fis, storePass);  
       }
       finally
       {
@@ -73,13 +74,14 @@
 
    /**
     * Get the Keystore given the url to the keystore file as a string
+    * @param keyStoreType or null for default
     * @param fileURL
     * @param storePass 
     * @return
     * @throws GeneralSecurityException
     * @throws IOException
     */
-   public static KeyStore getKeyStore(String fileURL, char[] storePass) throws GeneralSecurityException, IOException
+   public static KeyStore getKeyStore(String keyStoreType, String fileURL, char[] storePass) throws GeneralSecurityException, IOException
    {
       if (fileURL == null)
          throw PicketBoxMessages.MESSAGES.invalidNullArgument("fileURL");
@@ -89,7 +91,7 @@
       try
       {
          fis = new FileInputStream(file);
-         return getKeyStore(fis, storePass);
+         return getKeyStore(keyStoreType, fis, storePass);
       }
       finally
       {
@@ -99,13 +101,14 @@
 
    /**
     * Get the Keystore given the URL to the keystore
+    * @param keyStoreType or null for default
     * @param url
     * @param storePass
     * @return
     * @throws GeneralSecurityException
     * @throws IOException
     */
-   public static KeyStore getKeyStore(URL url, char[] storePass) throws GeneralSecurityException, IOException
+   public static KeyStore getKeyStore(String keyStoreType, URL url, char[] storePass) throws GeneralSecurityException, IOException
    {
       if (url == null)
          throw PicketBoxMessages.MESSAGES.invalidNullArgument("url");
@@ -114,7 +117,7 @@
       try
       {
          is = url.openStream();
-         return getKeyStore(is, storePass);
+         return getKeyStore(keyStoreType, is, storePass);
       }
       finally
       {
@@ -125,6 +128,7 @@
    /**
     * Get the Key Store
     * <b>Note:</b> This method wants the InputStream to be not null. 
+    * @param keyStoreType or null for default
     * @param ksStream
     * @param storePass
     * @return
@@ -132,13 +136,12 @@
     * @throws IOException
     * @throws IllegalArgumentException if ksStream is null
     */
-   public static KeyStore getKeyStore(InputStream ksStream, char[] storePass) throws GeneralSecurityException,
+   public static KeyStore getKeyStore(String keyStoreType, InputStream ksStream, char[] storePass) throws GeneralSecurityException,
          IOException
    {
       if (ksStream == null)
          throw PicketBoxMessages.MESSAGES.invalidNullArgument("ksStream");
-      // KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
-      KeyStore ks = KeyStore.getInstance("JCEKS");
+      KeyStore ks = KeyStore.getInstance((keyStoreType == null ? KeyStore.getDefaultType() : keyStoreType));
       ks.load(ksStream, storePass);
       return ks;
    }
@@ -190,6 +193,7 @@
 
    /**
     * Add a certificate to the KeyStore
+    * @param keyStoreType or null for default
     * @param keystoreFile
     * @param storePass
     * @param alias
@@ -197,10 +201,10 @@
     * @throws GeneralSecurityException
     * @throws IOException
     */
-   public static void addCertificate(File keystoreFile, char[] storePass, String alias, Certificate cert)
+   public static void addCertificate(String keyStoreType, File keystoreFile, char[] storePass, String alias, Certificate cert)
          throws GeneralSecurityException, IOException
    {
-      KeyStore keystore = getKeyStore(keystoreFile, storePass);
+      KeyStore keystore = getKeyStore(keyStoreType, keystoreFile, storePass);
 
       // Add the certificate
       keystore.setCertificateEntry(alias, cert);

Modified: branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/vault/EncryptionUtilUnitTestCase.java
===================================================================
--- branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/vault/EncryptionUtilUnitTestCase.java	2013-04-16 19:10:44 UTC (rev 404)
+++ branches/embargo/4.0.16.Final-vault/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/security/vault/EncryptionUtilUnitTestCase.java	2013-04-16 19:11:51 UTC (rev 405)
@@ -48,7 +48,7 @@
    @Test
    public void testEncryptDecrypt() throws Exception
    {
-      KeyStore ks = KeyStoreUtil.getKeyStore(keyStoreURL, keyStorePass.toCharArray());
+      KeyStore ks = KeyStoreUtil.getKeyStore("JKS", keyStoreURL, keyStorePass.toCharArray());
       assertNotNull(ks);
       EncryptionUtil encUtil = new EncryptionUtil("AES", 128);
       

Modified: branches/embargo/4.0.16.Final-vault/security-spi/common/src/main/java/org/jboss/security/PicketBoxMessages.java
===================================================================
--- branches/embargo/4.0.16.Final-vault/security-spi/common/src/main/java/org/jboss/security/PicketBoxMessages.java	2013-04-16 19:10:44 UTC (rev 404)
+++ branches/embargo/4.0.16.Final-vault/security-spi/common/src/main/java/org/jboss/security/PicketBoxMessages.java	2013-04-16 19:11:51 UTC (rev 405)
@@ -454,4 +454,6 @@
     @Message(id = 139, value = "Unable to store keystore to file (%s)")
     RuntimeException unableToStoreKeyStoreToFile(@Cause Throwable throwable, String file);
 
+    @Message(id = 140, value = "Unable to get keystore (%s)")
+    RuntimeException unableToGetKeyStore(@Cause Throwable throwable, String file);
 }
\ No newline at end of file



More information about the jboss-cvs-commits mailing list