Ok so the three things i think i need to do are as follows.

This bean will be created per request 

public class SystemUserHolder implements ISystemUserHolder{
private final SystemUser systemUser;
    /**
     * 
     */
    public SystemUserHolder() {
        super();
        SecureContext secureContext = ((SecureContext)         
        ContextHolder.getContext());
              systemUser = ( SystemUser
)secureContext.getAuthentication().getDetails();
    }
getSystemUser() ........ 
}

Then I will implement the 
snip=
public class HibernateAuthenticationDAOImpl extends
HibernateDaoSupport implements AuthenticationDao {

    /* (non-Javadoc)
     * @see 
net.sf.acegisecurity.providers.dao.AuthenticationDao#loadUserByUsername(java.lang.String)
     */
    public UserDetails loadUserByUsername(String arg0)
            throws UsernameNotFoundException, DataAccessException {
        // TODO Impliment this properly
        
        GrantedAuthority [] authorities = {new
Authority("SYSTEM_ADMINISTRATOR"),new Authority("CUSTOMER")};
        
        SystemUser systemUser = new SystemUser();
                
        systemUser.setId(new Integer(1));
        systemUser.setUsername("bryanhunt");
        systemUser.setPassword("bryanhunt");
        systemUser.setAuthorities(authorities);
        return (UserDetails) systemUser;
    }

}
=snip

and then I will have 
                
        <bean id="systemUserHolder" 
                class="ie.jestate.acegi" singleton="false">
        
        </bean>

        <bean id="orderServiceTarget" 
                class="ie.jestate.spring.service.impls.OrderService">
                <property name="orderDAO">
                        <ref local="orderDAO"/>
                </property>
                <property name="systemUserHolder">
                        <ref local="systemUserHolder"/>                 
                </property>
        </bean>

Then my methods that are in the orderService class can 
call systemUserHolder.getSystemUser.getId() and 
do searches for example where the user is only allowed
to see financial data for a certain region.

I am very much new to Spring so if I'm completely off the 
mark here feel free to flame me. I think this code will be 
a good reference implimentation if I can get it working 
good. 

--b



On Mon, 9 Aug 2004 17:39:46 +0200, Karel Miarka <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> > So it would be really cool if the User ( which implements UserDetails )
> > also had an id ( Integer ) properties.
> 
> You can return any object implementing UserDetails interface from your
> loadUserByUsername() implementation of AuthenticationDao interface, so at
> any place you can cast this user object from the UserDetails to your
> appropriate user object and access all its properties for example the
> integer id.
> 
> > Also is there any way that I could get this information into the service
> > beans without adding any ageci dependant code into my struts actions ?
> >
> 
> I think you can encapsulate the acegi code for obtaining the current user
> into a method in your service layer like this:
> 
> public class MyServiceImpl {
>   ...
> public MyUser getCurrentUser() {
>    SecureContext secureContext = ((SecureContext)
> ContextHolder.getContext());
>    final Authentication currentUser = secureContext.getAuthentication();
>    return (MyUser)currentUser.getPrincipal();
> }
> ....
> }
> 
> HTH,
> Karel
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by OSTG. Have you noticed the changes on
> Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
> one more big change to announce. We are now OSTG- Open Source Technology
> Group. Come see the changes on the new OSTG site. www.ostg.com
> _______________________________________________
> Acegisecurity-developer mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/acegisecurity-developer


-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
Acegisecurity-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/acegisecurity-developer

Reply via email to