Thursday, August 23, 2018

Mule 4 - Retrieve client id from an API with client ID enforcement policy


This article describes how one could retrieve the client_id that is consuming an API protected by client ID enforcement policy in API Manager.

Assumptions:
1. The API is exposed from Anypoint Runtime - API Manager
2. The API policy is applied - Client ID enforcement

3. The client is has requested access to the API via exchange
4. The client is using Basic Authentication to login to the API with client id and secret key.

How it works:
Since the client application is using Basic Authentication to access Mulesoft API, we will always have the header value as below. This value is in a fixed format, which is username:password encoded with Base64.



Note: this is not a very secure method as anyone with basic understanding of authentication would be able to decode and decipher the information. As such, this should always be used together with SSL to avoid unauthorized users from retrieving login information.

We can use Dataweave 2.0 to retrieve the header from attributes.headers.authorization.
Following that, Base64 decode the value and split the value to extract the client id.

Example of Dataweave which sets the payload to be the extracted client id:

%dw 2.0
import * from dw::core::Binaries
output application/java
---
(fromBase64((attributes.headers.authorization replace "Basic " with "")) splitBy(":"))[0] default ""

Monday, April 30, 2018

Using secure configuration properties in Mule 4

Overview

The enterprise edition of Mule runtime comes equipped with a Secure Configuration Properties module which is a very neat tool that allows you to hide your keys from prying eyes.
Here is an example of how you could:
  • encrypt strings or entire files
  • reference encrypted properties stored in a file
  • decrypt them with a master key;
  • and use those values to connect to Salesforce cloud to retrieve a list of Accounts.

This article assumes that you have a Salesforce developer account, and possess basic knowledge of Anypoint Studio 7 and various Mule concepts.

1. Get the tool ready, and prepare your encrypted values
Come up with your master key. For this demo I am using My$ecr3tK3y!!
Open DOS and change directory to the folder where your jar file is located.

Thursday, April 26, 2018

Create a domain project in Mule 4

A domain project comes in handy when you want to share resources across different Mule projects in your hosted on-premise Mule Runtime.

In Mule Runtime 4, the resources that can be shared are: 
  • VM
  • TLS Context
  • JMS and JMS Caching Connection
  • Database
  • WMQ
  • JBoss, Bitronix Transaction Manager

Tuesday, April 10, 2018

Invoke static custom Java methods in Mule 4


This example demonstrates how to use Mule 4's Java method to invoke a custom static method with 2 arguments. The custom class is reused from this post: Define and consume custom Java methods using Dataweave 2.0 in Mule 4.

Tips when working with custom java classes in Mule 4:
  1. Include your custom namespace in mule-artifact.json
  2. If you are making references to third party libraries, include them as maven dependencies in pom.xml

This is a simple example using a HTTP Listener to listen for POST requests to http://localhost:8081/list-files2



Define and consume custom Java methods with Dataweave 2.0 in Mule 4


With the introduction of a brand-new Java module in Mule 4, it is now possible to invoke Java classes in a more straightforward manner from the flow or in Dataweave 2.0 itself.

Here is a simple demonstration of file manipulation using custom Java classes and methods in Mule Anypoint Studio 7.1. This step-by-step tutorial shows how to:
1. Create a custom java class to list files recursively for a local or shared network path
2. Invoking this class from Mulesoft Dataweave 2.0 transformations, and filter information.

Pre-requisites:
There is a dependency on apache commons-io, log4j and joda-time as I will be reusing some methods for file manipulation.
You can find the jar file or maven references here:
https://mvnrepository.com/artifact/commons-io/commons-io/2.6
https://mvnrepository.com/artifact/joda-time/joda-time
https://mvnrepository.com/artifact/log4j/log4j


1. Create your Mule project and add maven dependency
Download the apache commons-io jar file, or alternatively include the reference in your maven pom.xml file.
For this example, I am going to include it as a maven dependency. Copy and paste the code below and include it between the dependencies node in pom.xml, before the closing node:

Tuesday, March 27, 2018

Mulesoft Flow to create Service Request in ServiceNow

This article describes how you could create a Mulesoft flow to create a Service Request in Service-Now.

First of all, you will need to have access to a Service-Now Development instance, for example:
* Replace with your company's development instance, if needed.

You will need a username and password to connect to this instance.
Go to https://developer.servicenow.com/ and register for a new account for testing purposes.

