Example usage for java.security KeyStoreException getCause

List of usage examples for java.security KeyStoreException getCause

Introduction

In this page you can find the example usage for java.security KeyStoreException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:mitm.application.djigzo.workflow.impl.KeyAndCertificateWorkflowImpl.java

@Override
public void getPFX(final Collection<X509Certificate> certificates, final char[] password,
        final boolean includeRoot, final OutputStream pfx) throws KeyStoreException {
    Check.notNull(certificates, "certificates");
    Check.notNull(password, "password");

    try {//from w  w  w .  ja v  a2 s .c o  m
        getActionExecutor().executeTransaction(new DatabaseVoidAction() {
            @Override
            public void doAction(Session session) throws DatabaseException {
                try {
                    Session previousSession = getSessionManager().getSession();

                    getSessionManager().setSession(session);

                    try {
                        getPFXTransacted(certificates, password, includeRoot, pfx);
                    } finally {
                        /* restore the session */
                        getSessionManager().setSession(previousSession);
                    }
                } catch (KeyStoreException e) {
                    throw new DatabaseException(e);
                }
            }
        });
    } catch (DatabaseException e) {
        Throwable cause = e.getCause();

        if (cause == null) {
            cause = e;
        }

        if (cause instanceof KeyStoreException) {
            throw (KeyStoreException) cause;
        }

        throw new KeyStoreException(cause);
    }
}

From source file:mitm.application.djigzo.workflow.impl.KeyAndCertificateWorkflowImpl.java

@Override
public int importKeyStore(final KeyStore keyStore, final MissingKey missingKey) throws KeyStoreException {
    Check.notNull(keyStore, "keyStore");
    Check.notNull(missingKey, "missingKey");

    int importedEntries = 0;

    try {//from w  w w  .  j a  v a 2  s  .c o m
        importedEntries = getActionExecutor().executeTransaction(new DatabaseAction<Integer>() {
            @Override
            public Integer doAction(Session session) throws DatabaseException {
                try {
                    Session previousSession = getSessionManager().getSession();

                    getSessionManager().setSession(session);

                    try {

                        return importKeyStoreTransacted(keyStore, missingKey);
                    } finally {
                        /* restore the session */
                        getSessionManager().setSession(previousSession);
                    }
                } catch (KeyStoreException e) {
                    throw new DatabaseException(e);
                }
            }
        });
    } catch (DatabaseException e) {
        Throwable cause = e.getCause();

        if (cause == null) {
            cause = e;
        }

        if (cause instanceof KeyStoreException) {
            throw (KeyStoreException) cause;
        }

        throw new KeyStoreException(cause);
    } catch (ConstraintViolationException e) {
        logger.warn(
                "ConstraintViolationException. A certificate was probably already in the certStore. Message: "
                        + e.getMessage());
    }

    return importedEntries;
}

From source file:be.fedict.eid.tsl.Pkcs11Token.java

public List<String> getAliases() throws KeyStoreException, NoSuchAlgorithmException, CertificateException,
        IOException, UnrecoverableEntryException {
    List<String> aliases = new LinkedList<String>();
    try {//from   w  w  w  . j  av a 2  s  . com
        this.keyStore = KeyStore.getInstance("PKCS11", this.pkcs11Provider);
    } catch (KeyStoreException e) {
        JOptionPane.showMessageDialog(null, "No keystore present: " + e.getMessage(), "PKCS#11 error",
                JOptionPane.ERROR_MESSAGE);
        throw e;
    }
    LoadStoreParameter loadStoreParameter = new Pkcs11LoadStoreParameter();
    try {
        this.keyStore.load(loadStoreParameter);
    } catch (IOException e) {
        LOG.debug("I/O error: " + e.getMessage(), e);
        Throwable cause = e.getCause();
        if (null != cause) {
            if (cause instanceof FailedLoginException) {
                JOptionPane.showMessageDialog(null, "PIN incorrect", "Login failed", JOptionPane.ERROR_MESSAGE);
            }
        }
        return aliases;
    }
    Enumeration<String> aliasesEnum = this.keyStore.aliases();
    while (aliasesEnum.hasMoreElements()) {
        String alias = aliasesEnum.nextElement();
        LOG.debug("keystore alias: " + alias);
        if (false == this.keyStore.isKeyEntry(alias)) {
            continue;
        }
        aliases.add(alias);
    }
    return aliases;
}