OpenDDS  Snapshot(2023/04/28-20:55)
SecurityRegistry.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_SECURITY_FRAMEWORK_SECURITYREGISTRY_H
9 #define OPENDDS_DCPS_SECURITY_FRAMEWORK_SECURITYREGISTRY_H
10 
11 #include "SecurityPluginInst_rch.h"
12 #include "SecurityConfig_rch.h"
14 
15 #include <dds/DCPS/dcps_export.h>
16 #include <dds/DCPS/PoolAllocator.h>
17 #include <dds/DdsDcpsDomainC.h>
18 
22 
24 
25 #define TheSecurityRegistry OpenDDS::Security::SecurityRegistry::instance()
26 
27 namespace OpenDDS {
28 namespace Security {
29 
30 /**
31  * The TheSecurityRegistry is a singleton object which provides a mechanism to
32  * the application code to configure OpenDDS's security plugins.
33  */
35 public:
36 
37  /// Return a singleton instance of this class.
38  static SecurityRegistry* instance();
39 
40  /// Close the singleton instance of this class.
41  static void close();
42 
43  static const char* DEFAULT_CONFIG_NAME;
44  static const char* BUILTIN_CONFIG_NAME;
45 
46  /// This will shutdown all Security plugin objects.
47  ///
48  /// Client Application calls this method to tear down the security framework.
49  void release();
50 
51  /**
52  * If the plugin is registered then return it. If it's not and attempt_fix is
53  * true, then try to load and return the plugin, otherwise return a nil rch.
54  */
55  SecurityPluginInst_rch get_plugin_inst(
56  const OPENDDS_STRING& plugin_name, bool attempt_fix = true);
57 
58  // Called by plugins to register their factory interface
59  void register_plugin(const OPENDDS_STRING& plugin_name,
60  SecurityPluginInst_rch plugin);
61 
62  // Create or get an existing SecurityConfig object based off the name
63  // in the configuration file
64  SecurityConfig_rch create_config(const OPENDDS_STRING& config_name);
65 
66  SecurityConfig_rch create_config(const OPENDDS_STRING& config_name,
67  SecurityPluginInst_rch plugin);
68 
69  bool has_no_configs() const;
70 
71  SecurityConfig_rch get_config(const OPENDDS_STRING& config_name) const;
72 
73  SecurityConfig_rch default_config() const;
74  void default_config(const SecurityConfig_rch& cfg);
75 
76  SecurityConfig_rch builtin_config() const;
77  void builtin_config(const SecurityConfig_rch& cfg);
78 
79  /// For internal use by OpenDDS DCPS layer:
80  /// Transfer the configuration in ACE_Configuration_Heap object to
81  /// the SecurityRegistry. This is called by the Service_Participant
82  /// at initialization time. This function iterates each section in
83  /// the configuration file, and creates SecurityConfigEntry
84  /// objects and adds them to the registry.
85  int load_security_configuration(ACE_Configuration_Heap& cf);
86 
87 private:
89 
90  static const char* DEFAULT_INST_PREFIX;
91  static const char* DEFAULT_PLUGIN_NAME;
92  static const char* SECURITY_SECTION_NAME;
93  static const char* ACCESS_CTRL_PLUGIN_NAME;
94  static const char* AUTHENTICATION_PLUGIN_NAME;
95  static const char* CRYPTO_PLUGIN_NAME;
96 
97  // Internal class used to store configuration information
99  {
100  public:
101 
102  SecurityConfigEntry(const OPENDDS_STRING& entryNamee);
104 
105  void add_property(const OPENDDS_STRING& name, const OPENDDS_STRING& value);
106 
107  const OPENDDS_STRING& get_entry_name() const { return entry_name_; }
108  const OPENDDS_STRING& get_auth_name() const { return auth_name_; }
109  const OPENDDS_STRING& get_access_control_name() const { return access_ctrl_name_; }
110  const OPENDDS_STRING& get_crypto_name() const { return crypto_name_; }
111 
112  const ConfigPropertyList& get_properties() const { return properties_; }
113 
114  private:
116 
120  ConfigPropertyList properties_;
121  };
122 
124  typedef OPENDDS_MAP(OPENDDS_STRING, SecurityConfig_rch) ConfigMap;
126  typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) LibDirectiveMap;
127  typedef OPENDDS_MAP(OPENDDS_STRING, SecurityConfigEntry_rch) ConfigEntryMap;
128 
130  ~SecurityRegistry();
131 
132  int load_security_sections(ACE_Configuration_Heap& cf, ConfigEntryMap& entries);
133 
134  /// For internal use by OpenDDS DCPS layer:
135  /// Dynamically load the library for the supplied security plugin type.
136  void load_security_plugin_lib(const OPENDDS_STRING& security_plugin_type);
137 
138  bool find_config(const OPENDDS_STRING& name, SecurityConfig_rch& config);
139  bool add_config(const OPENDDS_STRING& name, SecurityConfig_rch& config);
140 
143 
144  ConfigEntryMap config_entries_;
145  ConfigMap config_map_;
147  LibDirectiveMap lib_directive_map_;
150 
151  mutable LockType lock_;
152  mutable LockType default_load_lock_;
153 };
154 
155 } // namespace Security
156 } // namespace OpenDDS
157 
159 
160 #endif /* OPENDDS_DCPS_SECURITYREGISTRY_H */
#define ACE_BEGIN_VERSIONED_NAMESPACE_DECL
const LogLevel::Value value
Definition: debug.cpp:61
#define ACE_SYNCH_MUTEX
void release(T x)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
static const char * AUTHENTICATION_PLUGIN_NAME
static const char * ACCESS_CTRL_PLUGIN_NAME
int close(ACE_HANDLE handle)
#define OPENDDS_STRING
static const char * SECURITY_SECTION_NAME
#define ACE_END_VERSIONED_NAMESPACE_DECL
const char *const name
Definition: debug.cpp:60
#define OPENDDS_MAP(K, V)
DCPS::RcHandle< SecurityConfigEntry > SecurityConfigEntry_rch
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28