title: Mule Basic Authentication
body: <p>I am trying to use Basic authentication and get the credentials in Mule flows.</p>
  
  <p>Here is my Mule flows:</p>
  
  <pre><code>&lt;http:listener config-ref="httpConfig" path="/*" doc:name="HTTP" allowedMethods="get, post, delete" /&gt;
  &lt;apikit:router config-ref="api-config" doc:name="APIkit Router" /&gt;
  &lt;flow name="get:/sourcing/helloworld-secure:api-config"&gt;
     &lt;flow-ref name="authenticate-ldap" doc:name="authenticate-ldap"/&gt;
  &lt;/flow&gt; 
  
  &lt;flow name="authenticate-ldap"&gt;
      &lt;logger message="Name: #[message.inboundProperties.get('username')] Password:#[message.inboundProperties['password']] level="INFO"/&gt;
      &lt;component class="com.test.AuthTest" doc:name="Java"/&gt;
      &lt;logger message="After java: #[flowVars.username] #[flowVars.password]" level="INFO" doc:name="Logger"/&gt;
      &lt;json:object-to-json-transformer doc:name="Object to JSON"/&gt;
      &lt;data-mapper:transform config-ref="Map_auth_to_ldap_request" doc:name="Map auth to ldap request"/&gt;      
   &lt;/flow&gt;
  </code></pre>
  
  <p>Java code:</p>
  
  <pre><code>public class AuthTest implements Callable {
  @Override
      public Map&lt;String, String&gt; onCall(MuleEventContext eventContext) throws Exception {     
          Map&lt;String, String&gt; authMap = new HashMap&lt;String, String&gt;();              
          final String authorization = eventContext.getMessage().getInboundProperty("authorization");        
          if (authorization != null &amp;&amp; authorization.startsWith("Basic")) {           
              String base64Credentials = authorization.substring("Basic".length()).trim();
              String credentials = new String(Base64.decode(base64Credentials), Charset.forName(Base64.PREFERRED_ENCODING));
              if (credentials != null) {
                   final String[] values = credentials.split(":",2);              
                   eventContext.getMessage().setInvocationProperty("username", values[0]);
                   eventContext.getMessage().setInvocationProperty("password", values[1]);                 
                   authMap.put("username", values[0]);
                   authMap.put("password", values[1]);
              }
          }        
          return authMap;       
      }
  }
  </code></pre>
  
  <p>To run this application, I am using rest client in Chrome and selecting Basic Auth, then giving username and password. </p>
  
  <p>Above code is working fine. What I need is instead of getting credentials in Java then put into Map, I need to get the credentials in Mule flows without using Java code. Is this possible in Mule flows directly?</p>
  
  <p>I have implemented with Spring security which is working fine, but in this case I need user to enter credentials and proceed further.</p>