title: Why do I have a huge memory leak when trying to use Basic Authentication in a simple Web Service with Apache Geronimo
body: <p>I'm using Apache Gronimo 3.01 and I am finding a huge memory leak in a Web Service that uses Basic Authentication (and no memory leak if no authentication is used):</p>
  
  <p>The only code is simply this:</p>
  
  <pre><code> package org.apache.geronimo.samples.jws;
  
  import javax.annotation.Resource;
  import javax.jws.WebService;
  import javax.xml.ws.WebServiceContext;
  
  @WebService(serviceName = "Calculator",
              portName="CalculatorPort",
              endpointInterface = "org.apache.geronimo.samples.jws.Calculator",
              targetNamespace = "http://jws.samples.geronimo.apache.org"
              )
  public class CalculatorService implements Calculator {
  
      @Resource
      private WebServiceContext context;
  
      public int add(int value1, int value2) {
          System.out.println("User Principal: " + context.getUserPrincipal());
          return value1 + value2;
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>package org.apache.geronimo.samples.jws;
  
  import javax.jws.WebService;
  import javax.jws.WebMethod;
  import javax.jws.WebParam;
  
  @WebService(name="CalculatorPortType",
              targetNamespace = "http://jws.samples.geronimo.apache.org")
  public interface Calculator {
  
      @WebMethod
      public int add(@WebParam(name = "value1") int value1,
                     @WebParam(name = "value2") int value2);
  
  }
  </code></pre>
  
  <p>And the following XMLs:</p>
  
  <p>jaxws-calculator/WebContent/WEB-INF/WebContent/web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt;
    &lt;display-name&gt;jaxws-calculator&lt;/display-name&gt;
    &lt;security-constraint&gt;
      &lt;web-resource-collection&gt;
        &lt;web-resource-name&gt;Protected&lt;/web-resource-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
        &lt;http-method&gt;GET&lt;/http-method&gt;
        &lt;http-method&gt;POST&lt;/http-method&gt;
      &lt;/web-resource-collection&gt;
      &lt;auth-constraint&gt;
        &lt;role-name&gt;wsusers&lt;/role-name&gt;
      &lt;/auth-constraint&gt;
    &lt;/security-constraint&gt;
    &lt;login-config&gt;
      &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
      &lt;realm-name&gt;LeakyWsSecurityRealm&lt;/realm-name&gt;
    &lt;/login-config&gt;
    &lt;security-role&gt;
      &lt;role-name&gt;wsusers&lt;/role-name&gt;
    &lt;/security-role&gt;
    &lt;servlet&gt;
      &lt;display-name&gt;Apache-Axis Servlet&lt;/display-name&gt;
      &lt;servlet-name&gt;AxisServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.apache.axis.transport.http.AxisServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AxisServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/servlet/AxisServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AxisServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.jws&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AxisServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/services/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet&gt;
      &lt;display-name&gt;Axis Admin Servlet&lt;/display-name&gt;
      &lt;servlet-name&gt;AdminServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.apache.axis.transport.http.AdminServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;100&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AdminServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/servlet/AdminServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>jaxws-calculator/WebContent/WEB-INF/WebContent/geronimo-web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;web:web-app xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0" xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2" xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:jaspi="http://geronimo.apache.org/xml/ns/geronimo-jaspi" xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0" xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence" xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"&gt;
      &lt;dep:environment&gt;
          &lt;dep:moduleId&gt;
              &lt;dep:groupId&gt;leaky-ws&lt;/dep:groupId&gt;
              &lt;dep:artifactId&gt;jaxws-calculator&lt;/dep:artifactId&gt;
              &lt;dep:version&gt;1.0&lt;/dep:version&gt;
              &lt;dep:type&gt;car&lt;/dep:type&gt;
          &lt;/dep:moduleId&gt;
      &lt;/dep:environment&gt;
      &lt;web:context-root&gt;/jaxws-calculator&lt;/web:context-root&gt;
      &lt;web:security-realm-name&gt;LeakyWsSecurityRealm&lt;/web:security-realm-name&gt;
  &lt;/web:web-app&gt;
  </code></pre>
  
  <p>jaxws-calculatorEAR/EarContent/META-INF/application.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6"&gt;
    &lt;display-name&gt;jaxws-calculatorEAR&lt;/display-name&gt;
    &lt;module&gt;
      &lt;web&gt;
        &lt;web-uri&gt;jaxws-calculator.war&lt;/web-uri&gt;
        &lt;context-root&gt;jaxws-calculator&lt;/context-root&gt;
      &lt;/web&gt;
    &lt;/module&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>jaxws-calculatorEAR/EarContent/META-INF/geronimo-application.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;app:application xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0" xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2" xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2" xmlns:jaspi="http://geronimo.apache.org/xml/ns/geronimo-jaspi" xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0" xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence" xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" application-name="ws-ivr"&gt;
      &lt;dep:environment&gt;
          &lt;dep:moduleId&gt;
              &lt;dep:groupId&gt;leaky-ws&lt;/dep:groupId&gt;
              &lt;dep:artifactId&gt;jaxws-calculatorEAR&lt;/dep:artifactId&gt;
              &lt;dep:version&gt;1.0&lt;/dep:version&gt;
              &lt;dep:type&gt;car&lt;/dep:type&gt;
          &lt;/dep:moduleId&gt;
          &lt;dep:dependencies&gt;
              &lt;dep:dependency&gt;
                  &lt;dep:groupId&gt;console.realm&lt;/dep:groupId&gt;
                  &lt;dep:artifactId&gt;LeakyWsSecurityRealm&lt;/dep:artifactId&gt;
              &lt;/dep:dependency&gt;
          &lt;/dep:dependencies&gt;
      &lt;/dep:environment&gt;
      &lt;sec:security&gt;
          &lt;sec:role-mappings&gt;
              &lt;sec:role role-name="wsusers"&gt;
                  &lt;sec:principal class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal" name="wsusers"/&gt; 
              &lt;/sec:role&gt;
          &lt;/sec:role-mappings&gt;
      &lt;/sec:security&gt;
  &lt;/app:application&gt;
  </code></pre>
  
  <p>In geronimo's console I have set up a Security Realm: LeakyWsSecurityRealm that is a "Properties File Realm". </p>
  
  <p>The problem is that it leaks objects, as I have seen using VisualVM, of type "java.security.AccessControlContext" (128K instances before an OutOfMemoryError) referenced by 64K instances "org.apache.geronimo.security.Context". </p>
  
  <p>Does anybody have any clue on what's wrong here?</p>