My Max does this too. If he is off leash in a dog park he greets everyone with a wagging tail. At home he thinks he needs to protect the house.
A citronella bark collar will discourage the barking. As for the protective attitude that I am still working on.