Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package de.hshannover.f4.trust.ifmapj;
  
  /*
   * #%L
   * =====================================================
   *   _____                _     ____  _   _       _   _
   *  |_   _|_ __ _   _ ___| |_  / __ \| | | | ___ | | | |
   *    | | | '__| | | / __| __|/ / _` | |_| |/ __|| |_| |
   *    | | | |  | |_| \__ \ |_| | (_| |  _  |\__ \|  _  |
  *    |_| |_|   \__,_|___/\__|\ \__,_|_| |_||___/|_| |_|
  *                             \____/
  * 
  * =====================================================
  * 
  * Hochschule Hannover
  * (University of Applied Sciences and Arts, Hannover)
  * Faculty IV, Dept. of Computer Science
  * Ricklinger Stadtweg 118, 30459 Hannover, Germany
  * 
  * Email: trust@f4-i.fh-hannover.de
  * Website: http://trust.f4.hs-hannover.de
  * 
  * This file is part of IfmapJ, version 1.0.0, implemented by the Trust@HsH
  * research group at the Hochschule Hannover.
  * 
  * IfmapJ is a lightweight, platform-independent, easy-to-use IF-MAP client
  * library for Java. IF-MAP is an XML based protocol for sharing data across
  * arbitrary components, specified by the Trusted Computing Group. IfmapJ is
  * maintained by the Trust@HsH group at the Hochschule Hannover. IfmapJ
  * was developed within the ESUKOM research project.
  * %%
  * Copyright (C) 2010 - 2013 Trust@HsH
  * %%
  * 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.
  * #L%
  */
 
 import java.io.File;
 
 
To create a de.hshannover.f4.trust.ifmapj.channel.SSRC one needs to have javax.net.ssl.KeyManager and javax.net.ssl.TrustManager instances. This is a helper class to make it easy to get those.

Author(s):
aw
 
 public abstract class IfmapJHelper {

Creates javax.net.ssl.KeyManager instances based on the javax.net.ssl.keyStore and javax.net.ssl.keyStorePassword environment variables.

 
 	public static KeyManager[] getKeyManagers() throws InitializationException {
 		String file = System.getProperty("javax.net.ssl.keyStore");
 		String pass = System.getProperty("javax.net.ssl.keyStorePassword");
 		
 		if (file == null || pass == null)
 			throw new InitializationException("javax.net.ssl.keyStore / " +
 					"javax.net.ssl.keyStorePassword not set");
 		
 		return getKeyManagers(filepass);
 	}

Creates javax.net.ssl.KeyManager instances based on the given parameters.

Parameters:
keyStoreFile path to keyStore file
pass password for keyStore
Returns:
an array of javax.net.ssl.KeyManager instances
Throws:
de.hshannover.f4.trust.ifmapj.exception.InitializationException
	public static KeyManager[] getKeyManagers(String keyStoreFileString pass)
		return getKeyManagers(getFileAsInputStream(keyStoreFile), pass);
	}

Creates javax.net.ssl.KeyManager instances based on the given parameters.

Parameters:
keyStoreIs java.io.InputStream representing contents of a keyStore
pass password for the keyStore
Returns:
an array of javax.net.ssl.KeyManager instances
Throws:
de.hshannover.f4.trust.ifmapj.exception.InitializationException
	public static KeyManager[] getKeyManagers(InputStream keyStoreIsString pass)
		if (keyStoreIs == null || pass == null)
			throw new NullPointerException("parameters null?");
		try {
			String defaultAlgo = KeyManagerFactory.getDefaultAlgorithm();
			KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgo);
			KeyStore ks = loadKeyStore(keyStoreIspass);
			kmf.init(kspass.toCharArray());
			return kmf.getKeyManagers();
catch (Exception e) {
		}
	}

Creates javax.net.ssl.TrustManager instances based on the javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword environment variables.

	public static TrustManager[] getTrustManagers() throws InitializationException {
		String file = System.getProperty("javax.net.ssl.trustStore");
		String pass = System.getProperty("javax.net.ssl.trustStorePassword");
		if (file == null || pass == null)
			throw new InitializationException("javax.net.ssl.trustStore / " +
					"javax.net.ssl.trustStorePassword not set");
		return getTrustManagers(filepass);
	}

Creates javax.net.ssl.TrustManager instances based on the given parameters.

Parameters:
trustStorePath path to trustStore
pass password for trustStore
Returns:
an array of javax.net.ssl.TrustManager instances
Throws:
de.hshannover.f4.trust.ifmapj.exception.InitializationException
	public static TrustManager[] getTrustManagers(String trustStorePathString pass
			return getTrustManagers(getFileAsInputStream(trustStorePath), pass);
	}

Creates javax.net.ssl.TrustManager instances based on the given parameters.

Parameters:
trustStoreIs java.io.InputStream representing contents of a trustStore
pass password for the trustStore
Returns:
an array of javax.net.ssl.TrustManager instances
Throws:
de.hshannover.f4.trust.ifmapj.exception.InitializationException
	public static TrustManager[] getTrustManagers(InputStream trustStoreIsString pass)
		if (trustStoreIs == null || pass == null)
			throw new NullPointerException("parameters null?");
		try {
			String defaultAlgo = TrustManagerFactory.getDefaultAlgorithm();
			TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgo);
			KeyStore ks = loadKeyStore(trustStoreIspass);
			tmf.init(ks);
			return tmf.getTrustManagers();
catch (Exception e) {
		}
	}

Helper to load a java.security.KeyStore instance.

Parameters:
is java.io.InputStream representing contents of a keyStore
pass the password of the keyStore
Returns:
an instance of the new loaded java.security.KeyStore
Throws:
java.security.NoSuchAlgorithmException
java.security.cert.CertificateException
java.io.IOException
java.security.KeyStoreException
	private static KeyStore loadKeyStore(InputStream isString pass)
			KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
			ks.load(ispass.toCharArray());
			return ks;
	}

Helper to open a usual File to get the content as java.io.InputStream

Parameters:
file the name of the file
Returns:
an java.io.InputStream that points to the file
Throws:
de.hshannover.f4.trust.ifmapj.exception.InitializationException
		if (file == null)
			throw new NullPointerException("file is null");
		try {
			return new FileInputStream(new File(file));
catch (FileNotFoundException e) {
			throw new InitializationException("File not found: " + file);
		}
	}
New to GrepCode? Check out our FAQ X