Adding security to CXF web services
In my previous post, I demonstrated how easy it is to create REST services using Spring and CXF. Now I'll show you something even easier: adding security.
For this example, I'll start where I left off, which is a working REST service showing the time, and add basic HTTP authentication. I'll be using Spring Security 3 to add the security features. Spring Security 3 is relatively new and those used to version 2 will need a wee bit of adjustment (you'll need more jars, as they split them up).
Creating a REST service with CXF and Spring in 10 minutes
I love REST. It's easy, straightforward and above all: easily testable. When you're developing with REST, you have a lot of options to choose from. There's Jersey, the reference Sun implementation, then you have RestEasy, the JBoss choice, and there is CXF, the Apache choice. I chose CXF for this example simply because it's so easy to create REST services with it, without a lot of configuration.