Example usage for org.hibernate HibernateException HibernateException

List of usage examples for org.hibernate HibernateException HibernateException

Introduction

In this page you can find the example usage for org.hibernate HibernateException HibernateException.

Prototype

public HibernateException(Throwable cause) 

Source Link

Document

Constructs a HibernateException using the given message and underlying cause.

Usage

From source file:mitm.common.hibernate.CertificateUserType.java

License:Open Source License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    try {//w w w .j  a  v  a  2  s . c o m
        byte[] encodedCert = null;
        String certificateType = null;
        String thumbprint = null;

        if (value != null) {
            if (!(value instanceof Certificate)) {
                throw new IllegalArgumentException("Object is not a Certificate.");
            }

            Certificate certificate = (Certificate) value;

            CertificateInspector inspector = new CertificateInspector(certificate);

            encodedCert = certificate.getEncoded();
            certificateType = certificate.getType();
            thumbprint = inspector.getThumbprint();
        }

        Hibernate.BINARY.nullSafeSet(st, encodedCert, index + CERTIFICATE_COLUMN);
        Hibernate.STRING.nullSafeSet(st, certificateType, index + CERTIFICATE_TYPE_COLUMN);
        Hibernate.STRING.nullSafeSet(st, thumbprint, index + THUMBPRINT_COLUMN);
    } catch (CertificateEncodingException e) {
        throw new HibernateException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new HibernateException(e);
    } catch (NoSuchProviderException e) {
        throw new HibernateException(e);
    }
}

From source file:mitm.common.hibernate.CertPathUserType.java

License:Open Source License

@Override
public Object deepCopy(Object value) throws HibernateException {
    if (value == null) {
        return null;
    }//from  w ww  .ja va  2 s. c o m
    CertPath original = (CertPath) value;

    CertPath copy = null;

    try {
        byte[] encodedCertPath = original.getEncoded();

        String certificateType = original.getType();

        CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory()
                .createCertificateFactory(certificateType);

        copy = factory.generateCertPath(new ByteArrayInputStream(encodedCertPath));
    } catch (CertificateException e) {
        throw new HibernateException(e);
    } catch (NoSuchProviderException e) {
        throw new HibernateException(e);
    }

    return copy;
}

From source file:mitm.common.hibernate.CertPathUserType.java

License:Open Source License

@Override
public Object getPropertyValue(Object component, int property) throws HibernateException {
    if (component == null) {
        return null;
    }//from  www.ja v  a  2s.  c om

    CertPath certPath = (CertPath) component;

    try {
        switch (property) {
        case CERT_PATH_COLUMN:
            return certPath.getEncoded();
        case CERT_PATH_TYPE_COLUMN:
            return certPath.getType();
        }
    } catch (CertificateEncodingException e) {
        throw new HibernateException(e);
    }

    return null;
}

From source file:mitm.common.hibernate.CertPathUserType.java

License:Open Source License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    CertPath certPath = null;/*from  ww  w .j a v  a 2  s .  c  o m*/

    byte[] encodedCertPath = rs.getBytes(names[CERT_PATH_COLUMN]);

    if (!rs.wasNull() && encodedCertPath != null) {
        String certPathType = rs.getString(names[CERT_PATH_TYPE_COLUMN]);

        try {
            CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory()
                    .createCertificateFactory(certPathType);

            certPath = factory.generateCertPath(new ByteArrayInputStream(encodedCertPath));
        } catch (CertificateException e) {
            throw new HibernateException(e);
        } catch (NoSuchProviderException e) {
            throw new HibernateException(e);
        }
    }

    return certPath;
}

From source file:mitm.common.hibernate.CertPathUserType.java

License:Open Source License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    CertPath certPath = (CertPath) value;

    try {//from   ww w  .j a  v a2 s.  c  o m
        byte[] encodedCertPath = null;
        String certPathType = null;

        if (certPath != null) {
            encodedCertPath = certPath.getEncoded();
            certPathType = certPath.getType();
        }

        Hibernate.BINARY.nullSafeSet(st, encodedCertPath, index + CERT_PATH_COLUMN);
        Hibernate.STRING.nullSafeSet(st, certPathType, index + CERT_PATH_TYPE_COLUMN);
    } catch (CertificateEncodingException e) {
        throw new HibernateException(e);
    }
}

From source file:mitm.common.hibernate.StatelessSessionAdapterImpl.java

License:Open Source License

@Override
public void saveOrUpdate(Object entity) throws HibernateException {
    throw new HibernateException("saveOrUpdate is not supported by StatelessSession.");
}

From source file:mitm.common.hibernate.X509CertificateUserType.java

License:Open Source License

@Override
public Object deepCopy(Object value) throws HibernateException {
    if (value == null) {
        return null;
    }/*from  w w  w.  ja  v a  2s . c  o  m*/

    if (!(value instanceof X509Certificate)) {
        throw new IllegalArgumentException("Object is not a X509Certificate.");
    }

    X509Certificate original = (X509Certificate) value;

    X509Certificate copy = null;

    try {
        byte[] encodedCert = original.getEncoded();

        CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory()
                .createCertificateFactory("X.509");

        copy = (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(encodedCert));
    } catch (CertificateException e) {
        throw new HibernateException(e);
    } catch (NoSuchProviderException e) {
        throw new HibernateException(e);
    }

    return copy;
}

