ZappWeb a secured ZK web framework"

From Documentation
m (Created page with ''''Author:''' Ramzi Maâlej '''Date''' 18/06/2009 = '''Introdution''' = This small talk is intended to provide you a web framework to start building secure web applications.…')
(No difference)

Revision as of 01:54, 21 September 2010


Ramzi Maâlej




This small talk is intended to provide you a web framework to start building secure web applications. The idea behind this is to provide something similar to Appfuse that uses Zkoss as front end/ presentation layer. It is also based on the two small talks writen by Henri Chen showing how to integrate Spring security with Zkoss: Making Spring Security Work with ZK and Ajax Based Login with ZK and Spring Security System. It's doesn't include yet appgen to generate the redundant stuffs.


Spring framework version 3.0.0

Spring security 3.0.0

Zkoss 3.6.1


The example consists of securing the access to the private section by configuring the authentication provider to use DaoAuthenticationProvider to load authentication's informations from database. For this reasons, you have to write two classes User which implements UserDetails interface and Role which implements GranthedAuthority. Theses classes are fit in the model package. Second, you need to develop the DAO layer (look at dao package). Finally, we write the service layer (look at service layer).


First of all, as said in the previous small talks, we need to configure zk to work with spring. In zk.xml you should have the following lines

<?xml version="1.0" encoding="UTF-8"?>

	Created by ZK Studio



After that, put in your web.xml the followings lines


      - Spring Security Filter Chains


In the next step we will configure a data connection to be used by JPA. Your applicationContext-jpa.xml should look like this one

    <bean id="dataSource"
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/lms" />
		<property name="username" value="ramzi" />
		<property name="password" value="kantoul" />

	<!-- JPA EntityManagerFactory -->
	<bean id="entityManagerFactory"
		<property name="dataSource" ref="dataSource" />
		<property name="jpaVendorAdapter">
			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
				<property name="generateDdl" value="true" />
				<property name="database" value="MYSQL" />
				<property name="showSql" value="true" />
		<property name="loadTimeWeaver">
				class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />

		Transaction manager for a single JPA EntityManagerFactory (alternative
		to JTA)
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />

	<!-- post-processors for all standard config annotations -->
		class="" />

		Instruct Spring to perform declarative transaction management
		automatically on annotated classes.
	<tx:annotation-driven transaction-manager="transactionManager" />

		Activates various annotations to be detected in bean classes: Spring's
		@Required and @Autowired, as well as JSR 250's @PostConstruct,
		@PreDestroy and @Resource (if available) and JPA's @PersistenceContext
		and @PersistenceUnit (if available).
	<context:annotation-config />

We define a datasource bean to connect to the database and then we define the EntityManagerFactory to use this datasource with the JPAVendor.

Finally, we need to add some stuffs to applicationContext-security.xml.

		<security:intercept-url pattern="/" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
		<security:intercept-url pattern="/login.zul" access="IS_AUTHENTICATED_ANONYMOUSLY" />
                <security:intercept-url pattern="/admin/**" access="ROLE_ADMIN" />
		<security:intercept-url pattern="/privatesection.zul" access="ROLE_ADMIN" />
		<security:form-login login-page="/login.zul" default-target-url="/privatesection.zul" authentication-failure-url="/accessDenied.zul"/>
		<security:concurrent-session-control max-sessions="1" exception-if-maximum-exceeded="true"/>
		<security:logout logout-success-url="/login.zul"/>
	<beans:bean id="passwordEncoder"
		class="" />
	<security:authentication-provider user-service-ref="myUserDao">
		<security:password-encoder ref="passwordEncoder"/>

First, we define the access roles to the various sections. As we see, /admin folder and privatesection.zul are protected and need ROLE_ADMIN role to be accessible, otherwise an exception will be generated and the user will be redirected to accessDenied.zul. We define the authentication-provider that refers to myUserDao. This bean must implements UserDetails interface. Finally, we define the passwordEncoder since the passwords are encoded with md5 algorithm.

Source files

The project can be downloaded from here. It's an Eclipse project, you can import it directly into your workspace. All jar files was removed for faster download


This small talk aims to provide you a basic framework which regroup the most powerful web framework to start building Ajax based web applications. It still need improvements but I believe that it's a good start point. Your comment and suggestions are welcome at

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.