在xslt中登录后屏蔽非XML敏感数据

时间:2016-03-08 08:40:22

标签: xslt ibm-datapower

任何人都可以帮我在Datapower中屏蔽非XML输入。

我首先在Datapower日志存储中记录输入并将该输入用于掩码,我编写了一段适用于XML但不适用于非XML的代码,

附加我的输入非XML和代码以供参考。 附加屏蔽file.xsl有两个模板,一个用于非XML,另一个用于XML。 XML适用于数值而不屏蔽字符。 调用非XML模板但不进行屏蔽。(我可以在系统日志中看到它被调用)

给予屏蔽模板的控件由附加的log.xml文件给出。

快速回复表示赞赏。     谢谢,     Anuj

  
      
  1. 输入非xml。   PCTM-ODS-MTRF-WRSP-RSP PCTM-ODS-MTRF-WRSP-RSP 0200000298111 00000000ODS00000000000000834978953 00LIQ055003241NYYNYNNY 10000020130823Y000000000018765-000000000018765-000000000018765-010000100000000000000000000000-0000000000000000-000000000000000 -

  2.   
  3. 我的代码:在下面的maskFldName是从log.xml文件中调用的。

  4.   
<xsl:template name="NONXMLmaskingTemplate">
    <xsl:param name="maskFldName"/>
            <xsl:param name="Input"/>
        <xsl:variable name="maskchars" select="'******************************'"/>
        <xsl:message>maskFldName:<xsl:copy-of select="$maskFldName"/>
        </xsl:message>
        <xsl:variable name="logInput">
            <!--<dp:serialize select="$Input" omit-xml-decl="yes"/>-->
            <xsl:copy-of select="translate($Input,'&#x22;&#x20;:&#x20;&#x22;','&#x22;:&#x22;')"/>
        </xsl:variable>
        <xsl:message>MaskInputMessage:<xsl:copy-of select="$logInput"/>
        </xsl:message>
        <dp:set-local-variable name="'var://local/input'" value="$logInput"/>
        <xsl:message>!!!!
            <xsl:copy-of select="translate($Input,'&#x20;','')"/>
        </xsl:message>
        <xsl:for-each select="$maskFldName">
            <xsl:variable name="startPosition" select="./@startPosition"/>
            <xsl:variable name="noOfChars" select="./@numOfChars"/>
            <xsl:message>startPosition:<xsl:value-of select="$startPosition"/>
            </xsl:message>
            <xsl:message>noOfChars:<xsl:value-of select="$noOfChars"/>
            </xsl:message>
            <xsl:variable name="maskString" select="substring($maskchars,1,$noOfChars)"/>
            <xsl:message>Matches:<xsl:copy-of select="regexp:match($logInput,.,'g')"/>
            </xsl:message>
            <xsl:message>InputMessage1:<xsl:copy-of select="$Input"/>
            </xsl:message>
            <xsl:for-each select="regexp:match($logInput,.,'g')">
                <xsl:message>InputMessage:<xsl:copy-of select="$logInput"/>
                </xsl:message>
                <xsl:message>ValueX:<xsl:copy-of select="."/>
                </xsl:message>
                <xsl:variable name="strToReplace" select="substring(.,$startPosition,$noOfChars)"/>
                <xsl:variable name="strToReplace2" select="regexp:replace(.,$strToReplace,'g',$maskString)"/>
                <xsl:message>strToReplace:<xsl:copy-of select="$strToReplace"/>
                </xsl:message>
                <xsl:message>strToReplace2:<xsl:value-of select="$strToReplace2"/>
                </xsl:message>
                <dp:set-local-variable name="'var://local/input'" value="regexp:replace(dp:local-variable('var://local/input'),.,'g',$strToReplace2)"/>
            </xsl:for-each> 
            </xsl:for-each>
        <xsl:copy-of select="dp:local-variable('var://local/input')"/>
        <!--    
        If message to be proper xml i.e. &lt; needs to be output as < then the following code to be used

        <xsl:copy-of select="dp:transform('detailLog.xsl',dp:parse(dp:local-variable('var://local/input')))"/>
        <xsl:message>MaskOutputMessage:<xsl:copy-of select="dp:local-variable('var://local/input')"/> </xsl:message>
        -->
    </xsl:template>
</xsl:stylesheet>
  
      
  1. log.xml
  2.   
<?xml version="1.0" encoding="UTF-8"?>
<logConfig>
    <!-- ALL/NONE/FRONT/BACK -->
    <log-enabled value="ALL"/>
    <!-- Y/N -->
    <detail-log-enabled value="Y"/>
    <!-- Y/N -->
    <slim-log-enabled value="N"/>
    <masking isMaskRequire="Y">
        <logpoint id="service_req_entry">
                    <contentType>NONXML</contentType>
            <maskPattern attribute="detail" startPosition="50" numOfChars="4">(PCTM[\w])</maskPattern>
        </logpoint>
        <logpoint id="SCRq-out">
            <contentType>XML</contentType>
            <maskPattern attribute="detail" startPosition="11" numOfChars="4">(Severity>[\w]+&lt;)</maskPattern>
        </logpoint>
    </masking>
</logConfig>

1 个答案:

答案 0 :(得分:-1)

也许您可以使用此技术说明将非xml包装在XML中,然后使用您的XSLT http://www-01.ibm.com/support/docview.wss?uid=swg21321379

相关部分:

将原始文本转换为伪XML:

此示例将以下文本作为输入:

这里有一些文字 还有一些 还有一些

还有一些

等一下,再多一点

创建步骤:

1.在将接收非XML请求的服务中创建Transform操作。

2.选择“在非XML消息中使用此操作中指定的XSLT”以指定这是二进制转换。

3.上传以下样式表作为处理控制文件。

4.单击完成,然后应用所有窗口。

Pageable
  1. 将以下FFD文件从文件管理器上传到local://sample.ffd目录。

        <?xml version="1.0" encoding="utf-8"?>
        <xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:dp="http://www.datapower.com/extensions"
        version="1.0">
    
        <dp:input-mapping href="sample.ffd" type="ffd"/>
    
        <!-- This stylesheet copies the input to the output -->
        <xsl:output method="xml"/>
    
        <xsl:template match="/">
        <xsl:value-of select="sampleFile/sampleTag" disable-output-escaping="yes" />
        </xsl:template>
        </xsl:stylesheet>
    
  2. 发送上面的示例输入将导致以下输出

    <File name="sampleFile">
    <!-- capture all data into this tag -->
    <Field name="sampleTag" />
    </File>