Sunday, 17 May 2009

Forcing comments in Subversion

While administering Subversion is a simple task, getting all developers to add comments to their subversion is not. The importance of having comments while checking-in their code helps especially in an Agile environment where in there may be several check ins during the day and comments are an important tool in communicating what was done. Fortunately for those forgetful developers, there is help at hand to enforce commenting during a check-in.

A simple script available in a dormant form with every Subversion installation works the magic. The operation of the script is explained very clearly in this blog post. The script is present in the pre-commit.tmpl file in the /{repository-location}/hooks/ directory. To get it to fire, make sure the script has commands that are valid DOS commands (if you are in a Windows environment) AND re-name the file to pre-commit.bat. That's it. Every check-in will require a comment!!

Sunday, 10 May 2009

Hibernate Annotations : A powerful addition to the Hibernate family.

I recently used Hibernate Annotations in a project and was impressed by the power and relative flexibility offered by annotations and the difference it made with regards to cleaning up the project build. While the major advantage of using annotations was that I could completely get rid of the hibernate mapping xmls, it also made life easier when it came to specifying relationships between my entity beans.

To get started with Hibernate Annotations, follow the Hibernate learning trail and download the required jars and set up your project. If you are using Maven, you can specify the dependencies in a Maven POM as outlined in this example. Once you have a project set up, take a look at this reference guide. Mapping entity bean associations and relationships is simple and this is a good example that demonstrates the annotation entries for mapping different relationships. One major advantage of using Annotations is that several mappings and associations can be configured by default. For example, if I defined a primary key mapping of an entity bean to a database as follows:
@Id
public Long getId() {
return id;
}
and left out @GeneratedValue(strategy=GenerationType.AUTO)

Hibernate would assume that the application will provide the Primary Key or in other words, the strategy for the primary key, if I were to specify the same in an hbm file would be equivalent to "assigned". Similarly, If the Annotation @Table(name="EMPLOYEE") on a bean can be used to map the bean to the table EMPLOYEE but if not given, the name of the bean would be used as a key by Hibernate for mapping the table to a bean.

Thus, Hibernate Annotations reduces the setup time in adding Hibernate to a project while simplifying the maintenance of the associated code.

Saturday, 21 March 2009

Integrating Spring Security with Active Directory on JBOSS 4.0.5

Spring Security (formely ACEGI) is a fairly robust and flexible framework that fits in well with a J2EE solution stack. Some of the main features that made us choose Spring was its flow transition authorization policy and its database backed 'remember me' implementation.
Based on this, we decided to use Spring Security 2.0.4 on a JBOSS 4.0.5 server. The Spring component authenticates and authorizes a user against a Active Directory through its LDAP authenticator component (org.springframework.security.providers.ldap.authenticator.BindAuthenticator) and authorize the user using its LDAP authorities search classes (org.springframework.security.ldap.populator.DefaultLdapAuthoritiesPopulator & org.springframework.security.providers.ldap.LdapAuthenticationProvider).

The important thing to remember is that Spring security matches a group name with the prefix "ROLE_" so if you have a user belonging to a group called "PG_JAVA_DEV), it would get mapped as ROLE_PG_JAVA_DEV within the security context. You can get more information on how the Spring security LDAP component works in Chapter 10 of the Spring Security guide.A detailed example of how to set up Spring Security to talk to the Active Directory is given here.

To set up Spring Security, you will need Spring Security 2.0.4 and Spring LDAP 1.3 (which has some additional dependencies mapped in them).Just map these to your Maven POM and you'll be good to go.

Monday, 2 February 2009

Australian Open 2009: Rafa aces the FedEx yet again

Incredible! This one word sums up Rafa's game in the Australian Open 2009 final. As Jim Courier put it "How is this guy even on his feet?". But on his feet he was and for more than 18 hours 54 minutes of playing time which included close to 10 hours in the last 48 hours of the Open.
Incredible athleticism combined with a die-hard must win attitude cracked Federer's normally impassive veneer to make him visibly nervous and suddenly the 14th major for the FedEx looked further away. Federer's first serve percentage kept dropping and the double faults crept up to hurt him at crucial junctures and when he hit one long after saving three championship points, he handed the Australian Open to Rafa.
While Rafa has been gracious enough to acknowledge Federer as the 'greatest ever', it now appears as if it will be Rafa who now has a realistic chance of completing a Grand Slam in 2009. Also, Rafa has now beaten Federer in their last five encounters. If Federer wants to confirm his place as the 'greatest ever' in history, he will have to break this wall down or stand by and witness Rafa's elevation to that epithet.