MuleSoft Technical Guides

Guides for MuleSoft Developers.

Until Successful Scope in Mule 

Until Successful Scope in Mule 

“Until Successful” is the scope for executing a  set of components as one unit.

It processes all the components within it until they produce a successful result. If one processor within the scope fails, it retries the enclosed processors again. The number of retries is configurable and decided by the user.

Configuration

  1. Design a new flow and configure an HTTP listener for it.
  2. Create one more flow using the same HTTP Config but listening on a different path.
  3. From the first row, call the second flow using HTTP Requester.

  1. Wrap the HTTP requester under Until Successful Keep the default values for Max  Retries and Milliseconds Between Retries.

until-successful-properties

  1. To test the flow, change the initial state of the second flow to stopped and run.
  2. The requester will fail, and the scope will retry five times before throwing the error.

 

<flow name="until-succesfullFlow" >

                        <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/us"/>

                        <until-successful maxRetries="5" doc:name="Until Successful" >

                                    <http:request method="GET" doc:name="Request" config-ref="HTTP_Request_configuration" path="/us-demo"/>

                        </until-successful>

                        <logger level="INFO" doc:name="Logger" message="Success"/>

            </flow>

            <flow name="until-succesfullFlow1" initialState="stopped">

                        <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/us2"/>

                        <logger level="INFO" doc:name="Logger" message="US2 flow"/>

            </flow>

 

Variable Propagation

New variables created within the scope are not available for the subsequent execution, and any modifications to variables created outside the scope are not available to the subsequent execution. Each execution cycle starts with a fresh set of variables.

 

Thanks for reading. Find more MuleSoft Best practices at Caelius Consulting Resource Centre.

 

Multi Factor Authentication in MuleSoft Anypoint Platform

Multi Factor Authentication in MuleSoft Anypoint Platform

Multi-Factor Authentication (MFA) is a security mechanism wherein a user is granted access only after providing more than one authentication method.

An organization administrator can make it mandatory for all non-SSO users to use MFA, exempt some accounts from this or make it optional for users – allowing users to enable it if they want.

MFA setting does not apply to SSO users; they have to enable MFA at their respective Identity provider level.

 

Following are the methods to implement the Anypoint platform Multi-Factor Authentication:

  1. One-Time Password Generator: Registers an authenticator app to create verification codes that you provide when logging in to Anypoint Platform.
  2. Built-in Authenticator: Registers a physical authentication device, such as Touch ID or Windows Hello, to verify your identity when logging in to Anypoint Platform.
  3. Security Key: Registers a USB security key, such as Yubico YubiKey or Google Titan Security Key, to your account. The device is then authorized to create verification codes that you provide when logging in to Anypoint Platform.
  4. Salesforce Authenticator: Registers the Salesforce Authenticator mobile app to create verification codes that you provide when logging in to Anypoint Platform.

In this article, we will look at the last method, i.e., Salesforce Authenticator.

The process to apply MFA

  1. Login to Anypoint platform account, navigate to Access Management > Multi-Factor Auth

mfa-setting

Two options are there: Optional and Required. By default, it is optional, meaning the organization does not require MFA, but users can enable it. Selecting Required makes it mandatory for all users to use MFA. Admin can exempt some accounts from it.

Let’s make it required.

  1. Either log out, log in again, or open the Platform login page using a different browser or incognito. After entering the username and password, it will ask to use one of the four MFA methods.
  2. Here, we will go with the Salesforce Authenticator, for which the Salesforce authenticator should be pre-installed on the phone. Finish the pretty simple setup.

For users, Login to the MuleSoft Anypoint platform will require authentication using the Salesforce Authenticator app.

On selecting the alternative option in the first step, there will not be a prompt for another verification for Logging-in. Enabling MFA, in this case, is also possible by navigating to profile > Configure Multi-Factor Authentication (MFA) and setting up the MFA method.

SFTP in MuleSoft

SFTP (2)

SFTP stands for SSH File Transfer Protocol which, unlike the FTP protocol, is secure. SFTP in MuleSoft is a secure protocol for transferring files that work more or less the same as FTP but safe. Since the files are transmitted over a secure channel, it prevents files from unauthorized access and any content or password sniffing. SFTP requires a username and password to connect as well as using an SSH key.

Creating a local SFTP server

Download Rebex Tiny SFTP Server for creating an SFTP server on a local machine. Once downloaded, unzip the contents and Browse to the folder and start the server by clicking on the RebexTinySftpServer application file.

sftp-rebex

User and password are displayed on the Rebex Server screen. Create a new folder for reading and writing files under the User root directory displayed on the Rebex start screen.

SFTP Configuration

Create a global SFTP Configuration with details shown on Rebex screen.

<sftp:config name="SFTP_Config" doc:name="SFTP Config">
	<sftp:connection host="localhost" username="tester" password="password" />
</sftp:config>

Operations supported 

  1. List: Returns list of all files under a directory.
  2. Read: Read a specific file from a specified location.
  3. Write: Write to the specified directory.
  4. On New or Updated: Triggers the flow when a new file is created or updated which matches the criteria.
  5. Copy: Copy a given file.
  6. Move: Move a given file
  7. Delete: Deletes the specified file.
  8. Create Directory: Create a directory at the given path.
  9. Rename: Renames a file

