def create_in_document(self, ctx, charset=None): super(BaseSmev, self).create_in_document(ctx, charset) in_document, _ = ctx.in_document if ctx.udc is None: ctx.udc = _utils.EmptyCtx() ctx.udc.in_smev_header_document = in_document.find( ".//{{{smev}}}Header".format(**self._ns)) ctx.udc.in_smev_message_document = in_document.find( ".//{{{smev}}}Message".format(**self._ns)) ctx.udc.in_smev_appdoc_document = in_document.find( ".//{{{smev}}}AppDocument".format(**self._ns)) message_data = in_document.find( ".//{{{smev}}}MessageData".format(**self._ns)) if any( map(_utils.isnone, (ctx.udc.in_smev_message_document, message_data))): raise _Fault("SMEV-100010", "Invalid configuration!") map( self._validate_smev_element, filter(_utils.notisnone, (ctx.udc.in_smev_message_document, ctx.udc.in_smev_header_document, message_data))) method_data = message_data.find( ".//{{{smev}}}AppData".format(**self._ns)).getchildren() method = in_document.find(".//{{{0}}}Body".format( _ns.soapenv)).getchildren()[0] method.clear() method.extend(method_data) self.event_manager.fire_event('smev_in_document_built', ctx)
def create_in_document(self, ctx, charset=None): super(BaseSmev, self).create_in_document(ctx, charset) in_document, _ = ctx.in_document if ctx.udc is None: ctx.udc = _utils.EmptyCtx() ctx.udc.in_smev_header_document = in_document.find( ".//{{{smev}}}Header".format(**self._ns)) ctx.udc.in_smev_message_document = in_document.find( ".//{{{smev}}}Message".format(**self._ns)) ctx.udc.in_smev_appdoc_document = in_document.find( ".//{{{smev}}}AppDocument".format(**self._ns)) message_data = in_document.find( ".//{{{smev}}}MessageData".format(**self._ns)) if any(map(_utils.isnone, (ctx.udc.in_smev_message_document, message_data))): raise _Fault("SMEV-100010", "Invalid configuration!") map(self._validate_smev_element, filter(_utils.notisnone, ( ctx.udc.in_smev_message_document, ctx.udc.in_smev_header_document, message_data))) method_data = message_data.find( ".//{{{smev}}}AppData".format(**self._ns)).getchildren() method = in_document.find( ".//{{{0}}}Body".format(_ns.soapenv)).getchildren()[0] method.clear() method.extend(method_data) self.event_manager.fire_event('smev_in_document_built', ctx)
def _validate_smev_element(self, element): self._smev_schema = self._smev_schema or _utils.load_schema( self._smev_schema_path) if not self._smev_schema.validate(element): errors = "\n".join( (err.message for err in self._smev_schema.error_log)) raise _Fault( "SMEV-102000", "Message didn't pass validation checks!" " Errors:\n{0}".format(errors))
def _validate_smev_element(self, element): self._smev_schema = self._smev_schema or _utils.load_schema( self._smev_schema_path) if not self._smev_schema.validate(element): errors = "\n".join(( err.message for err in self._smev_schema.error_log)) raise _Fault( "SMEV-102000", "Message didn't pass validation checks!" " Errors:\n{0}".format(errors))
def validate(self, envelope): """ Проверяем, удовлетворяет ли конверт требованиям безопасности :param envelope: Soap конверт :raises: spyne.model.fault.Fault """ logger.info("Validate signed document") try: verify_document(envelope, self.certificate) except (_crypto.Error, ValueError), e: logger.error("Signature check failed! Error:\n{0}".format( unicode(e))) raise _Fault( faultstring="Signature check failed! Error:\n{0}".format( unicode(e)))
Проверяем, удовлетворяет ли конверт требованиям безопасности :param envelope: Soap конверт :raises: spyne.model.fault.Fault """ logger.info("Validate signed document") try: verify_document(envelope, self.certificate) except (_crypto.Error, ValueError), e: logger.error("Signature check failed! Error:\n{0}".format( unicode(e))) raise _Fault( faultstring="Signature check failed! Error:\n{0}".format( unicode(e))) except _crypto.InvalidSignature: raise _Fault(faultstring="Invalid signature!") class Soap11WSSE(_Soap11): """ Протокол SOAP с поддержкой WS-Security :param wsse_security: Объек WS-Security :type wsse_security: wsfactory.spyne_smev.security.BaseWSSecurity """ def __init__( self, app=None, validator=None, xml_declaration=True, cleanup_namespaces=True,