View Javadoc

1   package com.atlassian.plugin;
2   
3   import com.google.common.collect.ImmutableSet;
4   
5   import static com.google.common.base.Preconditions.checkNotNull;
6   
7   /**
8    * Copied from remotable, remove when integrated!
9    */
10  public final class Permissions
11  {
12      // represents all the permissions in one. This is useful for plugins before version 3 which by default require all
13      // permissions
14      public static final String ALL_PERMISSIONS = "all_permissions";
15  
16      // code execution
17      public static final String EXECUTE_JAVA = "execute_java";
18  
19      // sandbox escaping
20      public static final String GENERATE_ANY_HTML = "generate_any_html";
21  
22      private Permissions()
23      {
24      }
25  
26      public static Plugin addPermission(Plugin plugin, String permission, InstallationMode mode)
27      {
28          checkNotNull(plugin);
29  
30          getPluginInformation(plugin).setPermissions(
31                  ImmutableSet.<PluginPermission>builder()
32                          .addAll(getPluginInformation(plugin).getPermissions())
33                          .add(new PluginPermission(permission, mode))
34                          .build());
35          return plugin;
36       }
37  
38      private static PluginInformation getPluginInformation(Plugin plugin)
39      {
40          final PluginInformation pluginInformation;
41          if (plugin.getPluginInformation() != null)
42          {
43              pluginInformation = plugin.getPluginInformation();
44          }
45          else
46          {
47              pluginInformation = new PluginInformation();
48          }
49          return pluginInformation;
50      }
51  }