Results 1 to 3 of 3

Thread: UserDetailsService and Hibernate

  1. #1
    Join Date
    May 2009
    Location
    POLAND
    Posts
    52

    Question 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. #2
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    I don't really understand the problem. Why do you have to declare your Hibernate beans in the dispatcher-servlet.xml?
    Spring - by Pivotal
    twitter @tekul

  3. #3
    Join Date
    May 2009
    Location
    POLAND
    Posts
    52

    Default

    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 at 06:19 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •