Sunday, October 24, 2010

Spring 3 Security

Use java 1.5 or higher when using spring 3 security. The most fundamental object in spring security is Security Context Holder. Security Context Holder use ThreadLocal to store security information. Inside Security Context Holder Authentication object is used to store principle information which currently interact with the application.

UserDetail is an Central Interface which can provide userInformation like email , employee number etc.. To provide those Information You need to provide the userService inside the spring context. You can include a custom userService by implementing UserDetailService interface. It has following method.
UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
Spring provide Some UserService based on Memory Map and JdbcDao. You can use those or you can implement your own.

Wednesday, October 6, 2010

Spring Dependecy Lookup in a servlet

@Override
public void init() throws ServletException {
super.init();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
bonusTypeRepository = (BonusTypeRepository)ctx.getBean("bonusTypeRepository");
bonusCategoryRepository = (BonusCategoryRepository)ctx.getBean("bonusCategoryRepository");
}

Sunday, September 26, 2010

Hibernate with JPA annotation

Hibernate with JPA annotation is interesting. We no need to worry about mapping configuration files. Simply do it in java source with annotations. I used maven hibernate plugin to setup a project. Here is my pom.xml

Friday, September 10, 2010

Vaadin

Vaadin is a java frame work for building web UI (RIA -> Rich Internet Application). With Vaadin you can develop a web UI without knowing any httml or java script. This is similer to Java Swing UI creation. Vaadin internally use GWT to generate web content. Server is communicated with clients web browser through a java script with AJAX runinng in a web browser. But developer doest not need to know java script or AJAX. Vaadin generate those when the java code compile and when it running.

The Vaadin library defines a clear separation between user interface presentation and logic and allows you to develop them separately.

Creating Vaadin Project with Maven

mvn archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-clean -DarchetypeVersion=LATEST -DgroupId=your.company -DartifactId=project-name -Dversion=1.0 -Dpackaging=war

Running the application

mvn clean package jetty:run

Sunday, July 4, 2010

jspx EL is not working (Resolved)

I had to expend a long time to understand why EL is not working in my jspx. I tested all the dependencies and jsp files and with differnet different vision of spring distributions. Finlay I understood what the wrong is in my DD. I have given a old declaration which I have copied from some where. I did not believe that will be an issue.


So my advice is use correct XML declaration according to the version that you are using.

I used spring 2.5.6 and used the web xml declaration as below

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"

</web-app>

OK keep in mind these declaration is very much improtent in spring context and jspx also.
Spring Context Config XML should have declaration as below.

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

Now in jspx it should be like this.

<?xml version="1.0" encoding='utf-8'?>
<jsp:root version="2.0"
xmlns="http://www.w3c.org/1999/xhtml"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:spring="http://www.springframework.org/tags"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:decorator="http://www.opensymphony.com/sitemesh/decorator"
xmlns:authz="http://www.springframework.org/security/tags"
xmlns:form="http://www.springframework.org/tags/form"
xmlns:c="http://java.sun.com/jstl/core_rt"
xsi:schemaLocation="http://www.w3c.org/1999/xhtml http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd">