Archive for Plex Tip

MD5 Hash Encryption in CA Plex

Occasionally you will need to perform a one way hash for passwords. This post shows how to do it using the MD5 algorithm in CA Plex with some java source code.

For background on this, check out this link.

First, create a source code object that looks like this:

MD4Hash

Here is the code to cut and paste:


{

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

String passwordToHash = &(1:).toString();
String generatedPassword = null;
try {
// Create MessageDigest instance for MD5
MessageDigest md = MessageDigest.getInstance(“MD5”);
//Add password bytes to digest
md.update(passwordToHash.getBytes());
//Get the hash’s bytes
byte[] bytes = md.digest();
//This bytes[] has bytes in decimal format;
//Convert it to hexadecimal format
StringBuilder sb = new StringBuilder();
for(int i=0; i< bytes.length ;i++)
{
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
}
//Get complete hashed password in hex format
generatedPassword = sb.toString();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}

&(2:).fromString(generatedPassword);

}

WCF Service Design

In this post, I want to outline two concepts that may help you to create a better service architecture for CA Plex WCF services. First, we should make sure the interfaces are decoupled from the business logic in order to make sure that a change to business functions will not affect the interface used by clients. The second suggestion will make your WCF service more compatible with REST principles and will allow for easier transformation to REST-based services.

Decouple interfaces from business logic

In order to decouple the business logic, we use an adaptor pattern. We create a wrapper function for each method on the interface and define separate input and output parameter fields scoped to the wrapper function.

plextip001

The following images show a simple example using the “SalesSystem” model shipped with CA Plex. On the IOrder interface, we define a method “GetOrderHeader”. This method is implemented by Function “Order.Header.Adaptor.GetOrderHeader”.

plextip002

plextip003

plextip004

Design for stateless operation

Make sure the exposed methods do not require a session (server application state per client). The standard BlockFetch pattern relies on server state (open cursor).

To get more than one instance from a collection, we still have to hard code the number of instances that will be returned as a page from a service (CA Plex limitation). A PageFetch pattern’s interface has to be designed similar to the one shown below:

plextip005

Navigation through pages is by PageNumber.

If there are any questions regarding this post please feel free to contact me at lorenz.alder@cmfirstgroup.com.

 
 
© 2013 CM First Group - All rights reserved