|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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.
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.xml 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();Even in the case where a config file cannot be used, using
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();When working with a 5.0.x portal without the Credential Vault, it is necessary to define 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();
Method Summary | |
CredentialSource |
getCredentialSource()
Returns the source of the credentials as a CredentialSource object. |
java.lang.String |
getPassword()
Returns the decrypted password for a backend application. |
java.lang.String |
getUsername()
Returns the username for a backend application. |
void |
setCredentialEncryptionType(EncryptionType type)
Specifies the type of encryption used to encrypt the password that was sent to the portlet. |
void |
setCredentialSettingType(SettingType type)
Specifies which type of setting is being used to pass the credentials to the portlet. |
void |
setPasswordParameterName(java.lang.String paramName)
Specifies the name of the setting that contains the password for the backend application. |
void |
setPrivateKey(java.lang.String key)
Specifies the private key to use to decrypt the encrypted password that was sent to the portlet. |
void |
setUsernameParameterName(java.lang.String paramName)
Specifies the name of the setting that contains the username for the backend application. |
Method Detail |
public java.lang.String getUsername()
public java.lang.String getPassword()
public void setCredentialSettingType(SettingType type)
type
- the type of setting being used to send credentials to the portletpublic void setUsernameParameterName(java.lang.String paramName)
paramName
- the name of the username settingpublic void setPasswordParameterName(java.lang.String paramName)
paramName
- the name of the password settingpublic void setCredentialEncryptionType(EncryptionType type)
type
- the type of encryptionpublic void setPrivateKey(java.lang.String key)
CredentialEncryptionType
must be set with the
setCredentialEncryptionType
method. This value is
used only if it is not specified in a config file (web.xml). Settings
in the config file override anything set with this method.
The config file parameter for this setting depends on the type of encryption being
used, and can be one of the following: RSAPrivateKey, RC2PrivateKey, or AESPrivateKey.
key
- the key used for decryptionpublic CredentialSource getCredentialSource()
CredentialSource
object.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright ©2010 Oracle® Corporation. All Rights Reserved.