View | Details | Raw Unified | Return to bug 49456
Collapse All | Expand All

(-)src/org/apache/xml/security/keys/storage/StorageResolver.java (-6 / +38 lines)
Lines 22-27 Link Here
22
import java.util.ArrayList;
22
import java.util.ArrayList;
23
import java.util.Iterator;
23
import java.util.Iterator;
24
import java.util.List;
24
import java.util.List;
25
import java.util.NoSuchElementException;
25
26
26
import org.apache.xml.security.keys.storage.implementations.KeyStoreResolver;
27
import org.apache.xml.security.keys.storage.implementations.KeyStoreResolver;
27
import org.apache.xml.security.keys.storage.implementations.SingleCertificateResolver;
28
import org.apache.xml.security.keys.storage.implementations.SingleCertificateResolver;
Lines 116-123 Link Here
116
   /**
117
   /**
117
    * Method getIterator
118
    * Method getIterator
118
    * @return the iterator for the resolvers.
119
    * @return the iterator for the resolvers.
119
    *
120
     */
120
    */
121
   public Iterator getIterator() {
121
   public Iterator getIterator() {
122
122
123
      if (this._iterator == null) {
123
      if (this._iterator == null) {
Lines 132-138 Link Here
132
   /**
132
   /**
133
    * Method hasNext
133
    * Method hasNext
134
    *
134
    *
135
    * @return true if there is more elements.
135
    * @return true if there are more elements.
136
    */
136
    */
137
   public boolean hasNext() {
137
   public boolean hasNext() {
138
138
Lines 156-161 Link Here
156
156
157
   /**
157
   /**
158
    * Class StorageResolverIterator
158
    * Class StorageResolverIterator
159
    * This iterates over all the Certificates found in all the resolvers.
159
    *
160
    *
160
    * @author $Author$
161
    * @author $Author$
161
    * @version $Revision$
162
    * @version $Revision$
Lines 165-187 Link Here
165
      /** Field _resolvers */
166
      /** Field _resolvers */
166
      Iterator _resolvers = null;
167
      Iterator _resolvers = null;
167
168
169
      /** Field _currentResolver */
170
      Iterator _currentResolver = null;
171
168
      /**
172
      /**
169
       * Constructor FilesystemIterator
173
       * Constructor StorageResolverIterator
170
       *
174
       *
171
       * @param resolvers
175
       * @param resolvers
172
       */
176
       */
173
      public StorageResolverIterator(Iterator resolvers) {
177
      public StorageResolverIterator(Iterator resolvers) {
174
         this._resolvers = resolvers;
178
         this._resolvers = resolvers;
179
         _currentResolver = findNextResolver();
175
      }
180
      }
176
181
177
      /** @inheritDoc */
182
      /** @inheritDoc */
178
      public boolean hasNext() {
183
      public boolean hasNext() {
179
	  return _resolvers.hasNext();
184
         if (_currentResolver == null) {
185
            return false;
186
         }
187
            
188
         if (_currentResolver.hasNext()) {
189
            return true;
190
         }
191
192
         _currentResolver = findNextResolver();
193
         return (_currentResolver != null);
180
      }
194
      }
181
195
182
      /** @inheritDoc */
196
      /** @inheritDoc */
183
      public Object next() {
197
      public Object next() {
184
	  return _resolvers.next();
198
         if (hasNext()) {
199
            return _currentResolver.next();
200
         }
201
         
202
         throw new NoSuchElementException();
185
      }
203
      }
186
204
187
      /**
205
      /**
Lines 191-195 Link Here
191
         throw new UnsupportedOperationException(
209
         throw new UnsupportedOperationException(
192
            "Can't remove keys from KeyStore");
210
            "Can't remove keys from KeyStore");
193
      }
211
      }
212
213
      // Find the next storage with at least one element and return its Iterator
214
      private Iterator findNextResolver() {
215
         
216
         while (_resolvers.hasNext()) {
217
            StorageResolverSpi resolverSpi = (StorageResolverSpi)_resolvers.next();
218
            Iterator iter = resolverSpi.getIterator();
219
            if (iter.hasNext()) {
220
               return iter;
221
            }
222
         }
223
         
224
         return null;
225
      }
194
   }
226
   }
195
}
227
}
(-)src_unitTests/org/apache/xml/security/test/ModuleTest.java (+1 lines)
Lines 61-66 Link Here
61
      suite.addTest(org.apache.xml.security.test.keys.content.x509.XMLX509IssuerSerialTest.suite());
61
      suite.addTest(org.apache.xml.security.test.keys.content.x509.XMLX509IssuerSerialTest.suite());
62
      suite.addTest(org.apache.xml.security.test.keys.content.x509.XMLX509CertificateTest.suite());
62
      suite.addTest(org.apache.xml.security.test.keys.content.x509.XMLX509CertificateTest.suite());
63
      suite.addTest(org.apache.xml.security.test.keys.storage.KeyStoreResolverTest.suite());
63
      suite.addTest(org.apache.xml.security.test.keys.storage.KeyStoreResolverTest.suite());
64
      suite.addTest(org.apache.xml.security.test.keys.storage.StorageResolverTest.suite());
64
      // suite.addTest(org.apache.xml.security.test.algorithms.implementations.KeyWrapTest.suite());
65
      // suite.addTest(org.apache.xml.security.test.algorithms.implementations.KeyWrapTest.suite());
65
      // suite.addTest(org.apache.xml.security.test.algorithms.implementations.BlockEncryptionTest.suite());
66
      // suite.addTest(org.apache.xml.security.test.algorithms.implementations.BlockEncryptionTest.suite());
66
      //J+
67
      //J+
(-)src_unitTests/org/apache/xml/security/test/keys/storage/StorageResolverTest.java (+82 lines)
Line 0 Link Here
1
/*
2
 * Copyright  2008-2010 The Apache Software Foundation.
3
 *
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 *  you may not use this file except in compliance with the License.
6
 *  You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *  Unless required by applicable law or agreed to in writing, software
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *  See the License for the specific language governing permissions and
14
 *  limitations under the License.
15
 *
16
 */
17
package org.apache.xml.security.test.keys.storage;
18
19
import java.io.FileInputStream;
20
import java.security.KeyStore;
21
import java.security.cert.X509Certificate;
22
import java.util.NoSuchElementException;
23
24
import junit.framework.Test;
25
import junit.framework.TestCase;
26
import junit.framework.TestSuite;
27
28
import org.apache.xml.security.keys.storage.StorageResolver;
29
30
/**
31
 * KeyStore StorageResolver test.
32
 */
33
public class StorageResolverTest extends TestCase {
34
35
	private static final String BASEDIR = System.getProperty("basedir");
36
	private static final String SEP = System.getProperty("file.separator");
37
38
	public StorageResolverTest() {
39
		super("KeyStoreResolverTest");
40
	}
41
42
	public StorageResolverTest(String name) {
43
		super(name);
44
	}
45
46
	public static Test suite() {
47
		return new TestSuite(StorageResolverTest.class);
48
	}
49
50
	public void testStorageResolver() throws Exception {
51
52
		String inputDir = BASEDIR + SEP + "data" + SEP
53
				+ "org" + SEP + "apache" + SEP + "xml" + SEP + "security" + SEP
54
				+ "samples" + SEP + "input";
55
56
		FileInputStream inStream = new FileInputStream(inputDir + SEP + "keystore.jks");
57
		KeyStore ks = KeyStore.getInstance("JKS");
58
		ks.load(inStream, "xmlsecurity".toCharArray());
59
60
		FileInputStream inStream2 = new FileInputStream(inputDir + SEP + "keystore2.jks");
61
		KeyStore ks2 = KeyStore.getInstance("JCEKS");
62
		ks2.load(inStream2, "xmlsecurity".toCharArray());
63
64
		StorageResolver storage = new StorageResolver(ks);
65
		storage.add(ks2);
66
		
67
		int count = 0;
68
		while (storage.hasNext()) {
69
			X509Certificate cert = storage.next();
70
			assertNotNull(cert);
71
			count++;
72
		}
73
74
		assertEquals(4, count);
75
		
76
		try {
77
			storage.next();
78
			fail("Expecting NoSuchElementException");
79
		} catch (NoSuchElementException e) {
80
		}
81
	}
82
}

Return to bug 49456