There are certain situations that require that certain applications be hidden from users, or maybe that only certain applications be shown to the user.  This is very common when providing remote access to users and you only want certain applications available when accessing the environment remotely, or you want to hide certain applications when accessing the environment via a mobile or tablet, or maybe there are multiple farms in your environment and you only want to provide access to certain applications from each farm through a single site.  Whatever the case may be, unfortunately there is no out-of-the-box solution for this, but it can still be done.

For this solution, filtering is done based on the Description field of the published applications.  That is, applications will be displayed is their description meets a certain criteria, such as a particular character or symbol. For these examples we will be using the @ symbol.

Application filtering for both Services and XenApp sites are covered.  Please note that this requires modification of the Web Interface code and is not officially supported by Citrix Tech Support.

 

XenApp Site

1. Open C:\inetpub\wwwroot\Citrix\<XenAppsite>\app_code\global.asax.cs

2. At the very end add your filter class:

           public class HideAppsFilter : Filter
          {             
                          public bool doFilter(ResourceInfo r, UserContext context)
                          {
                                          if(r is ApplicationInfo)
                                          {
                                                          if(r.getDescription().StartsWith(“@”))
                                                                          return false;
                                                          else
                                                                          return true;
                                          }
                                          return true;
                          }

                          public string getDescription()
                          {
                                          return “Filters out all applications with @ in the begining of their description”;
                          }
          }

 

3. Look for the following line:   WebPN primaryWebPN = builder.createWebPN(CreateWINGConfigFromWIConfig(config), staticEnvAdaptor);

4. Add the following after the above line:    primaryWebPN.addGlobalFilter( new HideAppsFilter() );

This will filter out all applications that have the @ symbol at the beginning of their description.

 

Services Site

1. Open C:\inetpub\wwwroot\Citrix\<PNAgentsite>\app_code\PagesJava\com\Citrix\wi\pna\enumeration.java

2. Look for the following line:  ResourceInfo[] resources = enumRequest.getAllResources();

3. Add the following after the above line:

             java.util.ArrayList filtered = new java.util.ArrayList();

             for (int i=0; i<resources.length; i++)
             {
                        if (resources[i].getDescription().StartsWith(“@”))
                       {
                                filtered.add(resources[i]);
                        }
            }

            resources = (ResourceInfo[]) filtered.toArray( new ResourceInfo[0] );

 

This will filter out all applications that have the @ symbol at the beginning of their description.

In case you’re wondering, filters cannot be applied to Services sites like on XenApp sites.  If you look at the global.asax.cs file you’ll notice that the Services site uses the PNAgentService class which doesn’t support adding filters, as opposed to the WebPN class used by the XenApp site.

If you want to show only applications with the @ symbol instead, all you have to do is change the conditions.

For the XenApp site example:

            // …
            if(r.getDescription().StartsWith(“@”))
                    return true;
            else
                    return false;
            // …

For the Services site example:

            // …
            if (!resources[i].getDescription().StartsWith(“@”))
            // …

 

 

Until next time, Migs.

Miguel Contreras
Senior Consultant
Citrix Consulting