Search code examples
javatomcatrestful-authenticationrest-client

Validate Tomcat Authentication in rest client


I am using rest full web service and tomcat security. I want to write a restclient which will provide the username and password and will do authentication in server.

Please suggest some ways how can I do this?


Solution

  • The easiest way to do this is through basic HTTP authentication. You'll need to modify two files:

    1.web.xml of your application. Add:

    <login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>Basic authentication</realm-name>
    </login-config>
    <security-role>
      <description>Some role description</description>
      <role-name>role1</role-name>
    </security-role>
    

    2.tomcat-users.xml in conf directory:

    <tomcat-users>
      <user name="user1" password="pass" roles="role1" />
    </tomcat-users>