Plumtree EDK (Enterprise Web Development Kit) 5.4.0

ICredentialProvider Interface

ICredentialProvider is an interface for retrieving the username and password for a backend application that were sent to the portlet in the headers. It provides methods for configuring the credential location and type if a config file cannot be used. In most cases a config file should be used, and the values in the config file will override anything set via the Set methods in this interface.

Using ICredentialProvider allows a portlet developer to retrieve the username and password from the headers in 3 lines of code, no matter how that information is being passed. It also allows: the method of credential passing to change, switching from basic auth to a preference value, upgrading from a 5.0.x Portal to a 6.0.x Portal, making use of the Plumtree Credential Vault, changing encryption methods, or even changing the encryption key; without ever having to change your code or re-compile. Only settings in the web.config file would need to be updated.

The following example code shows how easy it is to retrieve the username and password when using a config file:
// Get an ICredentialProvider instance from the IPortletContext
IPortletContext portletContext = PortletContextFactory.CreatePortletContext(req, resp);
ICredentialProvider cProvider = portletContext.GetCredentialProvider();

// get the username and password
String username = cProvider.GetUsername();
String password = cProvider.GetPassword();

Even in the case where a config file cannot be used, using ICredentialProvider can still save a developer from having to deal with his/her own cipher utilities.

Extracting the username and password when they are passed from the Credential Vault in version 6.0.x still requires very few lines of code, as illustrated in the following example code:
// Get an ICredentialProvider instance from the IPortletContext
IPortletContext portletContext = PortletContextFactory.CreatePortletContext(req, resp);
ICredentialProvider cProvider = portletContext.GetCredentialProvider();

// set the RSA private key used to decrypt the password; this value could
// normally be read from the config file
cProvider.SetPrivateKey(rsaPrivateKeyString);

// get the username and password
String username = cProvider.GetUsername();
String password = cProvider.GetPassword();

When a developer is working with a 5.0.x Portal without the Credential Vault, it is necessary to configure all the parameters that indicate how the credentials are being passed to the portlet.

The following example code retrieves the username and password when they are being sent as user prefs with the parameter names DCTMUsername and DCTMPassword, and the password is RC2 encrypted:
// Get an ICredentialProvider instance from the IPortletContext
IPortletContext portletContext = PortletContextFactory.CreatePortletContext(req, resp);
ICredentialProvider cProvider = portletContext.GetCredentialProvider();

// set the header type and parameter names; these values could normally be
// read from the config file
cProvider.SetCredentialSettingType(SettingType.User);
cProvider.SetUsernameParameterName("DCTMUsername");
cProvider.SetPasswordParameterName("DCTMPassword");

// set the encryption type and key; these values could normally be
// read from the config file
cProvider.SetCredentialEncryptionType(EncryptionType.RC2);
cProvider.SetPrivateKey("skiroblbpauwyryrhfvnmsl");

// get the username and password
String username = cProvider.GetUsername();
String password = cProvider.GetPassword();

For a list of all members of this type, see ICredentialProvider Members.

public interface ICredentialProvider

Requirements

Namespace: Plumtree.Remote.Portlet

Assembly: edk (in edk.dll)

See Also

ICredentialProvider Members | Plumtree.Remote.Portlet Namespace