1 /* 2 * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.] 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.opensaml.security; 18 19 import org.opensaml.saml2.metadata.provider.MetadataProvider; 20 import org.opensaml.xml.util.AbstractWrappedSingletonFactory; 21 22 /** 23 * Singleton factory for producing instances of {@link MetadataCredentialResolver} 24 * based on a given instance of {@link MetadataProvider}. 25 * 26 * <p> 27 * Only once instance of a metadata credential resolver will exist for 28 * each metadata provider instance. 29 * </p> 30 */ 31 public class MetadataCredentialResolverFactory 32 extends AbstractWrappedSingletonFactory<MetadataProvider, MetadataCredentialResolver> { 33 34 /** The global instance of the factory itself. */ 35 private static MetadataCredentialResolverFactory factory; 36 37 /** 38 * Constructor. 39 * 40 * This constructor hides the superclass public constructor, forcing 41 * the single, global factory instance to be obtained from {@link #getFactory()}. 42 * 43 */ 44 protected MetadataCredentialResolverFactory() { 45 super(); 46 } 47 48 /** 49 * Return the global factory instance. 50 * 51 * @return the global factory instance 52 */ 53 public static synchronized MetadataCredentialResolverFactory getFactory() { 54 if (factory == null) { 55 factory = new MetadataCredentialResolverFactory(); 56 } 57 return factory; 58 } 59 60 /** {@inheritDoc} */ 61 protected MetadataCredentialResolver createNewInstance(MetadataProvider metadataProvider) { 62 return new MetadataCredentialResolver(metadataProvider); 63 } 64 65 }