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

  • UserDetailsService and Hibernate

    Ok I will clean all in relation to post http://forum.springsource.org/showthread.php?t=72255

    I want to link Spring Security with Hibernate.

    I have dispatcher-servlet.xml with working hibernate
    Code:
        <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
           <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                    <prop key="hibernate.connection.datasource">jdbc/nowoczesne_cc</prop>
             (...)
        </bean>
    
        <!-- Hibernate Pojo manipulation Layer -->
        <bean id="hibernateTUserDao" class="org.mysite.cc.hibernatedao.HibernateTUserDao">
            <property name="sessionFactory" ref="hibernateSessionFactory"/>
        </bean>
       (...)
    I have securityContext.xml
    Code:
        <s:http auto-config="true">
           (...)
        </s:http>
    
        <!-- IN MEMORY PROVIDER -->
        <!--
        <s:authentication-provider>
            <s:user-service>
                <s:user name="marcin" password="xxx" authorities="ROLE_USER, ROLE_ADMIN" />
                <s:user name="bob" password="yyy" authorities="ROLE_USER" />
            </s:user-service>
        </s:authentication-provider>
         -->
        <!-- MY OWN zCC PROVIDER -->
        <beans:bean id="customUserDetailsService" class="org.zethost.cc.hibernatedao.HibernateTUserDao">
            <property name="sessionFactory" ref="[ THIS IS THE MAIN PROBLEM ]"/>
        </beans:bean>
    
        <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
    Code:
    <b:bean id="userDetailsService" class="com.ap.user.HibernateUserDetailsService">
    		<b:property name="hibernateTemplate" ref="hibernateTemplate" />
    </b:bean>
    
    OR 
    
      <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?

    Comment


    • #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.

      Comment

      Working...
      X