001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)SecurityHelper.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: /**
030: * SecurityHelper.java
031: *
032: * SUN PROPRIETARY/CONFIDENTIAL.
033: * This software is the proprietary information of Sun Microsystems, Inc.
034: * Use is subject to license terms.
035: *
036: * Created on September 1, 2004, 12:43 PM
037: */package com.sun.jbi.internal.security.test.binding1.rt;
038:
039: import java.security.Security;
040: import java.security.Provider;
041:
042: /**
043: *
044: * @author Sun Microsystems, Inc.
045: */
046: public class SecurityHelper {
047: /**
048: * Provider Class Name
049: */
050: public static final String BOUNCY_CASTLE_PROVIDER = "org.bouncycastle.jce.provider.BouncyCastleProvider";
051:
052: /** Provider */
053: Provider mBouncyCastleProvider = null;
054:
055: /** Creates a new instance of SecurityHelper */
056: public SecurityHelper() throws Exception {
057:
058: // -- Load the Provider
059: mBouncyCastleProvider = (Provider) (Class
060: .forName(BOUNCY_CASTLE_PROVIDER)).newInstance();
061:
062: mBouncyCastleProvider.put(
063: "Alg.Alias.Cipher.RSA/ECB/OAEPWithSHA1AndMGF1Padding",
064: "RSA/OAEP");
065:
066: }
067:
068: /**
069: * Load the Bouncy Castle Provider as the second provider in the list of
070: * providers managed by java.security.Security
071: */
072: public void loadProvider() throws Exception {
073:
074: if (Security.getProviders().length >= 1) {
075: Security.insertProviderAt(mBouncyCastleProvider, 2);
076: } else {
077: Security.addProvider(mBouncyCastleProvider);
078: }
079: }
080:
081: /**
082: * Unload the Bouncy Castle Provider
083: */
084: public void unloadProvider() throws Exception {
085: Security.removeProvider(mBouncyCastleProvider.getName());
086: }
087:
088: /**
089: * Print all the Providers
090: */
091: public void printProviders() {
092: Provider[] providers = Security.getProviders();
093: StringBuffer strBuffer = new StringBuffer();
094: java.util.logging.Logger logger = java.util.logging.Logger
095: .getLogger("com.sun.jbi.stockquote.client.service");
096: for (int i = 0; i < providers.length; i++) {
097: strBuffer.append("Provider [" + i + "] = "
098: + providers[i].toString() + "\n");
099: }
100: logger.info(strBuffer.toString());
101: }
102:
103: }
|