title: How to implement HTTP Basic Authentication with synchronous JMS in Mule ESB?
body: <p>I've created a simple flow that exposes an HTTP endpoint linked to a REST service. The REST service returns a String which is then placed onto a JMS queue using the request-response pattern. The idea is that the String placed on the queue will be consumed by some consumer and a reponse will created using the Reply-To address. So basically this is implimenting synchronous JMS.</p>
  
  <p>The flow works as expected, except when the HTTP endpoint is secured using Basic Authentication. In this case the response is:</p>
  
  <pre><code>java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: MuleResponseWriter$1
  </code></pre>
  
  <p>and no message is placed on the queue. Removing Basic Authentication results in no exception being thrown. Also, removing the JMS outbound endpoint results in the String being echoed back which leads me to believe the problem is with the JMS endpoint. I suspect that the problem is with the response from the JMS endpoint because setting component in the flow to one-way negates the problem. I think the issue might be that the endpoint is sending some response to the HTTP endpoint without authentication credentials and it fails because of it, but I'm unsure how to deal with this.</p>
  
  <p>Below is the flow that I created:</p>
  
  <pre><code>&lt;mule
      xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
      xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
      xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
      xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core"
      version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
      xmlns:json="http://www.mulesoft.org/schema/mule/json"
      xmlns:ss="http://www.springframework.org/schema/security" xsi:schemaLocation="
      http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
      http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd 
      http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
      http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd 
      http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd 
      http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd "&gt;
  &lt;jms:activemq-connector name="Active_MQ" specification="1.1" brokerURL="tcp://localhost:61616"
                          validateConnections="true" doc:name="Active MQ"/&gt;
  &lt;mule-ss:security-manager&gt;
      &lt;mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager"/&gt;
  &lt;/mule-ss:security-manager&gt;
  &lt;spring:beans&gt;
      &lt;ss:authentication-manager alias="authenticationManager"&gt;
          &lt;ss:authentication-provider&gt;
              &lt;ss:user-service id="userService"&gt;
                  &lt;ss:user name="username" password="password" authorities="ROLE_ADMIN"/&gt;
              &lt;/ss:user-service&gt;
          &lt;/ss:authentication-provider&gt;
      &lt;/ss:authentication-manager&gt;
  &lt;/spring:beans&gt;
  &lt;flow name="RESTAPISync" doc:name="RESTAPISync"&gt;
      &lt;http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"&gt;
          &lt;mule-ss:http-security-filter realm="realm"/&gt;
      &lt;/http:inbound-endpoint&gt;
      &lt;jersey:resources doc:name="REST"&gt;
          &lt;component class="SFREST"/&gt;
      &lt;/jersey:resources&gt;
      &lt;jms:outbound-endpoint exchange-pattern="request-response" queue="tmp" connector-ref="Active_MQ"
                             doc:name="JMS"/&gt;
  &lt;/flow&gt;
  </code></pre>
  
  <p></p>
  
  <p>The SFREST.java component:</p>
  
  <pre><code>import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  
  
  @Path("/pops")
  public class SFREST{
  
      @GET
      public String getPOPs()  throws Exception{
          return "hello";
      }
  
  }
  </code></pre>
  
  <p>And the exception:</p>
  
  <pre><code>ERROR 2012-11-04 21:40:57,485 [[jmstest].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
  ********************************************************************************
  Message               : Authentication Attempt Failed. Message payload is of type: String
  Code                  : MULE_ERROR-54999
  --------------------------------------------------------------------------------
  Exception stack is:
  1. Bad credentials (org.springframework.security.authentication.BadCredentialsException)
      org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider:137 (null)
  2. Authentication Attempt Failed. Message payload is of type: String (org.mule.api.security.UnauthorisedException)
  org.mule.security.MuleSecurityManager:96 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/UnauthorisedException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  org.springframework.security.authentication.BadCredentialsException: Bad credentials
  at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:137)
  at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156)
  at org.mule.module.spring.security.SpringProviderAdapter.authenticate(SpringProviderAdapter.java:70)
  + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  
  ERROR 2012-11-04 21:41:04,522 [[jmstest].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
  ********************************************************************************
  Message               : java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: MuleResponseWriter$1
  Code                  : MULE_ERROR-29999
  --------------------------------------------------------------------------------
  Exception stack is:
  1. com.sun.jersey.spi.container.ContainerResponse (java.io.NotSerializableException)
  java.io.ObjectOutputStream:1164 (null)
  2. java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException)
  org.apache.commons.lang.SerializationUtils:111 (null)
  3. java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: MuleResponseWriter$1 (org.mule.api.MessagingException)
  org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse
  at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
  at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
  at org.apache.commons.collections.map.AbstractHashedMap.doWriteObject(AbstractHashedMap.java:1182)
  + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  </code></pre>
  
  <p>Any ideas?</p>