List

This operation lists all the files in a directory. Returns an iterable object which is an array of payloads from each file.

sftp-list-flow

The directory whose files are listed is specified in the directory path

sftp-list-prop

The payload for each file can be accessed using payload[index].payload. The file metadata like name, creation time, size, path etc is saved in typedAttributes and can be accessed like payload[index].typedAttributes

sftp-list

The value of payloads in the returned array depends on whether it’s a subfolder or file. For subfolders the payload is null, and for the file it’s the content of the file. By default, List doesn’t look inside subfolders. This can be achieved by setting recursive to true. The operation can be customized to list files depending on the last updated time, name pattern, size etc, using File Matching Rules.

Read

Read operation returns the file content as payload and metadata in the attributes.

The MIME type of file is determined by file format but can be done using outputMimeType parameter is required to set explicitly.

Write

Writes the content to a file either by creating a new file or overwriting the existing one.

sftp-write

Parameters required by the Write operation

  1. Path: path where the file is written to
  2. Content: The content to write to file. The default value is
  3. Create Parent Directories: When checked, the target Path directory will be created when writing otherwise, the directory should be created beforehand.
  4. Write Mode: An Enumeration value for file write mode. OVERWRITE: overwrite existing file, default Value. APPEND: append the data to any existing file. Creates one if no file exists. CREATE_NEW: Create a new file every time, if any existing file, SFTP:FILE_ALREADY_EXISTS error is thrown.

On New or Updated File

This operation acts as a listener and polls the configured directory for any new or updated file, and triggers the flow when there is one.

sftp-listen

Parameters required by this operation

  1. Directory: Directory to poll for listening.
  2. Matcher: Matcher used to specify the criteria to pick up the file.
  3. Scheduling Strategy: Configures the scheduler that triggers the polling.
  4. Recursive: Whether to poll files in the subdirectories also.
  5. Auto Delete: Whether to delete the file after reading. False by default.
  6. Move To Directory: Each processed file be moved to the directory specified takes absolute path. Also, if the file is already in the target directory, it will not be moved.
  7. Rename To: Rename the file when moving.

Copy and Move

SFTP connector supports operations to copy or move a directory/file.

sftp-copy

<sftp:copy doc:name="Copy" config-ref="SFTP_Config" sourcePath="/poc/test.txt" targetPath="/poc/New Folder/" />
<sftp:move doc:name="Move" config-ref="SFTP_Config" sourcePath="/poc/test.txt" targetPath="/poc/New Folder"/>

Delete

The function Deletes the file or directory specified in the path.

<sftp:delete doc:name="Delete" config-ref="SFTP_Config" path="/poc/Data"/>

Throws FILE:ILLEGAL_PATH error if specified file is not present.

 

Create Directory

Creates a new directory on Directory Path. Directory Path should be an absolute path. Throws SFTP:FILE_ALREADY_EXISTS error if directory already exists.

<sftp:create-directory doc:name="Create directory" config-ref="SFTP_Config" directoryPath="/poc/Data"/>

Rename

Renames the file

<sftp:rename doc:name="Rename" config-ref="SFTP_Config" path="/poc/test.txt" to="test-3.txt"/>

 

This is all about STFP in MuleSoft. Feel free to leave comments on this article.

FInd more tips and tricks on MuleSoft at our Resource Centre.

 

 

 

Business Groups in MuleSoft CloudHub

Creating Business Groups in MuleSoft

Business groups are self-contained resource groups that contain MuleSoft Anypoint Platform resources such as applications and APIs. Business groups provide a way to separate and control access to MuleSoft Anypoint Platform resources because users have access only to the business groups in which they have a role. In this article we will discover how to create business groups on MuleSoft CloudHub.

Business groups reside within the master organization. The groups are organized in a hierarchical tree where the top-level business group is the root. Each business group you create has one direct parent and can have multiple children.

Business groups are required when your organization has multiple teams from different departments creating and publishing resources on Mulesoft Cloudhub iPaaS. You don’t want the resources created by one department to be visible to their team and sub department’s teams; for example, the finance department should only have visibility to API’s and exchange resources created by the finance and accounting, not the HR team.

Creating business groups in Mulesoft Cloudhub is pretty straightforward. However, before starting following the below steps, you need to make sure that your user has the organization administrator role, and your organization allows the creation of business groups. Also, business groups are hierarchical; the owner of a parent business group automatically has and retains administrator permissions for any child business group of that parent, even if they make another organization Administrators user owner of a child business group.

1.In the Anypoint Platform Side Panel Access Management, in the left menu, click organization.

Anypoint Platform Side Panel

2.Click on the blue plus sign or the Add Business Group button. You will get the following pop up:

Business group creation in MuleSoft

3. Allocate the resources and give business group and Owner name in the pop up.

Creating Business Group In MuleSoft

 

4. Click on Add business group after allocating the resources and giving the required permissions.

5. Now you can switch between business groups by clicking on the menu at the top right corner.

Feel free to leave comments on creating business groups in MuleSoft CloudHub.

Find more MuleSoft Tips & tricks right here on Caelius Consulting Inc Resource Centre.