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

  • 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
    You can't inject the User like that, you just access it from the threadLocal as you are currently.

    Comment


    • #3
      Using sessionScope bean

      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>

      Comment


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

        Comment

        Working...
        X