def run(self, params={}): conn = self.connection.conn dn = params.get(Input.DISTINGUISHED_NAME) group_dn = params.get(Input.GROUP_DN) add_remove = params.get(Input.ADD_REMOVE) # Normalize dn dn, search_base = ADUtils.format_dn(dn) dn = ADUtils.unescape_asterisk(dn) self.logger.info(f"Escaped DN {dn}") # Normalize group dn group_dn = ADUtils.format_dn(group_dn)[0] group_dn = ADUtils.unescape_asterisk(group_dn) self.logger.info(f"Escaped group DN {group_dn}") # Check that dn exists in AD if not ADUtils.check_user_dn_is_valid(conn, dn, search_base): self.logger.error(f"The DN {dn} was not found") raise PluginException(cause="The DN was not found.", assistance=f"The DN {dn} was not found.") try: if add_remove == "add": group = extend.ad_add_members_to_groups(conn, dn, group_dn, fix=True, raise_error=True) else: group = extend.ad_remove_members_from_groups(conn, dn, group_dn, fix=True, raise_error=True) except LDAPException as e: raise PluginException( cause= "Either the user or group distinguished name was not found.", assistance= "Please check that the distinguished names are correct", data=e, ) if group is False: self.logger.error( f"ModifyGroups: Unexpected result for group. Group was {str(group)}" ) raise PluginException(preset=PluginException.Preset.UNKNOWN) return {Output.SUCCESS: group}
def run(self, params={}): formatter = ADUtils() conn = self.connection.conn dn = params.get('distinguished_name') group_dn = params.get('group_dn') add_remove = params.get('add_remove') # Normalize dn dn = formatter.format_dn(dn)[0] dn = formatter.unescape_asterisk(dn) self.logger.info(f'Escaped DN {dn}') # Normalize group dn group_dn = formatter.format_dn(group_dn)[0] group_dn = formatter.unescape_asterisk(group_dn) self.logger.info(f'Escaped group DN {group_dn}') if add_remove == 'add': try: group = extend.ad_add_members_to_groups(conn, dn, group_dn) except LDAPInvalidDnError as e: raise PluginException( cause= 'Either the user or group distinguished name was not found.', assistance= 'Please check that the distinguished names are correct', data=e) else: try: group = extend.ad_remove_members_from_groups(conn, dn, group_dn, fix=True) except LDAPInvalidDnError as e: raise PluginException( cause= 'Either the user or group distinguished name was not found.', assistance= 'Please check that the distinguished names are correct', data=e) if group is False: self.logger.error( 'ModifyGroups: Unexpected result for group. Group was ' + str(group)) raise PluginException(preset=PluginException.Preset.UNKNOWN) return {'success': group}
def run(self, params={}): conn = self.connection.conn dn = params.get('distinguished_name') group_dn = params.get('group_dn') add_remove = params.get('add_remove') # Normalize dn dn = ADUtils.dn_normalize(dn) temp_list = ADUtils.dn_escape_and_split(dn) dn = ','.join(temp_list) # Normalize group dn group_dn = ADUtils.dn_normalize(group_dn) temp_list = ADUtils.dn_escape_and_split(group_dn) group_dn = ','.join(temp_list) if add_remove == 'add': try: group = extend.ad_add_members_to_groups(conn, dn, group_dn) except LDAPInvalidDnError as e: raise PluginException( cause= 'Either the user or group distinguished name was not found.', assistance= 'Please check that the distinguished names are correct', data=e) else: try: group = extend.ad_remove_members_from_groups(conn, dn, group_dn, fix=True) except LDAPInvalidDnError as e: raise PluginException( cause= 'Either the user or group distinguished name was not found.', assistance= 'Please check that the distinguished names are correct', data=e) if group is False: self.logger.error( 'ModifyGroups: Unexpected result for group. Group was ' + str(group)) raise PluginException(preset=PluginException.Preset.UNKNOWN) return {'success': group}
def run(self, params={}): conn = self.connection.conn dn = params.get('distinguished_name') dn = ADUtils.dn_normalize(dn) temp_list = ADUtils.dn_escape_and_split(dn) dn = ','.join(temp_list) group_dn = params.get('group_dn') add_remove = params.get('add_remove') if add_remove == 'add': group = extend.ad_add_members_to_groups(conn, dn, group_dn) else: group = extend.ad_remove_members_from_groups(conn, dn, group_dn, fix=True) if group is False: self.logger.log("ModifyGroups: Unexpected result for group. Group was " + str(group)) raise PluginException(PluginException.Preset.UNKNOWN) return {'success': group}
def run(self, params={}): conn = self.connection.conn dn = params.get('distinguished_name') dn = ADUtils.dn_normalize(dn) temp_list = ADUtils.dn_escape_and_split(dn) dn = ','.join(temp_list) group_dn = params.get('group_dn') add_remove = params.get('add_remove') if add_remove == 'add': group = extend.ad_add_members_to_groups(conn, dn, group_dn) else: group = extend.ad_remove_members_from_groups(conn, dn, group_dn, fix=True) if group is False: raise Exception('something went wrong') return {'success': group}