Once logged in, go to the MANAGE tab, and select Instance.
Create a new instance, and take note of the URL, admin username and password.
* The instance will be removed if there's no activity in 10 days.



For OOTB requests, there is typically one or more catalog items attached to a request.
Login to your service-now instance, in my case it's https://dev52286.service-now.com
Browse your service catalog and determine what kind of request you would like to make.

Wednesday, January 3, 2018

NodeJS httpServer make REST calls based on querystring parameter

Has dependencies on request, which you could install using the npm command.
In the example below it is a simple web application listening on localhost port 8080.
If the employeeId querystring parameter is detected, regardless of the path, it will make a call to a  RESTful service to retrieve a (fictional) worker information... you get the idea.

 // Include the request library for Node.js. This is not part of native libary.    
 var request = require('request');  
 var http = require('http');  
 var url = require('url');  
 http.createServer(function (req, res) {  
   res.writeHead(200, {'Content-Type': 'text/html'});  
      res.write('Start querying<br />');  
      var u = url.parse(req.url, true);  
      var queryData = u.query;  
      if (queryData.employeeId) {  
           console.log('employeeId: ' + queryData.employeeId);  
           // Sample URL call: http://localhost:8080/anything?employeeId=999  
           // Basic Authentication credentials    
           var username = "username";   
           var password = "password";  
           var authenticationHeader = "Basic " + new Buffer(username + ":" + password).toString("base64");  
           request.get(    
           {  
                uri : "https://service.domain.com/WorkerSnapshot?$format=JSONP&EmployeeID=" + queryData.wwid,  
                rejectUnauthorized: false,  
                json: true, // indicates the returning data is JSON, no need for JSON.parse()  
                headers : { "Authorization" : authenticationHeader }   
           },  
           function (error, response, body) {  
                res.write(body);  
           }  
           );            
      }  
 }).listen(8080);  

Powershell code (local) to list user AD memberships

Powershell code snippet which you could run using PowerShell ISE window. Do not need to install additional modules, unlike Get-ADUser

 # Create searcher object  
 $Domain = "sub.domain.com"  
 $ADsPath = [ADSI]"LDAP://$Domain"  
 $searcher = New-Object System.DirectoryServices.DirectorySearcher($ADsPath)  
 $searcher.SearchScope = "Subtree"  
 $searcher.PageSize = 1000  
 # Restrict properties to load  
 # $searcher.PropertiesToLoad.Add("name")  
 # $searcher.PropertiesToLoad.Add("sAMAccountName")  
 # $searcher.PropertiesToLoad.Add("employeeID")  
 # $searcher.PropertiesToLoad.Add("mail")  
 # $searcher.PropertiesToLoad.Add("userPrincipalName")  
 $searcher.PropertiesToLoad.Add("memberOf")  
 
 $searcher.Filter = "(&(objectClass=User)(samAccountName=username))"   
 $colResults = $searcher.FindOne()  
 
 $objItem = $colResults.Properties  
 $objItem.Item("memberOf") | foreach-object {  
   write-host $_  
 }  

Saturday, December 16, 2017

Penang buffet lunch promotions

Last updated: 12/16/2017

The information is compiled, to my best effort, from other websites, newspaper, and directory listing and MAY NOT REFLECT the most updated information.
Please call directly or go to the official website for the hotels listed for an accurate description.

Place Day Adult Child Remarks Contact
360 at the TOP Sun 58   Until Feb 2018  
Bayview Beach Sun 42 24   6048812123
Café Jen Daily 68   International buffet 6042622622
E&O Mon-Fri 79.3 39.65   6042222000
E&O Sat-Sun 86.3 43.15    
Eastin Mon-Fri 70 35 Executive lunch 6046121128
Eastin Sun 88 34 Eat and swim Sunday  
Equatorial Sat-Sun 98 49 Kampachi 6046327000
Flamingo Hotel Sun 28     6048927111
Four points Sun 54 27    
G Hotel Daily 95   International; buy 2 free 1 Dec 2017 6042380000
Lexis Suites Sunday 88 50 Umi japanese restaurant 6046262888
Lone Pine Sun 85 42.5    
Olive Tree Sat 60 30 Amazing Thai  
Parkroyal Sun 68   Gourmet buffet lunch 6048811133
Rasa Sayang Sun 103 53.3   6048888888
Royale Chulan Penang Sun 62 32 High tea  
St Giles Wembley Thurs 68 34 Japanese and western 6042598000
St Giles Wembley Fri 68 34 Seafood  
St Giles Wembley Sat 68 34 Japanese and Seafood  
St Giles Wembley Sun 68 34 Oriental hi tea  
Sunway Hotel Sat-Sun 28     6042299988
Vistana Hotel Daily 45 22.5 International buffet  