From source file:mitm.common.hibernate.X509CertificateUserType.java

License:Open Source License

@Override
public Object getPropertyValue(Object component, int property) throws HibernateException {
    if (component == null) {
        return null;
    }/*w ww  .ja  va  2 s. c o  m*/

    if (!(component instanceof X509Certificate)) {
        throw new IllegalArgumentException("Object is not a X509Certificate.");
    }

    X509Certificate certificate = (X509Certificate) component;

    try {
        X509CertificateInspector inspector = new X509CertificateInspector(certificate);

        switch (property) {
        case NOT_BEFORE_COLUMN:
            return certificate.getNotBefore();
        case NOT_AFTER_COLUMN:
            return certificate.getNotAfter();
        case ISSUER_COLUMN:
            return inspector.getIssuerCanonical();
        case ISSUER_FRIENDLY_COLUMN:
            return inspector.getIssuerFriendly();
        case SERIAL_NUMBER_COLUMN:
            return inspector.getSerialNumberHex();
        case SUBJECT_KEY_IDENT_COLUMN:
            return getSubjectKeyIdentifierHex(inspector);
        case SUBJECT_COLUMN:
            return inspector.getSubjectCanonical();
        case SUBJECT_FRIENDLY_COLUMN:
            return inspector.getSubjectFriendly();
        case CERTIFICATE_COLUMN:
            return certificate.getEncoded();
        case THUMBPRINT_COLUMN:
            return inspector.getThumbprint();
        }
    } catch (CertificateEncodingException e) {
        throw new HibernateException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new HibernateException(e);
    } catch (NoSuchProviderException e) {
        throw new HibernateException(e);
    } catch (CertificateParsingException e) {
        throw new HibernateException(e);
    } catch (IOException e) {
        throw new HibernateException(e);
    }

    return null;
}

From source file:mitm.common.hibernate.X509CertificateUserType.java

License:Open Source License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    X509Certificate certificate = null;

    byte[] encodedCertificate = rs.getBytes(names[CERTIFICATE_COLUMN]);

    if (!rs.wasNull() && encodedCertificate != null) {
        try {/*from ww w  .  j a  v  a 2 s. c  om*/
            CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory()
                    .createCertificateFactory("X.509");

            certificate = (X509Certificate) factory
                    .generateCertificate(new ByteArrayInputStream(encodedCertificate));
        } catch (CertificateException e) {
            throw new HibernateException(e);
        } catch (NoSuchProviderException e) {
            throw new HibernateException(e);
        }
    }

    return certificate;
}

From source file:mitm.common.hibernate.X509CertificateUserType.java

License:Open Source License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    try {//from ww w.j a va 2 s .  c o m
        Date notBefore = null;
        Date notafter = null;
        String issuer = null;
        String issuerFriendly = null;
        String serial = null;
        String subjectKeyIdentifier = null;
        String subject = null;
        String subjectFriendly = null;
        byte[] encodedCert = null;
        String thumbprint = null;

        if (value != null) {
            if (!(value instanceof X509Certificate)) {
                throw new IllegalArgumentException("Object is not a X509Certificate.");
            }

            X509Certificate certificate = (X509Certificate) value;

            X509CertificateInspector inspector = new X509CertificateInspector(certificate);

            notBefore = certificate.getNotBefore();
            notafter = certificate.getNotAfter();
            issuer = inspector.getIssuerCanonical();
            issuerFriendly = inspector.getIssuerFriendly();
            serial = inspector.getSerialNumberHex();
            subjectKeyIdentifier = getSubjectKeyIdentifierHex(inspector);
            subject = inspector.getSubjectCanonical();
            subjectFriendly = inspector.getSubjectFriendly();
            encodedCert = certificate.getEncoded();
            thumbprint = inspector.getThumbprint();
        }

        Hibernate.TIMESTAMP.nullSafeSet(st, notBefore, index + NOT_BEFORE_COLUMN);
        Hibernate.TIMESTAMP.nullSafeSet(st, notafter, index + NOT_AFTER_COLUMN);
        Hibernate.STRING.nullSafeSet(st, issuer, index + ISSUER_COLUMN);
        Hibernate.STRING.nullSafeSet(st, issuerFriendly, index + ISSUER_FRIENDLY_COLUMN);
        Hibernate.STRING.nullSafeSet(st, serial, index + SERIAL_NUMBER_COLUMN);
        Hibernate.STRING.nullSafeSet(st, subjectKeyIdentifier, index + SUBJECT_KEY_IDENT_COLUMN);
        Hibernate.STRING.nullSafeSet(st, subject, index + SUBJECT_COLUMN);
        Hibernate.STRING.nullSafeSet(st, subjectFriendly, index + SUBJECT_FRIENDLY_COLUMN);
        Hibernate.BINARY.nullSafeSet(st, encodedCert, index + CERTIFICATE_COLUMN);
        Hibernate.STRING.nullSafeSet(st, thumbprint, index + THUMBPRINT_COLUMN);
    } catch (CertificateEncodingException e) {
        throw new HibernateException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new HibernateException(e);
    } catch (NoSuchProviderException e) {
        throw new HibernateException(e);
    } catch (CertificateParsingException e) {
        throw new HibernateException(e);
    } catch (IOException e) {
        throw new HibernateException(e);
    }
}