Secure and Unsecured Configurations in Plugin in Dynamics 365
Secure and Unsecured Configurations in Plugin in Dynamics 365
We can put a string value on our plugin step, then we can consume those values in our plugin code to do some logic. There are two types of configuration: Secure and Unsecure. The differentiation for these 2 configuration is how the system store the value.
Unsecure Configuration: -
- Unsecure configuration information could be read by any user in CRM. Remember its public information.
- Imagine that you include a plugin, plugin steps and activate them in a solution. Later solution was exported as Managed Solution to another environment. In this scenario, the supplied unsecure configuration values would be available in the new environment.
Secure Configuration: -
- The Secure Configuration information could be read only by CRM Administrators.
- The plugin with secure configuration in a solution was exported as Managed Solution to another environment. In this scenario, the supplied secure configuration information would NOT be available in the new environment. The simple reason behind this is to provide more security to the contents of Secure Configuration
How to Set Secure and Unsecure Configurations: -
We can set Secure and Unsecure Configurations in plugin registration tool while creating a step.
How to Retrieve Secure and Unsecure Configurations in Plugin Code: -
We can retrieve the secure and unsecure configurations using an optional constructor of plugin parameters.
The below code will show that constructor in Plugin.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
namespace Plugin1
{
public class Secure_And_Unsecure_Configurations: IPlugin
{
private readonly string _unsecureString;
private readonly string _secureString;
// Constructor used to retrieve Secure and Unsecure Configuration
public Secure_And_Unsecure_Configurations(string unsecureString, string secureString)
{
_unsecureString = unsecureString;
_secureString = secureString;
}
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
try
{
Entity Contact = (Entity)context.InputParameters["Target"];
Contact["fax"] = _secureString + " " + _unsecureString;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}
}
Comments
Post a Comment