santuario-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1070849 - in /santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys: KeyInfo.java keyresolver/KeyResolver.java
Date Tue, 15 Feb 2011 11:36:35 GMT
Author: coheigea
Date: Tue Feb 15 11:36:35 2011
New Revision: 1070849

URL: http://svn.apache.org/viewvc?rev=1070849&view=rev
Log:
[SANTUARIO-259] - More KeyResolver cleanup.

Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/KeyInfo.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/KeyInfo.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/KeyInfo.java?rev=1070849&r1=1070848&r2=1070849&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/KeyInfo.java
(original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/KeyInfo.java
Tue Feb 15 11:36:35 2011
@@ -108,9 +108,9 @@ public class KeyInfo extends SignatureEl
     private List<StorageResolver> storageResolvers = nullList;
     
     /**
-     * Stores the individual (per-KeyInfo) {@link KeyResolver}s
+     * Stores the individual (per-KeyInfo) {@link KeyResolverSpi}s
      */
-    private List internalKeyResolvers = null;
+    private List<KeyResolverSpi> internalKeyResolvers = new ArrayList<KeyResolverSpi>();
 
     /**
      * Constructor KeyInfo
@@ -309,8 +309,7 @@ public class KeyInfo extends SignatureEl
      * @throws XMLEncryptionException
      */
 
-    public void add(EncryptedKey encryptedKey) 
-    throws XMLEncryptionException {
+    public void add(EncryptedKey encryptedKey) throws XMLEncryptionException {
         if (encryptedKeys == null) {
             encryptedKeys = new ArrayList<EncryptedKey>();
         }
@@ -428,7 +427,6 @@ public class KeyInfo extends SignatureEl
      * @throws XMLSecurityException
      */
     public KeyName itemKeyName(int i) throws XMLSecurityException {
-
         Element e = 
             XMLUtils.selectDsNode(
                 this.constructionElement.getFirstChild(), Constants._TAG_KEYNAME, i);
@@ -447,7 +445,6 @@ public class KeyInfo extends SignatureEl
      * @throws XMLSecurityException
      */
     public KeyValue itemKeyValue(int i) throws XMLSecurityException {
-
         Element e = 
             XMLUtils.selectDsNode(
                 this.constructionElement.getFirstChild(), Constants._TAG_KEYVALUE, i);
@@ -466,7 +463,6 @@ public class KeyInfo extends SignatureEl
      * @throws XMLSecurityException
      */
     public MgmtData itemMgmtData(int i) throws XMLSecurityException {
-
         Element e = 
             XMLUtils.selectDsNode(
                 this.constructionElement.getFirstChild(), Constants._TAG_MGMTDATA, i);
@@ -485,7 +481,6 @@ public class KeyInfo extends SignatureEl
      * @throws XMLSecurityException
      */
     public PGPData itemPGPData(int i) throws XMLSecurityException {
-
         Element e = 
             XMLUtils.selectDsNode(
                 this.constructionElement.getFirstChild(), Constants._TAG_PGPDATA, i);
@@ -504,7 +499,6 @@ public class KeyInfo extends SignatureEl
      * @throws XMLSecurityException
      */
     public RetrievalMethod itemRetrievalMethod(int i) throws XMLSecurityException {
-
         Element e = 
             XMLUtils.selectDsNode(
                 this.constructionElement.getFirstChild(), Constants._TAG_RETRIEVALMETHOD,
i);
@@ -523,7 +517,6 @@ public class KeyInfo extends SignatureEl
      * @throws XMLSecurityException
      */
     public SPKIData itemSPKIData(int i) throws XMLSecurityException {
-
         Element e = 
             XMLUtils.selectDsNode(
                 this.constructionElement.getFirstChild(), Constants._TAG_SPKIDATA, i);
@@ -732,19 +725,14 @@ public class KeyInfo extends SignatureEl
      * @throws KeyResolverException
      */
     PublicKey getPublicKeyFromStaticResolvers() throws KeyResolverException {
-        int length = KeyResolver.length();
-        int storageLength = this.storageResolvers.size();
-        Iterator it = KeyResolver.iterator();
-        for (int i = 0; i < length; i++) {
-            KeyResolverSpi keyResolver = (KeyResolverSpi) it.next();
+        Iterator<KeyResolverSpi> it = KeyResolver.iterator();
+        while (it.hasNext()) {
+            KeyResolverSpi keyResolver = it.next();
             Node currentChild = this.constructionElement.getFirstChild();
             String uri = this.getBaseURI();
             while (currentChild != null) {       
-                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {          	  
-                    for (int k = 0; k < storageLength; k++) {
-                        StorageResolver storage =
-                            (StorageResolver) this.storageResolvers.get(k);
-
+                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
+                    for (StorageResolver storage : storageResolvers) {
                         PublicKey pk =
                             keyResolver.engineLookupAndResolvePublicKey(
                                 (Element) currentChild, uri, storage
@@ -768,29 +756,27 @@ public class KeyInfo extends SignatureEl
      * @throws KeyResolverException
      */
     PublicKey getPublicKeyFromInternalResolvers() throws KeyResolverException {
-        int length=lengthInternalKeyResolver();
-        int storageLength=this.storageResolvers.size();
-        for (int i = 0; i < length; i++) {
-            KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i);
-            if (log.isDebugEnabled())
+        for (KeyResolverSpi keyResolver : internalKeyResolvers) {
+            if (log.isDebugEnabled()) {
                 log.debug("Try " + keyResolver.getClass().getName());
+            }
 
-            Node currentChild=this.constructionElement.getFirstChild();
-            String uri=this.getBaseURI();
-            while (currentChild!=null)      {    
-                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {               
-                    for (int k = 0; k < storageLength; k++) {
-                        StorageResolver storage =
-                            (StorageResolver) this.storageResolvers.get(k);
-                        PublicKey pk = keyResolver
-                        .engineLookupAndResolvePublicKey((Element) currentChild, uri, storage);
+            Node currentChild = this.constructionElement.getFirstChild();
+            String uri = this.getBaseURI();
+            while (currentChild != null)      {    
+                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {            
+                    for (StorageResolver storage : storageResolvers) {
+                        PublicKey pk = 
+                            keyResolver.engineLookupAndResolvePublicKey(
+                                (Element) currentChild, uri, storage
+                            );
 
                         if (pk != null) {
                             return pk;
                         }                     
                     }               
                 }
-                currentChild=currentChild.getNextSibling();
+                currentChild = currentChild.getNextSibling();
             }
         }
 
@@ -844,7 +830,7 @@ public class KeyInfo extends SignatureEl
      * @throws KeyResolverException
      */
     X509Certificate getX509CertificateFromStaticResolvers()
-    throws KeyResolverException {
+        throws KeyResolverException {
         if (log.isDebugEnabled()) {
             log.debug(
                 "Start getX509CertificateFromStaticResolvers() with " + KeyResolver.length()

@@ -852,12 +838,10 @@ public class KeyInfo extends SignatureEl
             );
         }
         String uri = this.getBaseURI();
-        int length = KeyResolver.length();
-        int storageLength = this.storageResolvers.size();   
-        Iterator it = KeyResolver.iterator();
-        for (int i = 0; i < length; i++) {
-            KeyResolverSpi keyResolver = (KeyResolverSpi) it.next();
-            X509Certificate cert = applyCurrentResolver(uri, storageLength, keyResolver);
+        Iterator<KeyResolverSpi> it = KeyResolver.iterator();
+        while (it.hasNext()) {
+            KeyResolverSpi keyResolver = it.next();
+            X509Certificate cert = applyCurrentResolver(uri, keyResolver);
             if (cert != null) {
                 return cert;
             }
@@ -866,15 +850,12 @@ public class KeyInfo extends SignatureEl
     }
 
     private X509Certificate applyCurrentResolver(
-        String uri, int storageLength, KeyResolverSpi keyResolver
+        String uri, KeyResolverSpi keyResolver
     ) throws KeyResolverException {
         Node currentChild = this.constructionElement.getFirstChild();
         while (currentChild != null)      {       
             if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
-                for (int k = 0; k < storageLength; k++) {
-                    StorageResolver storage =
-                        (StorageResolver) this.storageResolvers.get(k);
-
+                for (StorageResolver storage : storageResolvers) {
                     X509Certificate cert = 
                         keyResolver.engineLookupResolveX509Certificate(
                             (Element) currentChild, uri, storage
@@ -897,22 +878,20 @@ public class KeyInfo extends SignatureEl
      * @throws KeyResolverException
      */
     X509Certificate getX509CertificateFromInternalResolvers()
-    throws KeyResolverException {
+        throws KeyResolverException {
         if (log.isDebugEnabled()) {
             log.debug(
                 "Start getX509CertificateFromInternalResolvers() with " 
                 + this.lengthInternalKeyResolver() + " resolvers"
             );
         }
-        String uri=this.getBaseURI();
-        int storageLength=this.storageResolvers.size();
-        for (int i = 0; i < this.lengthInternalKeyResolver(); i++) {
-            KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i);
+        String uri = this.getBaseURI();
+        for (KeyResolverSpi keyResolver : internalKeyResolvers) {
             if (log.isDebugEnabled()) {
                 log.debug("Try " + keyResolver.getClass().getName());
             }
-            X509Certificate cert= applyCurrentResolver(uri, storageLength, keyResolver);
-            if (cert!=null) {        	
+            X509Certificate cert = applyCurrentResolver(uri, keyResolver);
+            if (cert != null) {        	
                 return cert;
             }      
         }
@@ -961,33 +940,27 @@ public class KeyInfo extends SignatureEl
      * @return the secret key contained in this KeyInfo
      * @throws KeyResolverException
      */
-
     SecretKey getSecretKeyFromStaticResolvers() throws KeyResolverException {
-        final int length=KeyResolver.length();
-        int storageLength=this.storageResolvers.size();
-        Iterator it = KeyResolver.iterator();
-        for (int i = 0; i < length; i++) {
-            KeyResolverSpi keyResolver = (KeyResolverSpi) it.next();
-
-            Node currentChild=this.constructionElement.getFirstChild();
-            String uri=this.getBaseURI();
-            while (currentChild!=null)      {    
-                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {   
-                    for (int k = 0; k < storageLength; k++) {
-                        StorageResolver storage =
-                            (StorageResolver) this.storageResolvers.get(k);
+        Iterator<KeyResolverSpi> it = KeyResolver.iterator();
+        while (it.hasNext()) {
+            KeyResolverSpi keyResolver = it.next();
 
+            Node currentChild = this.constructionElement.getFirstChild();
+            String uri = this.getBaseURI();
+            while (currentChild != null)      {    
+                if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
+                    for (StorageResolver storage : storageResolvers) {
                         SecretKey sk =
-                            keyResolver.engineLookupAndResolveSecretKey((Element) currentChild,
-                                                                        uri,
-                                                                        storage);
+                            keyResolver.engineLookupAndResolveSecretKey(
+                                (Element) currentChild, uri, storage
+                            );
 
                         if (sk != null) {
                             return sk;
                         }                     
                     }               
                 }
-                currentChild=currentChild.getNextSibling();
+                currentChild = currentChild.getNextSibling();
             }
         }
         return null;
@@ -1001,29 +974,27 @@ public class KeyInfo extends SignatureEl
      */
 
     SecretKey getSecretKeyFromInternalResolvers() throws KeyResolverException {
-        int storageLength=this.storageResolvers.size();
-        for (int i = 0; i < this.lengthInternalKeyResolver(); i++) {
-            KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i);
-            if (log.isDebugEnabled())
+        for (KeyResolverSpi keyResolver : internalKeyResolvers) {
+            if (log.isDebugEnabled()) {
                 log.debug("Try " + keyResolver.getClass().getName());
+            }
 
-            Node currentChild=this.constructionElement.getFirstChild();
-            String uri=this.getBaseURI();
-            while (currentChild!=null)      {    
+            Node currentChild = this.constructionElement.getFirstChild();
+            String uri = this.getBaseURI();
+            while (currentChild != null)      {    
                 if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
-                    for (int k = 0; k < storageLength; k++) {
-                        StorageResolver storage =
-                            (StorageResolver) this.storageResolvers.get(k);
-
-                        SecretKey sk = keyResolver
-                        .engineLookupAndResolveSecretKey((Element) currentChild, uri, storage);
+                    for (StorageResolver storage : storageResolvers) {
+                        SecretKey sk = 
+                            keyResolver.engineLookupAndResolveSecretKey(
+                                (Element) currentChild, uri, storage
+                            );
 
                         if (sk != null) {
                             return sk;
                         }                    
                     }
                 }            
-                currentChild=currentChild.getNextSibling();
+                currentChild = currentChild.getNextSibling();
             }
         }
 
@@ -1069,28 +1040,27 @@ public class KeyInfo extends SignatureEl
      * @throws KeyResolverException
      */
     PrivateKey getPrivateKeyFromStaticResolvers() throws KeyResolverException {
-        final int length=KeyResolver.length();
-        Iterator it = KeyResolver.iterator();
-        for (int i = 0; i < length; i++) {
-            KeyResolverSpi keyResolver = (KeyResolverSpi) it.next();
-
-            Node currentChild=this.constructionElement.getFirstChild();
-            String uri=this.getBaseURI();
-            while (currentChild!=null)      {    
+        Iterator<KeyResolverSpi> it = KeyResolver.iterator();
+        while (it.hasNext()) {
+            KeyResolverSpi keyResolver = it.next();
+
+            Node currentChild = this.constructionElement.getFirstChild();
+            String uri = this.getBaseURI();
+            while (currentChild != null)      {    
                 if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                     // not using StorageResolvers at the moment
                     // since they cannot return private keys
                     StorageResolver storage = null;
-                    PrivateKey pk = keyResolver.engineLookupAndResolvePrivateKey(
-                                                                                 (Element)
currentChild,
-                                                                                 uri,
-                                                                                 storage);
+                    PrivateKey pk = 
+                        keyResolver.engineLookupAndResolvePrivateKey(
+                            (Element) currentChild, uri, storage
+                        );
 
                     if (pk != null) {
                         return pk;
                     }                     
                 }
-                currentChild=currentChild.getNextSibling();
+                currentChild = currentChild.getNextSibling();
             }
         }
         return null;
@@ -1102,28 +1072,29 @@ public class KeyInfo extends SignatureEl
      * @return the private key contained in this KeyInfo
      * @throws KeyResolverException
      */
-
     PrivateKey getPrivateKeyFromInternalResolvers() throws KeyResolverException {
-        for (int i = 0; i < this.lengthInternalKeyResolver(); i++) {
-            KeyResolverSpi keyResolver = this.itemInternalKeyResolver(i);
-            if (log.isDebugEnabled())
+        for (KeyResolverSpi keyResolver : internalKeyResolvers) {
+            if (log.isDebugEnabled()) {
                 log.debug("Try " + keyResolver.getClass().getName());
+            }
 
-            Node currentChild=this.constructionElement.getFirstChild();
-            String uri=this.getBaseURI();
-            while (currentChild!=null)      {    
+            Node currentChild = this.constructionElement.getFirstChild();
+            String uri = this.getBaseURI();
+            while (currentChild != null) {    
                 if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                     // not using StorageResolvers at the moment
                     // since they cannot return private keys
                     StorageResolver storage = null;
-                    PrivateKey pk = keyResolver
-                    .engineLookupAndResolvePrivateKey((Element) currentChild, uri, storage);
+                    PrivateKey pk = 
+                        keyResolver.engineLookupAndResolvePrivateKey(
+                            (Element) currentChild, uri, storage
+                        );
 
                     if (pk != null) {
                         return pk;
                     }                    
                 }            
-                currentChild=currentChild.getNextSibling();
+                currentChild = currentChild.getNextSibling();
             }
         }
 
@@ -1137,9 +1108,6 @@ public class KeyInfo extends SignatureEl
      * @param realKeyResolver
      */
     public void registerInternalKeyResolver(KeyResolverSpi realKeyResolver) {
-        if (internalKeyResolvers==null) {
-            internalKeyResolvers=new ArrayList();
-        }
         this.internalKeyResolvers.add(realKeyResolver);
     }
 
@@ -1148,8 +1116,6 @@ public class KeyInfo extends SignatureEl
      * @return the length of the key
      */
     int lengthInternalKeyResolver() {
-        if (internalKeyResolvers==null)
-            return 0;
         return this.internalKeyResolvers.size();
     }
 
@@ -1160,7 +1126,7 @@ public class KeyInfo extends SignatureEl
      * @return the KeyResolverSpi for the index.
      */
     KeyResolverSpi itemInternalKeyResolver(int i) {
-        return (KeyResolverSpi) this.internalKeyResolvers.get(i);
+        return this.internalKeyResolvers.get(i);
     }
 
     /**

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java?rev=1070849&r1=1070848&r2=1070849&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java
(original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java
Tue Feb 15 11:36:35 2011
@@ -326,7 +326,6 @@ public class KeyResolver {
     static class ResolverIterator implements Iterator<KeyResolverSpi> {
         List<KeyResolver> res;
         Iterator<KeyResolver> it;
-        int i;
 
         public ResolverIterator(List<KeyResolver> list) {
             res = list;
@@ -338,7 +337,6 @@ public class KeyResolver {
         }
 
         public KeyResolverSpi next() {
-            i++;
             KeyResolver resolver = it.next();
             if (resolver == null) {
                 throw new RuntimeException("utils.resolver.noClass");



Mime
View raw message