Using HTTP Basic authentication is a common mechanism to check user’s authenticity, when creating REST-enabled API’s to prevent applications and it’s functionalities from unathorized access. Service Bus 12c (SB) supports this authentication method by using a OWSM security policy. The corresponding authentication information are transported in the HTTP header.
In some cases, for example when only user-relevant data should be determined when querying information from Enterprise Information Systems (EIS), the information about the current user that are available  in the HTTP header might be helpful. As an alternative the username information could be transported in the payload of each Service Call, e.g. as a query parameter.
In the following I will describe, which steps are needed to extract the username from the HTTP header, so transporting the same information twice, in the header and the payload, can be avoided.
Starting point is a simple HelloWorld service, which expects a valid HTTP Basic authentication token. In the example a corresponding OWSM policy is used to realize this. The service as such has an operation „greet“ that takes no parameter. As result, it returns a personalized salution based on the passed authorization header.
Enabling_HTTP_Basic_Auth_on_Proxies
Enabling HTTP basic authentication on proxy services
In the Proxy Service configuration it has to be ensured that the option „Get all headers“ is enabled in the transport configuration. Unfortunately setting this option is not sufficient, because SB removes Security information from the HTTP header before entering the processing pipeline. To force SB to keep the authentication information the additional java option „-Dcom.bea.wli.sb.transports.http.GetHttpAuthorizationHeaderAllowed=true“ has to be added in setDomainEnv.sh. A server restart is needed to enable the updated JVM settings.
Parsing out the username from the HTTP basic authentication token is done by a Java Callout that call a static method from a Java class that does the needed „magic“.
public class UsernameExtractor {

  public static String extract(String pHttpAuthenticationToken) {

    final String authenticationTokenWithoutBasicPrefix = pHttpAuthenticationToken
      .substring(6);

    final String base64DecodedAuthorizationString = new String(DatatypeConverter
      .parseBase64Binary(authenticationTokenWithoutBasicPrefix));

    return base64DecodedAuthorizationString.split(":")[0];
  }
}
The Java class from above is packaged in form of a JAR file, which is added to the corresponding HelloWorld project. The invocation is done by using a Java callout during message processing in the pipeline.
Parsing_username_from_HTTP_Basic_auth_token
Parsing out the username from HTTP header using a Java Callout
After deploying the HelloWorld SB service to Oracle Service Bus 12c, the service can be tested using SOAP UI.
SoapUI_Test_HelloWorldService
Resulting salutation after service invocation
As it can be seen from the result, the service works as expected. The resulting salutation contains the username passed with the corresponding authentication information in the HTTP header.
Alle Beiträge von Sven Bernhardt

Sven Bernhardt is a technology enthusiast who works for OPITZ CONSULTING as the Chief Architect on the Corporate Development team. In this role, he manages the technology portfolio and develops Best Practices and Guidelines. In addition, Sven supports his colleagues in implementing Software solutions for Customers. Sven regularly speaks at various conferences about technology or architecture topics. He also shares his thoughts and experiences by writing articles and blog posts. In addition, he's a Kong Champion.

2 Kommentare

  1. Pingback: SOA & BPM Community Newsletter February 2015 | SOA Community Blog

Schreibe einen Kommentar