How Can I Restrict Access to Web Applications Hosted on the NI Web Server?

Updated Oct 20, 2022

Reported In

Software

  • LabVIEW NXG Web Module
  • SystemLink Server
  • G Web Development Software

Issue Details

I have built a web application using the LabVIEW NXG Web Module, G Web Development Software, or another IDE. I want to host this application on the NI Web Server or SystemLink Server. How can I restrict access to the web application that I am hosting on the NI Web Server?

Solution

Custom groups can be added in the NI Web Server Configuration GUI on the Roles tab. When adding users to a Role, you must use Windows accounts or an LDAP server. Use the Authentication tab to enable your preferred user management tool. There are three Roles predefined by the NI Web Server: "admins", "users", and "everyone".

Please note that the term "web application" refers to the collection of web files that make the application. An example web application and XML file are attached. Extract the ZIP file into C:\Program Files\National Instruments\Shared\Web Server\htdocs and follow the steps below.

To create the roles required for the attached example:
  1. Open the NI Web Server Configuration. You can find this in the Start Menu under National Instruments.
  2. Click on the Roles tab
  3. Enter "technicians" as the new role name and click Add role
  4. Give the role a description
  5. Add a user to the Role. If using Windows, click on the Browse button and enter a username
  6. Repeat steps 3-5, entering "operators" as the new role name
  7. Click Apply
 

Follow the steps below to apply your configuration to the NI Web Server.
  1. Place the XML file in C:\Program Files\National Instruments\Shared\Web Server\conf\htpriv.d.
  2. Open a Command Prompt window as administrator and enter "C:\Program Files\National Instruments\Shared\Web Server Config\NIWebServerConfigurationCmd.exe" install privilege -f xxx.xml, where xxx is the name of your XML file (including quotes).
  3. In the same Command Prompt window, enter "C:\Program Files\National Instruments\Shared\Web Server Config\NIWebServerConfigurationCmd.exe" control restart (including quotes).
  4. Navigate to the URL for your web application.

Additional Information

In order to define the roles that can view your web application, you need to create an XML file with access requirements. An example XML file is attached. Each section of the XML file is described below.
  • Application
    • A unique name must be given to the web application. This name is only used internally to the NI Web Server (Line 2)
    • The description for the application will appear on the Applications tab of the NI Web Server Configuration. The description can be localized using the xml:lang property (Line 4)
  • Privileges (Line 6)
    • Each privilege you create will map to a specific Role and directory, defined in the XML. You can think of a Role as a person and a privilege as the "key" that enables them to access a web resource
    • Each privilege requires a unique ID within the XML file (Line 8, 14, 18, 24)
    • The description of the privilege will appear in the Applications tab under your application. (Line 10, 15, 19, 25)
    • The role property defines the Role that will have a privilege (Line 12, 16, 20, 26)
  • Routes
    • A route is what defines the directory that will have privileged access
    • Each privilege you create should map to a directory
    • The path for your directory is relative to the htdocs folder inside of the NI Web Server (C:\Program Files\National Instruments\Shared Web Server\htdocs)
      • In the example XML file, the path "/MyWebApp" refers to the absolute path C:\Program Files\National Instruments\Shared\Web Server\htdocs\MyWebApp
    • There are resources that every WebVI requires in order to load in the browser. To ensure these resources are available to all privilege levels, we create a special privilege and route to these resources (Lines 24-27, 37)
Once you have defined your privileges and routes in the XML file, follow the steps in the Solution field to apply your configuration to the NI Web Server.

Avoid using spaces or special characters in the role id of your XML file, you will get an error when you open NI Web Server Configuration Tool, removing the character and repeating the commands will allow you to solve it.

If you would like to replace the logo that appears on the login screen after navigating to a restricted web resource, change C:\Program Files\National Instruments\Shared\Web Server\htdocs\login\css\style.css to point to a different image located in the C:\Program Files\National Instruments\Shared\Web Server\htdocs\login\assets folder.