Tuesday, December 14, 2010

Install Certs

No more 'unable to find valid certification path to requested target'

Some of you may be familiar with the (not very user friendly) exception message

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

when trying to open an SSL connection to a host using JSSE. What this usually means is that the server is using a test certificate (possibly generated using keytool) rather than a certificate from a well known commercial Certification Authority such as Verisign or GoDaddy. Web browsers display warning dialogs in this case, but since JSSE cannot assume an interactive user is present it just throws an exception by default.

Certificate validation is a very important part of SSL security, but I am not writing this entry to explain the details. If you are interested, you can start by reading the Wikipedia blurb. I am writing this entry to show a simple way to talk to that host with the test certificate, if you really want to.

Basically, you want to add the server's certificate to the KeyStore with your trusted certificates. There are any number of ways to achieve that, but a simple solution is to compile and run the attached program as java InstallCert hostname, for example % java InstallCert ecc.fedora.redhat.com Loading KeyStore /usr/jdk/instances/jdk1.5.0/jre/lib/security/cacerts... Opening connection to ecc.fedora.redhat.com:443... Starting SSL handshake...

Note the source code in the article is WRONG. See below for correct source.

http://blogs.sun.com/andreas/entry/no_more_unable_to_find

Here's the correct source:

Friday, December 10, 2010

Hibernate setParameterList nudge the data type

OK, I've run into this before so I thought I would write it down this time. You do a sql query for a list of ids and they come back as big integers, but really in your object they are longs. So when you go to use the list as a parameter it will complain. However, if you do setParameterList("ids", ids, Hibernate.BIG_INTEGER) it doesn't complain. Sort of counter intuitive to me because your object id is a long. But I guess what you are telling it is what the stuff in the param list is? Whatever, it works. 

Collection<Long> ids = new ArrayList<Long>();

if (!frm.getRygs().isEmpty()) {
    Collection<Long> rygIds = reportDao
            .getSession()
            .createSQLQuery(
                    "select u.id from av_user "
                            + " u left join av_contribution c on u.contribid = c.id "
                            + " where c.redyellowgreen in (:rygs);")
            .setParameterList("rygs", toStringList(frm.getRygs()))
            .list();
    ids.addAll(rygIds);
}

if (!ids.isEmpty()) {
    List<User> users = reportDao.getSession().createQuery(
            "from User where id in (:ids) order by lastName")
            .setParameterList("ids", ids, Hibernate.BIG_INTEGER).list();

Google Refine

Amazing way to clean up messy data. Kudos to JC Mann for the heads up.

http://code.google.com/p/google-refine/

Monday, December 6, 2010

mac os x 10.5 vpn client

So MAC does have a built in PPTP client.

Creating a VPN connection for Mac OS X 10.5 Leopard

1. Click on System Preferences in the apple menu.

2. Click on the Network icon.

3. If the lock icon looks “locked”, click on it and type in your Administrator Name and password.

4. Click on the button at the bottom of the list panel to add a new service (Located just above the Lock).

5. Select VPN in the Interface drop down menu.

Friday, December 3, 2010

Common Hibernate column annotations

Common Hibernate annotations we use for PostgreSQL

@Column(name = "roomSetup", nullable = false, columnDefinition = "character varying(100) default ''")
public String getRoomSetup() {

@Column(name = "endTime")
@org.hibernate.annotations.Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDateTime")
public LocalDateTime getEndTime() {

@Column(name = "incDueDate", nullable = false, columnDefinition = "integer default 0")
public int getIncrementDueDate() {

@Column(name = "aviUpdateDate")
@org.hibernate.annotations.Type(type = "org.joda.time.contrib.hibernate.PersistentLocalDate")
public LocalDate getAviUpdateDate() {

@Column(name = "reservationId", nullable = false, columnDefinition = "bigint default 0")
public long getReservationId() {

@Column(name = "deleted", nullable = false, columnDefinition = "bool default false")
public boolean isDeleted() {

@Column(name = "time")
@org.hibernate.annotations.Type(type = "org.joda.time.contrib.hibernate.PersistentLocalTimeExact")
public LocalTime getDueTime() {

@Column(name = "price", nullable = false, columnDefinition = "double precision default 0")
public double getPrice() {

@Column(name = "unitPrice", nullable = false, columnDefinition = "real default 0")
float unitPrice;