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 portlet developers 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 following modifications without ever having to change your code or re-compile: change the method of passing credentials, switch from basic auth to a preference value, upgrade from portal version 5.0.x to 6.0.x, make use of the Credential Vault, change encryption methods, or even change the encryption key. Only settings in the Web.config file need to be updated. The following sample 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();
ICredentialProvider
can still save developers from having to deal with 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();
// 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.
Namespace: Plumtree.Remote.Portlet
Assembly: idk (in idk.dll)
ICredentialProvider Members | Plumtree.Remote.Portlet Namespace