2

new Zksample2 app. Spring, -AOP, -Security, Hibernate, Hibernate-Generic-DAO, Jasper

asked 2010-01-17 08:29:28 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2013-03-27 08:56:18 +0800

jimyeh gravatar image jimyeh
2047 1 4
ZK Team

Hi all,

today we have checked in the new Zksample2 application as maven2 projects on sourceforge.net. You can reach the project homepage under the link http://zksample2.sourceforge.net/ here.

You will find there 3 eclipse maven subprojects and the folder for the documentation.

  1. KeyGenZkoss = one-time-password generator
  2. spring-hibernate-backend = backend
  3. zkoss = frontend
  4. zksample2_doc = documentation

The Documentation you can download seperately as a pdf-file from here.

The documentation is a work in progress so be sure to check sometimes for the newest file.

For checkout and evaluate or work with the application please download and read first the documentation.

Mainly changes to the first sample app are: - change project structure as maven2 projects - spring managed frontend - @Secured() for securing methods with own implementation - login statistic - several integration options of ipToCountry - one-time-password sources are opend - Refactoring all Domain/DAO/Service Classes to english names - many many code changes - documentation

We whish all fun with it and hope that it can be usefull for others.

best Stephan and Björn

delete flag offensive retag edit

213 Replies

Sort by » oldest newest

answered 2011-02-25 15:34:01 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-02-25 15:37:49 +0800

Hi Lesstra,

i work with Eclipse and the m2e plugin. I have no problem to build the war file.
Maven tries all repositories that are defined for looking for a missing jar-file,
so it's 'NORMAL' that he looks in hibernate-generic-dao. That's no problem.

You must first let maven compile ALL single projects and let them store in its local .m2 maven repository.

In Eclipse do the follow actions on every sub project:
- KeyGenZkoss,
- Spring-Hibernate-Backend,
- zkoss

Eclipse Actions:
1. Run as --> Maven clean
2. Run as --> Maven install


You can also make the checkout from these three subprojects in folders OUTSIDE the Eclipse workspace like this:
So you can also use one MAIN project pom-file for do the building:

- D:\maven-projects
- D:\maven-projects\Zksample2
- D:\maven-projects\Zksample2\KeyGenZkoss
- D:\maven-projects\Zksample2\Spring-Hibernate-Backend
- D:\maven-projects\Zksample2\Zkoss
- D:\maven-projects\Zksample2\build.pom

Where the maven project build.pom looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>de.forsthaus</groupId>
  <version>1.0-SNAPSHOT</version>
  <name>${project.artifactId}->${project.version}</name>
  <artifactId>zkoss-Webapp</artifactId>
  <packaging>pom</packaging>
  <modules>
    <module>KeyGenZkoss</module>
    <module>spring-hibernate-backend</module>
    <module>zkoss</module>
  </modules>
</project>


It can be that you need several tries till all jar's are local saved.

best
Stephan

link publish delete flag offensive edit

answered 2011-03-01 02:54:20 +0800

Lesstra gravatar image Lesstra
193 1

Stephan,

thanks a lot for your great help and support.

I also installed and used m2eclipse plugin, but as you suspected backend and keyGen subprojects weren't installed properly in local repository,
even though there were snapshot jars there. It acts a bit strange sometimes.

Anyway, clean and install basically fixed the problem, but I also had to change JRE sys libs to jdk, for maven compiler to be able to compile the classes.
Further I had some problems with some xml file regarding jasper, and also for some reason had to remove and re-add all dependencies for backend,
but important thing is that it works now.

Thanks again.

Best regards

link publish delete flag offensive edit

answered 2011-03-01 06:31:13 +0800

Lesstra gravatar image Lesstra
193 1

One more thing regardin scope="session" and "non-serializable attribute: someEntityDAO" error:

I know that this is not quite the thread for this matter, but since Andyx and I ran into the same problem, and the same question was asked,
I thought it might be useful to post here what I found reading Spring docs in detail.

In chapter 3.5.4.5 Scoped beans as dependencies, it states : "If you want to inject (for example) an HTTP request scoped bean into another bean, you must inject an AOP proxy in place of the scoped bean."
Same applies to session scope. And basically, that is what is done here, DAO and Service beans are injected into controller beans in frontend.

So, simply by adding:

<aop:scoped-proxy/> 

in session-scoped beans, and adding cglib2 to classpath, the problem is gone, no need to implement Serializable on DAOs.
Still, I don't understand how in original code this works without AOP proxy, maybe there is some additional configuration that I haven't spotted yet... :-)

Cheers

link publish delete flag offensive edit

answered 2011-03-23 23:13:57 +0800

andyx gravatar image andyx
51

hi Lesstra,
You give me a idea to check again with aop setting in performance-db-logging.xml,
after modify configuration like below:
<aop:pointcut id="guiServiceMethods"
expression="execution(* de.forsthaus.gui.service.*.*(..))
or execution(* com.mytest.mte.gui.service.*.*(..))" />
<aop:pointcut id="serviceMethods"
expression="execution(* de.forsthaus.backend.service.*.*(..))
or execution(* com.mytest.mte.service.*.*(..))" />
<aop:pointcut id="daoMethods"
expression="execution(* de.forsthaus.backend.dao.*.*(..))
or execution(* com.mytest.mte.dao.*.*(..))" />
<aop:around pointcut-ref="guiServiceMethods" method="logging" />
<aop:around pointcut-ref="serviceMethods" method="logging" />
<aop:around pointcut-ref="daoMethods" method="logging" />
there is no need to implement Serializable or import cglib2 library in spring-hibernate-backend. i think this is the better solution like Stephan want.
thanks.

