((SecureContext) ContextHolder.getContext()).getAuthentication();
If you didn't want that in your audit object, you could write an interface:
Code:
public interface CurrentUser {
public Object getUser();
}
Then an implementation:
Code:
public class CurrentUserAcegiSecurityImpl implements CurrentUser {
public Object getUser() {
return ((SecureContext) ContextHolder.getContext()).getAuthentication();
}
}
Although I'd wonder whether it was necessary to make this pluggable, as you'd probably cast the returned Object back to Authentication anyway in order to view its roles etc. You could always add an additional method to your interface to achieve that, though. It's really a matter of personal preference.