basic/digest authentication implementation in Java server code/web server
===

We need to support basic authentication and later digest authentication in Java web project.
My doubt is

 - Whether basic/digest authentication is a configuration in web server
   (tomcat, jboss etc).Our users/password are in a SQL database and we
   get these through dataservices. In this case how I can configure the
   web server to use the dataservices to authenticate?
 - Whether I need to handle explicitly in code for basic/digest
   authentication? Like I will receive authentication request from
   Servlet and will connect to dataservices for authentication?

Please help me. Thanks.