How To set K2 SmartForm Runtime Authorization

This article describes how to restrict access to K2 Smart form at runtime, by allowing Access to only user in a particular Role or Group.

While working with any web application its required to authorized only particular users and group to access the pages. As it concerns to security issue. If will look at SmartForms we face this problem as we don’t have any direct property which can be used for this purpose. Some time we feel it as loophole in functionality as we don’t get any other solution for this.

But here it’s not the case, we can Authorized a group or user to access the form by putting a simple condition during form Initializing.

What to do?

  • Create a K2 Role or Group
  • In Smart Form at Initializing rule Add condition to check if current login User exists or not, In Case if user does not exists redirect to SmartForm having message like “Don’t have access rights.”

To restrict user from accessing SmartForm at runtime, we can manage list of authorized users  using any of the below:.

  • SharePoint Group
  • K2 Role
  • AD Group
  • SQL Server

Example:

Let’s Walk-through an example where I have an SmartForm which return List of Employees and their details and I have requirement to allow access to only authorized group user to view this page.

Step 1: Create K2 Role 

  • Access Your K2 Workspace
  • Click on Management tab and select Console.
  • On L.H.S. under K2 management expend server name tab and then search for Roles node.K2SFAuthorization-1.jpg
  • Right click on Roles Node and Select Create New Role.

k2sfauthorization-2

  • Add the Role detail, map users  or group and Click on SaveK2SFAuthorization-4.jpg

Step 2: Adding condition to SmartForm

    • Here I am using an existing SmartForm, which show’s the employees details.K2SFAuthorization-8
    • Edit this Smartform and do the below changes:
      • Drag and Drop Data label to SmartForm.
      • Here in my example I Have added Data Label with name “dlbHDIsAuthorised”.
      • And set the property visible to False(This will make it invisible at runtime).
        K2SFAuthorization-9
    • Edit Form Initialization rule
      • Under rules select Rule “When the Form is Initializing” and then click on edit.
        K2SFAuthorization-10
      • You will get popup with Form Initializing rule.
        K2SFAuthorization-11
    • Add advance If condition Rule (Keep all existing Action rules inside if condition ).K2SFAuthorization-12
      • Click on Text “an advance condition” and below conditions
      • Left side drag and drop hidden data label control
      • Select operator as Equal
      • Right hands side Enter text True.K2SFAuthorization-13.jpg
    • Add Else Condition
      • Add Action Navigate to another form
      • select the form you want to navigate (In my case I have selected the form to show message to user ” You don’t have access to open the Form”)
        K2SFAuthorization-15
    • Now on the top of if condition rule add Action “Execute a SmartObject method” and do the following changes in configuration.
    • For input mapping under properties Enter Role Name and Drag and Drop FQN for login user from Context browser.
    • For Out mapping under controls for “dlbHdIsAuthorised” map return property from Context browser.
    • Once done close the SmartForm and open it in Runtime mode. If you are part of K2Role you will be able to access the form else you will be redirected to Error message page.

OutPut :

  • When User is part of k2 Role
    K2SFAuthorization-8
  • When User is not Part of K2 Role
    K2SFAuthorization-19

Leave a comment