All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ws.security.saml.SAMLIssuerFactory Maven / Gradle / Ivy

Go to download

Apache WSS4J is an implementation of the Web Services Security (WS-Security) being developed at OASIS Web Services Security TC. WSS4J is a primarily a Java library that can be used to sign and verify SOAP Messages with WS-Security information. WSS4J will use Apache Axis and Apache XML-Security projects and will be interoperable with JAX-RPC based server/clients and .NET server/clients.

There is a newer version: 1.6.19
Show newest version
/*
 * Copyright  2003-2004 The Apache Software Foundation.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package org.apache.ws.security.saml;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.security.util.Loader;
import org.apache.ws.security.saml.SAMLIssuer;

import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.Properties;

/**
 * CryptoFactory.
 * 

* * @author Davanum Srinivas ([email protected]). */ public abstract class SAMLIssuerFactory { private static Log log = LogFactory.getLog(SAMLIssuerFactory.class); private static final String defaultSAMLClassName = "org.apache.ws.security.saml.WSSSAMLIssuerImpl"; /** * getInstance *

* Returns an instance of SAMLIssuer. This method uses the file * saml.properties to determine which implementation to * use. Thus the property org.apache.ws.security.saml.issuerClass * must define the classname of the SAMLIssuer implementation. The file * may contain other property definitions as well. These properties are * handed over to the SAMLIssuer implementation. The file * saml.properties is loaded with the * Loader.getResource() method. *

* * @return The SAMLIssuer implementation was defined */ public static SAMLIssuer getInstance() { return getInstance("saml.properties"); } /** * getInstance *

* Returns an instance of SAMLIssuer. The properties are handed over the the SAMLIssuer * implementation. The porperties can be null. It is depenend on the * SAMLIssuer implementation how the initialization is done in this case. *

* * @param samlClassName This is the SAMLIssuer implementation class. No default is * provided here. * @param properties The Properties that are forwarded to the SAMLIssuer implementaion. * These properties are dependend on the SAMLIssuer implementatin * @return The SAMLIssuer implementation or null if no samlClassName was defined */ public static SAMLIssuer getInstance(String samlClassName, Properties properties) { return loadClass(samlClassName, properties); } /** * getInstance *

* Returns an instance of SAMLIssuer. This method uses the specifed filename * to load a property file. This file shall use the property * org.apache.ws.security.saml.issuerClass * to define the classname of the SAMLIssuer implementation. The file * may contain other property definitions as well. These properties are * handed over to the SAMLIssuer implementation. The specified file * is loaded with the Loader.getResource() method. *

* * @param propFilename The name of the property file to load * @return The SAMLIssuer implementation that was defined */ public static SAMLIssuer getInstance(String propFilename) { Properties properties = null; String samlClassName = null; if ((samlClassName == null) || (samlClassName.length() == 0)) { properties = getProperties(propFilename); samlClassName = properties.getProperty("org.apache.ws.security.saml.issuerClass", defaultSAMLClassName); } return loadClass(samlClassName, properties); } private static SAMLIssuer loadClass(String samlClassName, Properties properties) { Class samlIssuerClass = null; SAMLIssuer samlIssuer = null; try { // instruct the class loader to load the crypto implementation samlIssuerClass = Loader.loadClass(samlClassName); } catch (ClassNotFoundException e) { throw new RuntimeException(samlClassName + " Not Found"); } log.info("Using Crypto Engine [" + samlClassName + "]"); try { Class[] classes = new Class[]{Properties.class}; Constructor c = samlIssuerClass.getConstructor(classes); samlIssuer = (SAMLIssuer) c.newInstance(new Object[]{properties}); return samlIssuer; } catch (java.lang.Exception e) { e.printStackTrace(); log.error(e); } try { // try to instantiate the Crypto subclass samlIssuer = (SAMLIssuer) samlIssuerClass.newInstance(); return samlIssuer; } catch (java.lang.Exception e) { e.printStackTrace(); log.error(e); throw new RuntimeException(samlClassName + " cannot create instance"); } } /** * Gets the properties for SAML issuer. * The functions loads the property file via * {@link Loader.getResource(String)}, thus the property file * should be accesible via the classpath * * @param propFilename the properties file to load * @return a Properties object loaded from the filename */ private static Properties getProperties(String propFilename) { Properties properties = new Properties(); try { URL url = Loader.getResource(propFilename); properties.load(url.openStream()); } catch (Exception e) { log.debug("Cannot find SAML property file: " + propFilename); throw new RuntimeException("SAMLIssuerFactory: Cannot load properties: " + propFilename); } return properties; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy