StrataFrame Security Documentation Send comments on this topic.
Adding Security to an Existing Application

Glossary Item Box

Adding Security to an Existing Application

For a new application, security may be easily included by using the StrataFrame Windows Application w/ Security template when creating the Visual Studio project.  However, adding security to existing applications requires some manual configuration.

To add security to an existing application, follow the steps below:

  1. Add Security Reference - Add a reference to MicroFour StrataFrame Security within your Visual Studio project.
    1. Open your application's visual studio project.
    2. Within the solution explorer, ensure that the Show All Files option is selected.
    3. Right-Click on the References folder and select the Add Reference option.
    4. Select the MicroFour StrataFrame Security component from the list, and click OK.
  2. Add Security Namespaces - Add the security namespaces to AppMain.vb (Visual Basic) or program.cs (C#).
  3. Add Security Namespaces (Visual Basic)
    Imports MicroFour.StrataFrame.Security
    Imports MicroFour.StrataFrame.Security.BusinessObjects
    Add Security Namespaces (C#)
    using MicroFour.StrataFrame.Security;
    using MicroFour.StrataFrame.Security.BusinessObjects;
  4. Set Data Source Key - Define and set the Security Data Source Key within the SetDataSources() method of AppMain.vb or program.cs. For a detailed description on the data source key, including what it does and how to set it, refer to the Setting the Security Data Source Key help topic.
  5. Security Data Source Key (Visual Basic)
    '-- Set the data source key for the security tables
    SecurityBasics.SecurityDataSourceKey = ""
  6. Create and Show the Login Form - The application login form is launched within the AppMain.vb (program.cs) file.  If desired, a custom form may be used instead of the default StrataFrame login form.
    1. ShowLoginAndInitMainForm() - The login form must be launched within the ShowLoginAndInitMainForm() method of AppMain.vb or program.cs. For more information on configuring the ShowLoginAndInitMainForm() method, refer to the Showing the Initial Login Form topic.
    2. ShowLoginAndInitMainForm (Visual Basic)
      Private Shared Sub ShowLoginAndInitMainForm(ByVal e As ShowLoginAndInitFormEventArgs)
          '-- Set the login form to your custom login form (optional)
          'Login.LoginFormType = GetType(MyLoginForm)
      
          '-- Show the login form and authenticate the user
          e.ShowMainForm = Login.ShowLoginAndAuthUser(True)
      End Sub
    3. Custom Login Form - If a custom login form is desired, it must be created as a new SF Login Form item within the Visual Studio project.  For more information on creating a custom login form, refer to the Creating a Custom Login Form topic. 
  7. Configure the InitApplication() Method - The following items are added to the InitiApplication() method within the AppMain.vb or program.cs file to configure the remaining security options.  The code snippits shown contain all default values for the listed options.
    1. Global Preferences - Required - Retrieve the global preferences from the database using the following method call.  For more information, refer to the Retrieving Global Preferences from the Database help topic.
    2. Retrieve Global Preferences(Visual Basic)
      '-- Retrieve the global preferences
      SFSPreferencesBO.RetrieveSecurityPreferences()
    3. Set Encryption Key - Required - Set the encryption key to be used for user data using the following method call.  For more information, refer to the Specifying the Encryption Key for User Data help topic.
    4. Encryption Key (Visual Basic)
      '-- Set the encryption key and vector for the user data
      SecurityBasics.SetSecurityKeyAndVectorForUserAuthentication("MySecurityKey")
    5. Configure Session Locking - Possibly Required - Start the session locking monitor and configure the quick lock key using the following lines of code.  This is only required if dynamic session locking will be used within your application.  For more information, refer to the Initializing Session Locking help topic.
    6. Session Locking (Visual Basic)
      '-- Start the session locking monitor & set the quick key to lock the application
      SessionLock.StartSessionMonitoring()
      SessionLock.SessionLockKey = Keys.F11
    7. Specify Initial Usernames and Passwords - Optional - Custom users for administration and security maintenance may be created using the code below. 
    8. Note: These users will not appear to end-users within the Security Maintenance and cannot be configured outside of the below code assignments.  As such, dynamic usernames and/or passwords (such as the default administrator password which dynamically includes the current date) are recommended.

      Custom Administrative Usernames and Passwords (Visual Basic)
      '-- Set the administrative and security maintenance usernames and passwords
      SecurityBasics.AdministratorUserName = "Administrator"
      SecurityBasics.AdministratorPassword = "admin" & DateTime.Now.Day.ToString() '-- set the admin password so that it changes from day to day
      SecurityBasics.AdministratorUserPk = -1
      
      SecurityBasics.SecurityMaintenanceUserName = "SecurityUser"
      SecurityBasics.SecurityMaintenancePassword = "mySecurityUserPass1"
      SecurityBasics.SecurityMaintenanceUserPk = -2
    9. Specify Default Security Settings - Optional - The default permission action, blocked message (using plain text or a message key), replacement character, and replacement regex can be specified using the following assignments.
    10. Security Settings (Visual Basic)
      '-- Set the default actions for security enabled objects within the application
      SecurityBasics.DefaultPermissionInfo = New PermissionInfo(PermissionAction.Deny, _
          "Access Denied.", DeniedActions.Message)
      SecurityBasics.DefaultPermissionAction = PermissionAction.Deny
      SecurityBasics.DefaultBlockedMsg = "Access Denied."
      'SecurityBasics.DefaultBlockedMsgKey = "AccessDeniedKey"
      SecurityBasics.BlockedReplacementCharacter = "*"c
      SecurityBasics.BlockedReplacementRegex = "[A-Za-z0-9@]"
    11. Allow or Deny Windows Authentication - Optional - Windows authentication may be explicitly denied using the follwoing line of code.  To allow windows authentication within the application, simply change the below False to a True.
    12. Windows Authentication (Visual Basic)
      '-- Determine whether to allow Windows authentication
      SecurityBasics.AllowWindowsAuth = False