Best regards.
Andyx

link publish delete flag offensive edit

answered 2011-03-28 04:39:30 +0800

Lesstra gravatar image Lesstra
193 1

Hi Andyx,

Well, yes, this also came to mind, I'll look closely into that. Also after some further research,
I found that it is OK to inject prototypes into session-scoped beans with no proxies or anything, beacuse basically "session" is wider sope than prototype.

I still can't quite figure out the multi-user scenario for this project, because in my opinion, DAOs in Stephan's app are effectively stateless.
Yes, each DAO here holds hibernateTemplate, which holds Hibernate's Session in the background (which is statefull), but there is no control over that anymore,
since transaction demarcation is achieved via Spring AOP. So I'm guessing, Hibernate's Sessions are available only at transaction level.

When I asked: why are DAOs and Services (which are stateless) scoped as "session"?
I got the answer: You have very old stuff there.
I again checked-out the newest revision, and still DAOs/Services were scoped as "session".

I don't see that session scope is necessary for DAOs here, I'd scope them as singletons. But of course I'm assuming that singletons are thread-safe in spring.
Are they thread-safe? I guess they should be..?

Best regards.

link publish delete flag offensive edit

answered 2011-03-28 15:36:33 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-03-28 15:38:50 +0800

Yes, we do more than needed. It's hidden in the transaction management. And you are right we can change it to scope singleton. I have found a few interesting parts that i would post here:

From the spring forum:

Q: hi, I plan to use my architecture with spring + hibernate + tomcat.

let say my tomcat got 200 thread for handling request from user. should I make the stateless DAO (is thread safea anyway) to prototypeor request ? which is the correct scope ?

If we using singleton, it that mean this dao will be share by all the 200 thread, compare to the prototype (or request?) scope, will it be slower (since only shared one object) ? Am i right ?

A: Start with singleton. If you encounter problems/issues with that you can always scale up. In 99% of the cases a singleton suffices as long as it is stateless of course.



Here is a nice link with the result:

There is no need to make your DAOs session-scoped.

Though Hibernate session has a state, under properly configured transaction management its state is bound to transactions (i.e. different DAO methods called inside the same transactions share the same session, whereas the same method called from different transactions use different sessions).

So, your DAOs are effectively stateless, and should be singleton-scoped (i.e. default scope).

best
Stephan

link publish delete flag offensive edit

answered 2011-03-29 07:33:54 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-03-29 07:35:24 +0800

I have updated the scopes in the backend DAOs to their defaults, means 'singleton'. Additionally i added a little chapter about how we using the spring scopes in the Zksample2 documentation.
Thank boths to their suggestions. Hope that now are all funny ? :-)

best
Stephan

link publish delete flag offensive edit

answered 2011-04-14 15:32:16 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Inspired by the demo data of BusinessPortalLayout we spend a new DashboardModule for BBCNews.

have fun with it.

best
Stephan

link publish delete flag offensive edit

answered 2011-05-27 04:20:02 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

We have updated the demo app codes to the newest zk version --> 5.0.7.1

have fun
Stephan

link publish delete flag offensive edit

answered 2011-05-29 09:47:08 +0800

andyx gravatar image andyx
51

Hi,
I had combined spring security with Windows AD authentication, it will extend zksample2 to meet more enterprise requirement.
before this, you can use microsoft ldp.exe to test ldap connection. below is how to do this.
1. add jar in pom.xml (spring-security-ldap and spring-ldap-core)
2. modify springSecurityContext.xml, refere to http://www.coderanch.com/t/525031/Spring/Spring-LDAP-Active-Directory-Security from line 33 to 79.
3. modify de.forsthaus.policy.model.PolicyManager and implement UserDetailsContextMapper like below
public class PolicyManager implements UserDetailsService, UserDetailsContextMapper, Serializable {
}
4. then you need to implement 2 abstract method, add them and add code on them
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx,
String username, Collection<GrantedAuthority> authorities) {
logger.debug("ctx"+ctx);
return loadUserByUsername(username);
}
@Override
public void mapUserToContext(UserDetails user, DirContextAdapter ctx) {
logger.debug("ctx"+ctx);
}
5. confirm your springSecurityContext.xml, make sure authenticationManager and ldapAuthProvider are correct.
<authentication-manager alias="authenticationManager">
<!-- Windows AD authentication -->
<authentication-provider ref="ldapAuthProvider"/>

<!-- DB authentication
<authentication-provider user-service-ref="myUserDetailsService">
<password-encoder ref="passwordEncoder">
<salt-source user-property="token" />
</password-encoder>
</authentication-provider>
-->
</authentication-manager>
<beans:bean class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider" id="ldapAuthProvider">
<beans:constructor-arg ref="ldapBindAuthenticator"/>
<!-- beans:constructor-arg ref="ldapAuthoritiesPopulator"/-->
<beans:property name="userDetailsContextMapper" ref="myUserDetailsService"/>
</beans:bean>

have fun.
Andyx

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
4 followers

RSS

Stats

Asked: 2010-01-17 08:29:28 +0800

Seen: 29,065 times

Last updated: May 27 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More