[jboss-cvs] Picketlink SVN: r783 - federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/metadata.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 28 15:28:24 EST 2011


Author: anil.saldhana at jboss.com
Date: 2011-02-28 15:28:24 -0500 (Mon, 28 Feb 2011)
New Revision: 783

Modified:
   federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/metadata/KeyDescriptorMetaDataBuilder.java
Log:
PLFED-151: add a new method just for the key descriptor

Modified: federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/metadata/KeyDescriptorMetaDataBuilder.java
===================================================================
--- federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/metadata/KeyDescriptorMetaDataBuilder.java	2011-02-28 20:17:28 UTC (rev 782)
+++ federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/metadata/KeyDescriptorMetaDataBuilder.java	2011-02-28 20:28:24 UTC (rev 783)
@@ -37,40 +37,72 @@
  * @since Apr 20, 2009
  */
 public class KeyDescriptorMetaDataBuilder
-{  
+{
    /**
-    * Create a Key Descriptor Type
+    * Create a Key Descriptor
+    * @param keyInfo
+    * @param algorithm
+    * @param keySize
+    * @param isSigningKey Whether the key is for signing
+    * @param isEncryptionKey Whether the key is for encryption
+    * @throws {@link IllegalArgumentException} when keyinfo is null
+    * @throws {@link IllegalArgumentException} when both the parameters "isSigningKey" and "isEncryptionKey" are same
     * @return
     */
-   public static KeyDescriptorType createKeyDescriptor( Element keyInfo,
-         String algorithm, int keySize,
+   public static KeyDescriptorType createKeyDescriptor(Element keyInfo, String algorithm, int keySize,
          boolean isSigningKey, boolean isEncryptionKey)
    {
-      if(keyInfo == null)
+      if (keyInfo == null)
          throw new IllegalArgumentException("keyInfo is null");
-      
-      if(isSigningKey == isEncryptionKey)
-         throw new IllegalArgumentException("Only one of isSigningKey " +
-         		"and isEncryptionKey should be true");
-      
+
+      if (isSigningKey == isEncryptionKey)
+         throw new IllegalArgumentException("Only one of isSigningKey " + "and isEncryptionKey should be true");
+
       KeyDescriptorType keyDescriptor = new KeyDescriptorType();
-      
-      if(isNotNull(algorithm))
+
+      if (isNotNull(algorithm))
       {
-         EncryptionMethodType encryptionMethod = new EncryptionMethodType( algorithm ); 
-         
-         encryptionMethod.setEncryptionMethod( new EncryptionMethod( BigInteger.valueOf(keySize), null ));
-         
-         keyDescriptor.addEncryptionMethod( encryptionMethod );  
-      } 
-      
-      if(isSigningKey)
+         EncryptionMethodType encryptionMethod = new EncryptionMethodType(algorithm);
+
+         encryptionMethod.setEncryptionMethod(new EncryptionMethod(BigInteger.valueOf(keySize), null));
+
+         keyDescriptor.addEncryptionMethod(encryptionMethod);
+      }
+
+      if (isSigningKey)
          keyDescriptor.setUse(KeyTypes.SIGNING);
-      if(isEncryptionKey)
-         keyDescriptor.setUse(KeyTypes.ENCRYPTION); 
-      
-      keyDescriptor.setKeyInfo( keyInfo );
-       
+      if (isEncryptionKey)
+         keyDescriptor.setUse(KeyTypes.ENCRYPTION);
+
+      keyDescriptor.setKeyInfo(keyInfo);
+
       return keyDescriptor;
    }
+
+   /**
+    * Create a key descriptor that specifies an algorithm but does not specify 
+    * whether the key is for signing or encryption
+    * @param keyInfo
+    * @param algorithm
+    * @param keySize
+    * @return
+    */
+   public static KeyDescriptorType createKeyDescriptor(Element keyInfo, String algorithm, int keySize)
+   {
+      if (keyInfo == null)
+         throw new IllegalArgumentException("keyInfo is null");
+      KeyDescriptorType keyDescriptor = new KeyDescriptorType();
+
+      if (isNotNull(algorithm))
+      {
+         EncryptionMethodType encryptionMethod = new EncryptionMethodType(algorithm);
+
+         encryptionMethod.setEncryptionMethod(new EncryptionMethod(BigInteger.valueOf(keySize), null));
+
+         keyDescriptor.addEncryptionMethod(encryptionMethod);
+      }
+      keyDescriptor.setKeyInfo(keyInfo);
+
+      return keyDescriptor;
+   }
 }
\ No newline at end of file



More information about the jboss-cvs-commits mailing list