Encryption Helper Extension Point
When building a report, some properties for a report item are encrypted, such as the password field for data sources. Other options are available for storing sensitive credentials. Data-source connection information can also be stored in external connection profiles that can be encrypted.
Credentials can be set at runtime by calling specific Java classes or session objects. In addition to these approaches, BIRT also provides an extension point to handle encrypting and decrypting properties that support encryption. The encryption helper extension point is very simple to implement.
Listing 10 shows a plugin.xml example.
Listing 10
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.birt.report.model.encryptionHelper"> <encryptionHelper class="org.eclipse.birt.examples.EncryptionHelper" extensionName="PasswordEncryption.encryptionHelper" isDefault="true"> </encryptionHelper> </extension> </plugin>
The class attribute of the encryptionHelper node specifies a class that implements the IEncryptionHelper interface. This interface contains only two method declarations, encrypt and decrypt, as shown in Listing 11.
Listing 11
package org.eclipse.birt.examples; import org.eclipse.birt.report.model.api.extension.IEncryptionHelper; public class EncryptionHelper implements IEncryptionHelper { public String decrypt(String string) { //provide your decryption here return string; } public String encrypt(String string) { //provide your encryption here return string; } }
The encrypt method is called when a field in the BIRT design needs to be encrypted and decrypt is called when an encrypted field needs to be decrypted.
The isDefault attribute of the encryptionHelper node in the plugin.xml file determines whether the encryption helper is the default for all fields that support encryption. If this attribute is set to false, the encryption extension isn't called unless you've specifically pointed to it in the report XML using the encryptionID attribute, as shown in Listing 12. If the value is true, the extension will be called for all fields that are encrypted.
Listing 12
<encrypted-property name="odaPassword" encryptionID="PasswordEncryption.encryptionHelper">test</encrypted-property>
Refer to the earlier section "Exporting and Deploying an Extension Point Plug-in" for information on how to deploy the encryption helper extension point.