Package java.security

Examples of java.security.KeyManagementException


     * Test for <code>KeyManagementException(String, Throwable)</code>
     * constructor Assertion: constructs KeyManagementException when
     * <code>cause</code> is null <code>msg</code> is not null
     */
    public void testKeyManagementException07() {
        KeyManagementException tE;
        for (int i = 0; i < msgs.length; i++) {
            tE = new KeyManagementException(msgs[i], null);
            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
                    .getMessage(), msgs[i]);
            assertNull("getCause() must return null", tE.getCause());
        }
    }
View Full Code Here


     * Test for <code>KeyManagementException(String, Throwable)</code>
     * constructor Assertion: constructs KeyManagementException when
     * <code>cause</code> is not null <code>msg</code> is null
     */
    public void testKeyManagementException08() {
        KeyManagementException tE = new KeyManagementException(null, tCause);
        if (tE.getMessage() != null) {
            String toS = tCause.toString();
            String getM = tE.getMessage();
            assertTrue("getMessage() must should ".concat(toS), (getM
                    .indexOf(toS) != -1));
        }
        assertNotNull("getCause() must not return null", tE.getCause());
        assertEquals("getCause() must return ".concat(tCause.toString()), tE
                .getCause(), tCause);
    }
View Full Code Here

     * Test for <code>KeyManagementException(String, Throwable)</code>
     * constructor Assertion: constructs KeyManagementException when
     * <code>cause</code> is not null <code>msg</code> is not null
     */
    public void testKeyManagementException09() {
        KeyManagementException tE;
        for (int i = 0; i < msgs.length; i++) {
            tE = new KeyManagementException(msgs[i], tCause);
            String getM = tE.getMessage();
            String toS = tCause.toString();
            if (msgs[i].length() > 0) {
                assertTrue("getMessage() must contain ".concat(msgs[i]), getM
                        .indexOf(msgs[i]) != -1);
                if (!getM.equals(msgs[i])) {
                    assertTrue("getMessage() should contain ".concat(toS), getM
                            .indexOf(toS) != -1);
                }
            }
            assertNotNull("getCause() must not return null", tE.getCause());
            assertEquals("getCause() must return ".concat(tCause.toString()),
                    tE.getCause(), tCause);
        }
    }
View Full Code Here

            "New message",
            "Long message for Exception. Long message for Exception. Long message for Exception." };

    protected Object[] getData() {
        Exception cause = new Exception(msgs[1]);
        KeyManagementException dExc = new KeyManagementException(msgs[0], cause);
        String msg = null;
        Throwable th = null;
        return new Object[] { new KeyManagementException(), new KeyManagementException(msg),
                new KeyManagementException(msgs[1]),
                new KeyManagementException(new Throwable()), new KeyManagementException(th),
                new KeyManagementException(msgs[1], dExc) };
    }
View Full Code Here

    private boolean init = false;
    @Override
    protected void engineInit(KeyManager[] km, TrustManager[] tm,
            SecureRandom sr) throws KeyManagementException {
        if (sr == null) {
            throw new KeyManagementException(
                    "secureRandom is null");
        }
        init = true;
    }
View Full Code Here

    private boolean init = false;
    @Override
    protected void engineInit(KeyManager[] km, TrustManager[] tm,
            SecureRandom sr) throws KeyManagementException {
        if (sr == null) {
            throw new KeyManagementException(
                    "secureRandom is null");
        }
        init = true;
    }
View Full Code Here

                        keyManager = (X509KeyManager)kms[i];
                        break;
                    }
                }
                if (keyManager == null) {
                    throw new KeyManagementException("No X509KeyManager found");
                }
                if (initialize_default) {
                    // found keyManager is default key manager
                    defaultKeyManager = keyManager;
                }
            }
           
            // initialize trust manager
            initialize_default = false;
            if ((tms == null) || (tms.length == 0)) {
                if (defaultTrustManager == null) {
                    TrustManagerFactory tmf = TrustManagerFactory
                        .getInstance(TrustManagerFactory.getDefaultAlgorithm());
                    tmf.init((KeyStore)null);
                    tms = tmf.getTrustManagers();
                    initialize_default = true;
                } else {
                    trustManager = defaultTrustManager;
                }
            }
            if (trustManager == null) { // was not initialized by default
                for (int i = 0; i < tms.length; i++) {
                    if (tms[i] instanceof X509TrustManager) {
                        trustManager = (X509TrustManager)tms[i];
                        break;
                    }
                }
                if (trustManager == null) {
                    throw new KeyManagementException("No X509TrustManager found");
                }
                if (initialize_default) {
                    // found trustManager is default trust manager
                    defaultTrustManager = trustManager;
                }
            }
        } catch (NoSuchAlgorithmException e) {
            throw new KeyManagementException(e);
        } catch (KeyStoreException e) {
            throw new KeyManagementException(e);
        } catch (UnrecoverableKeyException e) {
            throw new KeyManagementException(e);         
        }
        // initialize secure random
        if (sr == null) {
            if (defaultSecureRandom == null) {
              defaultSecureRandom = new SecureRandom();
View Full Code Here

            throw new NullPointerException(Messages.getString("security.92")); //$NON-NLS-1$
        }

        String name = identity.getName();
        if (names.containsKey(name)) {
            throw new KeyManagementException(Messages.getString("security.93", name)); //$NON-NLS-1$
        }

        PublicKey key = identity.getPublicKey();
        if (key != null && keys.containsKey(key)) {
            throw new KeyManagementException(Messages.getString("security.94", key)); //$NON-NLS-1$
        }

        names.put(name, identity);
        if (key != null) {
            keys.put(key, identity);
View Full Code Here

            contains = contains || keys.containsKey(key);
            keys.remove(key);
        }
       
        if (!contains) {
            throw new KeyManagementException(Messages.getString("security.96")); //$NON-NLS-1$
        }
    }
View Full Code Here

                        keyManager = (X509KeyManager)kms[i];
                        break;
                    }
                }
                if (keyManager == null) {
                    throw new KeyManagementException("No X509KeyManager found");
                }
                if (initialize_default) {
                    // found keyManager is default key manager
                    defaultKeyManager = keyManager;
                }
            }
           
            // initialize trust manager
            initialize_default = false;
            if ((tms == null) || (tms.length == 0)) {
                if (defaultTrustManager == null) {
                    TrustManagerFactory tmf = TrustManagerFactory
                        .getInstance(TrustManagerFactory.getDefaultAlgorithm());
                    tmf.init((KeyStore)null);
                    tms = tmf.getTrustManagers();
                    initialize_default = true;
                } else {
                    trustManager = defaultTrustManager;
                }
            }
            if (trustManager == null) { // was not initialized by default
                for (int i = 0; i < tms.length; i++) {
                    if (tms[i] instanceof X509TrustManager) {
                        trustManager = (X509TrustManager)tms[i];
                        break;
                    }
                }
                if (trustManager == null) {
                    throw new KeyManagementException("No X509TrustManager found");
                }
                if (initialize_default) {
                    // found trustManager is default trust manager
                    defaultTrustManager = trustManager;
                }
            }
        } catch (NoSuchAlgorithmException e) {
            throw new KeyManagementException(e);
        } catch (KeyStoreException e) {
            throw new KeyManagementException(e);
        } catch (UnrecoverableKeyException e) {
            throw new KeyManagementException(e);         
        }
        // initialize secure random
        if (sr == null) {
            if (defaultSecureRandom == null) {
              defaultSecureRandom = new SecureRandom();
View Full Code Here

TOP

Related Classes of java.security.KeyManagementException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.