Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.wss4j.common.crypto;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import org.apache.wss4j.common.ext.WSSecurityException;
import org.apache.wss4j.common.util.Loader;
/**
* CryptoFactory.
*/
public abstract class CryptoFactory {
private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(CryptoFactory.class);
static {
WSProviderConfig.init();
}
/**
* getInstance
*
* Returns an instance of Crypto. This method uses the file
* crypto.properties to determine which implementation to
* use. Thus the property org.apache.wss4j.crypto.provider
* must define the classname of the Crypto implementation. The file
* may contain other property definitions as well. These properties are
* handed over to the Crypto implementation. The file
* crypto.properties is loaded with the
* Loader.getResource() method.
*
*
* @return The crypto implementation was defined
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
public static Crypto getInstance() throws WSSecurityException {
return getInstance("crypto.properties");
}
/**
* getInstance
*
* Returns an instance of Crypto. The properties are handed over the the crypto
* implementation. The properties must at least contain the Crypto implementation
* class name as the value of the property : org.apache.wss4j.crypto.provider
*
*
* @param properties The Properties that are forwarded to the crypto implementation
* and the Crypto impl class name.
* These properties are dependent on the crypto implementation
* @return The cyrpto implementation or null if no cryptoClassName was defined
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
public static Crypto getInstance(Properties properties) throws WSSecurityException {
if (properties == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cannot load Crypto instance as properties object is null");
}
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
"empty", new Object[] {"Cannot load Crypto instance as properties object is null"});
}
return getInstance(properties, Loader.getClassLoader(CryptoFactory.class), null);
}
/**
* getInstance
*
* Returns an instance of Crypto loaded with the given classloader.
* The properties are handed over the the crypto implementation.
* The properties must at least contain the Crypto implementation
* class name as the value of the property : org.apache.wss4j.crypto.provider
*
*
* @param properties The Properties that are forwarded to the crypto implementation
* and the Crypto impl class name.
* These properties are dependent on the crypto implementation
* @param classLoader The class loader to use
* @param passwordEncryptor The PasswordEncryptor to use to decrypt encrypted passwords
* @return The crypto implementation or null if no cryptoClassName was defined
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
public static Crypto getInstance(
Properties properties,
ClassLoader classLoader,
PasswordEncryptor passwordEncryptor
) throws WSSecurityException {
if (properties == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cannot load Crypto instance as properties object is null");
}
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
"empty", new Object[] {"Cannot load Crypto instance as properties object is null"});
}
String cryptoClassName = properties.getProperty("org.apache.wss4j.crypto.provider");
if (cryptoClassName == null) {
cryptoClassName = properties.getProperty("org.apache.ws.security.crypto.provider");
}
Class extends Crypto> cryptoClass = null;
if (cryptoClassName == null
|| cryptoClassName.equals("org.apache.wss4j.common.crypto.Merlin")
|| cryptoClassName.equals("org.apache.ws.security.components.crypto.Merlin")) {
try {
return new Merlin(properties, classLoader, passwordEncryptor);
} catch (java.lang.Exception e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Unable to instantiate Merlin", e);
}
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, e, "empty",
new Object[] {"Cannot create Crypto class " + cryptoClassName});
}
} else {
try {
// instruct the class loader to load the crypto implementation
cryptoClass = Loader.loadClass(cryptoClassName, Crypto.class);
} catch (ClassNotFoundException ex) {
if (LOG.isDebugEnabled()) {
LOG.debug(ex.getMessage(), ex);
}
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, ex,
"empty", new Object[] {cryptoClassName + " Not Found"});
}
}
return loadClass(cryptoClass, properties, classLoader);
}
/**
* getInstance
*
* Returns an instance of Crypto. The supplied map is handed over the the crypto
* implementation. The map can be null. It is dependent on the
* Crypto implementation how the initialization is done in this case.
*
*
* @param cryptoClass This is the crypto implementation class. No default is
* provided here.
* @param map The Maps that is forwarded to the crypto implementation.
* These contents of the map are dependent on the
* underlying crypto implementation specified in the
* cryptoClassName parameter.
* @return The crypto implementation or null if no cryptoClassName was defined
* @throws WSSecurityException if there is an error in loading the crypto properties
*/
public static Crypto getInstance(
Class extends Crypto> cryptoClass,
Map