Patan
Patan

Reputation: 17873

How to fix annoying authorization popup requested by Tomcat?

I am trying to access a web service which is hosted on Tomcat 6 server. When I entered the wsdl url in the browser, I am being prompted for credentials.

I am getting a popup to enter the username and password.

A user name and password are being requested by http://localhost:8080. The site says: MyApplicationName

I gave my application login details. But it is prompting me again and again. When I click cancel I am getting 401 unauthorized exception.

tomcat-users.xml

   <?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
   <user name="admin" password="" roles="manager"/>
</tomcat-users>

server.xml has some details as below

<Server port="8205" shutdown="SHUTDOWN" debug="2">

  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <Service name="Catalina" debug="2">

    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" 
               scheme="http"
               secure="false"
               SSLEnabled="false"
               debug="2"
               emptySessionPath="true"
               URIEncoding="UTF-8" />

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    <Engine name="Catalina" defaultHost="localhost"
         debug="2">

      <Realm className="org.apache.catalina.realm.MemoryRealm"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost" appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false"
            debug="2">

             <Context path="" docBase="C:\mypath\app.war" debug="2"></Context>        

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

      </Host>
    </Engine>
  </Service>
</Server>

Web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">


    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>


    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>fork</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>xpoweredBy</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
    </servlet>

</web-app>

Can some one tell me how to remove this pop up or what username and password do I need to enter. Will it be my application specific or tomcat specific?

Upvotes: 1

Views: 10140

Answers (2)

Gopesh Verma
Gopesh Verma

Reputation: 31

I also faced the same issue. After hours of troubleshooting and trying all the possible solutions mentioned in this thread and the other similar threads, I could not fix the problem. Then I could determine that I started facing this issue all of a sudden because I have installed Oracle on my machine recently which used the same port 8080. I have changed the port number in my server.xml file and it is now working fine..

Below is the snippet of change :

 <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

Upvotes: 3

Jerry B
Jerry B

Reputation: 135

Try putting the following below the last listener tag above the service tag:

<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
          type="org.apache.catalina.UserDatabase"
          description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

And in the then under

<Engine name="Catalina" defaultHost="localhost"
     debug="2">

add:

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
         resourceName="UserDatabase"/>

Make sure you change the pathname in the UserDatabase resource to the correct path of your tomcat-users.xml file. You'll need to restart tomcat for changes to take effect.

Upvotes: 0

Related Questions