matt,

thanks so much. u r so helpful.

sorry to trouble for one more question.

aside from username, if I need  from User object that is special, e.g
department code 

how am i going to handle security context dependency, do u friend do this ?
User currentUser = (User)
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String depCode = currentUser.getDepartmentCode()

thanks for your great help
~thinkboy


Matt Raible-3 wrote:
> 
> The easiest way to do this is to use the remoteUser.  In your test:
> 
> MockHttpServletRequest request = ...
> request.setRemoteUser("foo");
> 
> Then in your Controller, use:
> 
> String username = request.getRemoteUser();
> 
> Matt
> 
> On 11/28/06, Man-Chi Leung <[EMAIL PROTECTED]> wrote:
>> hi,
>>
>> in my spring mvc controller, I need to get username from acegi security
>> context and pass this username to my service manager. but bcos of this
>> acegi dependency, I have difficulty to do unit test for my mvc
>> controller.
>>
>> may I know what is the best practice?
>>
>> should I refactor the mvc controller, injecting denpendency of
>> acegi security context to my Controller via spring from
>> setAcegiContext(), then use Jmock to mock a acegi security context in
>> my MyControllerTest ?
>>
>> i am a bit puzzled on this. pls advise. thanks so much.
>>
>> ~thinkboy.
>>
>>
>>         public ModelAndView handleRequest(HttpServletRequest request,
>>                         HttpServletResponse response) throws Exception {
>>
>>                 User currentUser = (User)
>> SecurityContextHolder.getContext()
>>                                 .getAuthentication().getPrincipal();
>>                 String username = currentUser.getUsername()
>>
>>
>>                 return new ModelAndView("serviceList",
>> Constants.SERVICE_LIST, mgr
>>                                 .lookupServicesByUsername(username));
>>         }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> -- 
> http://raibledesigns.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/to-test-a-spring-mvc-controller-that-has-acegi-dependency--tf2722652s2369.html#a7594161
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to