Penang buffet dinner promotions

I thought it would be handy to share (and for myself to refer to this list from time to time when running out of ideas for dinner. In Penang. Really).

Last updated: 12/16/2017

The information is compiled, to my best effort, from other websites, newspapers, and directory listings and MIGHT NOT REFLECT the most updated information.
Please call directly or go to the official website for the hotels listed for an accurate description.


Place Day Adult Child Remarks Contact
360 at the TOP Daily 88   Nyonya and local; Reservation mandatory 6042613540
Café Jen Fri 95   Fisherman's catch  
Café Jen Sat 95   Let's grill  
Cititel Fri 95 48 Seafood promotion 6042911128
Copthorne Orchid Saturday 42 25 Nyonya buffet 6048923333
E&O Sun-Thes 133.3 60.95    
E&O Fri-Sat 133.3 60.95 Add on 66 for alchohol  
Eastin Fri-Sat 110 55 add on 60 for alchohol  
Equatorial Sat 128 64 Kampachi japanese  
Equatorial Fri 128 64 Sensational seafood @ nada lama  
Equatorial Sat 128 64 Carvery buffet @ nada lama  
Flamingo Hotel Fri 76 40    
Flamingo Hotel Sat 85 45 BBQ and Carvery  
Four points Sat 84 42 BBQ and Carvery  
G Hotel Sun-Thur 120   International buffet  
G Hotel Fri-Sat 155   Lava Stone  
G Kelawai Sun-Thur 75   International buffet 6042190000
G Kelawai Fri-Sat 105   Japanese Buffet  
Golden Sands Thurs 98     6048861911
Golden Sands Sat 108   Seafood Heaven with drinks  
Golden Sands Fri 108   Sigi  
Golden Sands Sun 108   Sigi Beach BBQ  
Hard Rock Sat 99 59 Seafood on the rocks 6048811711
Holiday Inn Daily 75     6048866666
Hotel Royal Fri-Sat 41.99 31.99 Royal Buffet Dinner 6042267888
Icnonic Hotel  Fri-Sun 108 54 Seafood 6045059988
Ixora Hotel Sat 78 48 Seafood and BBQ 6043821111
Lone Pine Fri-Sat 102.6 67.6 Seafood BBQ 604886856
Lone Pine Thurs 79.3 39 Flaming roast and Grill  
Maritime Waterfront  Fri 68.9 44 BBQ 6043763797
Olive Tree Daily 88 44 Seafood 6046377777
Parkroyal Fri 148 38 Sunset BBQ and Carvery  
Parkroyal Sat 135 38 Seafood  
Parkroyal Sun 55 27.5    
Rasa Sayang Thurs 98 49 Sunset BBQ  
Rasa Sayang Fri-Sat 198 99 Seafood buffet  
Rasa Sayang Sun-Thur 169 85 International buffet  
Royale Chulan Penang Fri 88 44 Poolside BBQ 6042598888
Royale Chulan Penang Sat 70 35 Hawker's Delight  
St Giles Wembley Mon 95 48 Herbs and Spices  
St Giles Wembley Tue 95 48 Mediterranean  
St Giles Wembley Wed 95 48 Thai  
St Giles Wembley Thurs 95 48 Japanese and western  
St Giles Wembley Fri 95 48 Seafood  
St Giles Wembley Sat 108 54 Japanese and Seafood  
St Giles Wembley Sun 108 54 Oriental  
Sunway Hotel Wed 48 28 Hawker's buffet  
Sunway Hotel Fri-Sat 58 35 Barbeque  
Sunway Seberang Jaya Fri-Sat 45 35 Village Flavour 6043707788
Vistana Hotel Daily 55 27.5 International buffet 6046468000
Vouk Hotel  Fri-Sat 65   Seafood and Japanese buffet 6043708333
Related Posts Plugin for WordPress, Blogger...