Exodus 32: Moses' anger was justified and righteous in this instance because the people were defiling themselves and worshiping a man-made god. They were also crediting that god for delivering them from Egypt even though they had seen the power of the true God working to deliver them. His anger motivated him to obey God's command and cleanse the people, which he may have been hesitant to obey otherwise.
Numbers 20:1-12: Moses was continually being frustrated by the Israelites. Nothing was ever good enough for them. Rather than embracing each challenge they faced as an opportunity to see God work for them, they chose to complain to Moses about how they wanted to go back to Egypt. They often accused Moses of bringing them out into the wilderness to die. You would think that after everything they had seen God do through Moses that at some point they would begin trusting. I'm sure Moses was tired of their complaining and accusations. He probably hoped they would show gratitude for being delivered out of the abuse and slavery they experienced in Egypt. When they arrived at the Wilderness of Zin, where there was no water, and the people began rehashing their familiar complaints, Moses was probably thinking something along the lines of "Oh, here we go again!" At first he did the right thing and sought God for the solution, but as he approached the people his anger was still brewing. He may have wanted to show the people once and for all that he was the one in charge. In his anger he modified God's instructions. God had told Moses to simply speak to the rock in front of the Israelites, and it would yield water. Instead Moses chose to say, "Hear now, you rebels! Must we bring water for you out of this rock?" (vs 10) and hit the rock twice with his rod (emphasis added). In the past Moses had channeled his anger to enable him to do positive things, but this time he let his anger get the best of him. This time he took matters into his own hands, reminiscent of the time that he killed the Egyptian who had abused the Israeli slave (Exodus 2:11-12). In his anger he tried to take part of the credit for God's miracle. God wanted His own authority to be clearly demonstrated to the people. Moses wanted the people to accept his authority. He disobeyed God's command. In his anger he struck the rock. I think that both God's and Moses' authority would have been much more clearly demonstrated had Moses exactly obeyed God's command (that's not a judgment, just an observation). But, when we allow anger to get the best of us our judgment gets clouded. God was faithful and provided the water despite Moses' disobedience, but He punished Moses by preventing him from leading the people into the Promised Land.