Announcement Announcement Module
No announcement yet.
UserDetailsService and Hibernate Page Title Module
Move Remove Collapse
This topic is closed
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • UserDetailsService and Hibernate

    Ok I will clean all in relation to post

    I want to link Spring Security with Hibernate.

    I have dispatcher-servlet.xml with working hibernate
        <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
           <property name="hibernateProperties">
                    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                    <prop key="hibernate.connection.datasource">jdbc/nowoczesne_cc</prop>
        <!-- Hibernate Pojo manipulation Layer -->
        <bean id="hibernateTUserDao" class="">
            <property name="sessionFactory" ref="hibernateSessionFactory"/>
    I have securityContext.xml
        <s:http auto-config="true">
        <!-- IN MEMORY PROVIDER -->
                <s:user name="marcin" password="xxx" authorities="ROLE_USER, ROLE_ADMIN" />
                <s:user name="bob" password="yyy" authorities="ROLE_USER" />
        <!-- MY OWN zCC PROVIDER -->
        <beans:bean id="customUserDetailsService" class="">
            <property name="sessionFactory" ref="[ THIS IS THE MAIN PROBLEM ]"/>
        <s:authentication-provider user-service-ref="customUserDetailsService" />
    I implement UserDetails in my TUser Pojo, and in HibernateTUserDao implements UserDetailsService.

    Thing which I cant understand is how could I pass Hibernate session to security context? I supose that I can reDeclare session Factory and all other beans in security context but "my mind say me" that it not good idea. Is any way to declare one shared resource like sessionFactory for dispatcherServlet and securityContext? Maybe someone can give me advice How can I cleanly link Spring security and Hibernate. I read many post and many blogs but in evry place there is only something like
    <b:bean id="userDetailsService" class="com.ap.user.HibernateUserDetailsService">
    		<b:property name="hibernateTemplate" ref="hibernateTemplate" />
      <property name="sessionFactory" ref="sessionFactoryBean"/>
    I cant understand where and how this declared?
    Please help guys.

  • #2
    I don't really understand the problem. Why do you have to declare your Hibernate beans in the dispatcher-servlet.xml?


    • #3
      Thx very much Luke, I am a beginner with JEE5 and with all this servlets and servlet Context.
      Your last question allow me to understand what exactly the context is

      Offcourse you are in right this declaration in dispatcher-servlet.xml is stupid in this case

      Thx a lot again.
      Last edited by marcintom; May 22nd, 2009, 06:19 AM.