Results 1 to 4 of 4

Thread: Wiring user

  1. #1
    Join Date
    Mar 2005
    Location
    Los Angeles
    Posts
    20

    Default Wiring user

    I am wondering how we could inject the user object (implements UserDetails) into a bean?

    An Order object has an instance of user, I want to container automatically injects user (principal) into my order bean.

    <bean id="order" class="Order" >
    <property name="user" >?????</property>
    </bean>

    Currently, I am doing it in my service layer as:

    Authentication authentication = context.getAuthentication();
    if (authentication != null) {
    if (authentication.getPrincipal() instanceof User) {
    order.setUser((User) authentication.getPrincipal());
    }
    }

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    You can't inject the User like that, you just access it from the threadLocal as you are currently.

  3. #3
    Join Date
    Mar 2005
    Location
    Los Angeles
    Posts
    20

    Default Using sessionScope bean

    Quote Originally Posted by karldmoore View Post
    You can't inject the User like that, you just access it from the threadLocal as you are currently.
    Thanks for reply,

    Since our goal is not to expose any framework dependency into our code,
    I thought the Acegi might have mechanism like spring2's session scope bean, which returns instance of either Authentication or Principle object.

    If not, do you think is this a good idea to define the user bean like this:

    <bean id="user" class="User" scope="session">
    <aop:scoped-proxy/>
    </bean>

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you really want to do it like this, then your idea would work. Injecting a scoped-proxy e.g. request/session and then simply doing the lookup in there instead. That way you can hide the implementation away.

Posting Permissions

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