Transformatorhuis

September 2, 2009

Geronimo HTTPS, self signed keys and implementation in Java

Filed under: Coding, Configuration — Tags: , , , — cyberroadie @ 10:19 am

Geronimo

  • Create key in Geronimo (setup certificate)
  • CN needs to be the server name (e.g www.wordpress.com)
  • Create new Keystore (e.g wordpress)
  • In keystore create private key, again CN needs to be server name
  • Add Trust Certificate (copy paste it from the one you created before)
  • In Web Server edit the HTTPS listener and change the keystore file to the on you create before (e.g wordpress)
  • Optional: change address to fixed ip of server

Get certificate

In firefox got to https address -> Add exception -> Get Certificate -> View ->
Details -> Export: export certificate (PEM will do) (e.g. www.wordpress.com)

Shell

keytool -import -trustcacerts -storepass secretphrase -alias “Apache Geronimo Dev” -file www.wordpress.com.cer

The keystore is created in default location ${home}/.keystore

Java

System.setProperty("javax.net.ssl.trustStore", "/home/user/.keystore");
System.setProperty("javax.net.ssl.trustStorePassword","secretphrase");
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

PS Of course it shouldn’t be a static url (/home/user/.keystore), but this is for simplicities sake

January 27, 2009

Customizing hbm2java (Freemarker & Maven)

Filed under: Coding, Configuration — cyberroadie @ 4:24 pm

Copy the freemarker templates out the the hibernate-tools.jar into you maven directory tree (${basedir}).
In maven:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<componentProperties>
    ...
    <templatepath>${basedir}/templates</templatepath>
    <template>${basedir}/templates/pojo/Pojo.ftl</template>
</componentProperties>
</plugin>

The template needs to refer to the parent template, the rest is included automaticly.

Howto customize the freemarker templates

Example:
To pick up from a hibernate template (*.hbm.xml):

<property column="TestField" type="integer" name="testField">
    <meta attribute="annotation">@XmlElement</meta>
</property>

And generate:

@XmlElement
private Integer testField;

Add this in PojoFields.ftl:

<#if pojo.hasMetaAttribute(field, "annotation")>
${c2j.getMetaAsString(field, "annotation","\n")}
</#if>
${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
</#if>

Blog at WordPress.com.