Sun Java System Portal Server Secure Remote Access 7.2 管理指南

Rewriter 簡介

Secure Remote Access 的 Rewriter 元件能讓一般使用者利用修改網頁上的統一資源識別碼 (Uniform Resource Identifier, URI) 參照,以指向閘道從而瀏覽企業內部網路。URI 可定義於任何已註冊名稱空間內封裝名稱的方法,並以該名稱空間為其加標記。最常見的 URI 類別為單一資源定址器 (Uniform Resource Locator, URL)。Rewriter 僅支援 HTTP 或 HTTPS。不論協定的大小寫為何都支援。Rewriter 僅支援相對 URL 中包含反斜線符號。


範例 4–1 重新寫入 URL

http://abc.sesta.com\\index.html 會被重新寫入。

這些 URL 不會被重新寫入:http:\\\\abc.sesta.com http:/abc.com


字元集編碼

HTTP 標準需要 HTTP 標頭或 HTML 中繼標記為網頁指定字元集。但是有時候此資訊沒有辦法使用。字元集必須為已知,如此資料編碼的設定以及資料的顯示才會依照建立的想法進行。

要偵測字元集,請從 Java Enterprise System Accessory CD 安裝 SUNWjchdt 套裝軟體。如果已安裝此產品,Rewriter 將會偵測到它並在需要時使用。


備註 –

使用此產品將會影響效能,因此應該只在需要時才安裝此產品。如需安裝、配置與用法的詳細資訊,請參閱 jcharset_readme.txt


Rewriter 使用方案

使用者試圖經由閘道存取企業內部網路網頁時,即可使用 Rewriter 來順利存取網頁。URLScraper 與閘道會使用 Rewriter。

URLScraper

URL Scraper 提供者會從配置的 URI 取得內容。將這些 URI 傳送至瀏覽器前,它會將所有相對 URI 展開為絕對 URI。

例如,如果使用者嘗試用下列方式存取網站:

<a href="../mypage.html">

Rewriter 會將此轉譯為:

<a href="http://yahoo.com/mypage.html">

其中 http://yahoo.com/test/ 是網頁的基準 URL。

如需 URLScraper 提供者的詳細資訊,請參閱「Sun Java System Portal Server 管理指南」。

閘道

閘道從網際網路入口網站獲取內容。將內容傳送至瀏覽器前,它會將閘道 URI 置於目前的 URI 之前,如此來自瀏覽器的後續 URI 請求都可到達閘道。

例如,如果使用者試圖用以下方式存取網際網路機器上的 HTML 網頁:

<a href="http://mymachine.intranet.com/mypage.html>"

Rewriter 會引用閘道置於這個 URL 之前,如下所示:

<a href="https://gateway.company.com/http://mymachine.intranet.com/ mypage.html>"

使用者點選與此控點相關的連結時,瀏覽器便會連絡閘道。閘道會從 mymachine.intranet.com 取得 mypage.html 的內容。

閘道使用多種規則來判定是否需重新寫入取得網頁中的元素。

撰寫規則集

如需定義規則集的詳細資訊,請參閱「Portal Server 管理指南」。在建立新規則集後,您必須定義必要的規則。

本節涵蓋下列主題:

公開介面 (規則集 DTD)

規則集 DTD:

<?xml version="1.0" encoding="UTF-8"?>
<!--
The following constraints are not represented in DTD, but taken care of programmatically
    1. In a Rule, All Mandatory attributes cannot be "*".
    2. Only one instance of the below elements is allowed, but in any order.
    1)HTMLRules
    2)JSRules
    3)XMLRules
    3. ID should always be in lower case.
-->
<!ENTITY % eURL ’URL’>
<!ENTITY % eEXPRESSION ’EXPRESSION’>
<!ENTITY % eDHTML ’DHTML’>
<!ENTITY % eDJS ’DJS’>
<!ENTITY % eSYSTEM ’SYSTEM’>

<!ENTITY % ruleSetElements ’(HTMLRules | JSRules | XMLRules)?’>
<!ENTITY % htmlElements ’(Form | Applet | Attribute)*’>
<!ENTITY % jsElements ’(Variable | Function)*’>
<!ENTITY % xmlElements ’(Attribute | TagText)*’>

<!ELEMENT RuleSet (%ruleSetElements;,%ruleSetElements;,%ruleSetElements;)>
<!ATTLIST RuleSet
    id ID #REQUIRED
    extends CDATA "none"
>

<!-- Rules for identifying rules in HTML content -->
<!ELEMENT HTMLRules (%htmlElements;)>
<!ELEMENT Form EMPTY>
<!ATTLIST Form
    name CDATA #REQUIRED
    field CDATA #REQUIRED
    valuePatterns CDATA ""
    source CDATA "*"
>

<!ELEMENT Applet EMPTY>
<!ATTLIST Applet
    code CDATA #REQUIRED
    param CDATA "*"
    valuePatterns CDATA ""
    source CDATA "*"
>

<!-- Rules for identifying rules in JS content -->
<!ELEMENT JSRules (%jsElements;)>
<!ELEMENT Variable EMPTY>
<!ATTLIST Variable
    name CDATA #REQUIRED
    type (%eURL; | %eEXPRESSION; | %eDHTML; | %eDJS; | %eSYSTEM;) "EXPRESSION"
    source CDATA "*"
>

<!ELEMENT Function EMPTY>
<!ATTLIST Function
    name CDATA #REQUIRED
    paramPatterns CDATA #REQUIRED
    type (%eURL; | %eEXPRESSION; | %eDHTML; | %eDJS;) "EXPRESSION"
    source CDATA "*"
>

<!-- Rules for identifying rules in XML content -->
<!ELEMENT XMLRules (%xmlElements;)>
<!ELEMENT TagText EMPTY>
<!ATTLIST TagText
    tag CDATA #REQUIRED
    attributePatterns CDATA ""
    source CDATA "*"
>

<!ELEMENT Attribute EMPTY>
<!ATTLIST Attribute
    name CDATA #REQUIRED
    tag CDATA "*"
    valuePatterns CDATA ""
    type (%eURL; | %eDHTML; | %eDJS; ) "URL"
    source CDATA "*"
>

備註 –

除必要的屬性值不能只有 * 之外,您可使用 * 做為規則值的一部分。會忽略這類規則,但是訊息會記錄在 RuleSetInfo 記錄檔中。如需此記錄檔的資訊,請參閱除錯檔案名稱


XML DTD 範例

本節包含一範例規則集。我們使用第 140 頁的「案例研究」來說明 Rewriter 解譯這些規則的方式。

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Rules for integrating a mail client with the gateway.
-->
<!DOCTYPE RuleSet SYSTEM "jar://rewriter.jar/resources/RuleSet.dtd">
<RuleSet type="GROUPED" id="owa">
<HTMLRules>
<Attribute name="action" />
<Attribute name="background" />
<Attribute name="codebase" />
<Attribute name="href" />
<Attribute name="src" />
<Attribute name="lowsrc" />
<Attribute name="imagePath" />
<Attribute name="viewClass" />
<Attribute name="emptyURL" />
<Attribute name="draftsURL" />
<Attribute name="folderURL" />
<Attribute name="prevMonthImage" />
<Attribute name="nextMonthImage" />
<Attribute name="style" />
<Attribute name="content" tag="meta" />
</HTMLRules>
<JSRules>
<!-- Rules for Rewriting JavaScript variables in URLs -->
<Variable name="URL"> _fr.location </Variable>
<Variable name="URL"> g_szUserBase </Variable>
<Variable name="URL"> g_szPublicFolderUrl </Variable>
<Variable name="URL"> g_szExWebDir </Variable>
<Variable name="URL"> g_szViewClassURL </Variable>
<Variable name="URL"> g_szVirtualRoot </Variable>
<Variable name="URL"> g_szBaseURL </Variable>
<Variable name="URL"> g_szURL </Variable>
<Function name="EXPRESSION" name="NavigateTo" paramPatterns="y"/>
</JSRules>
<XMLRules>
<Attribute name="xmlns"/>
<Attribute name="href" tag="a"/>
<TagText tag="baseroot" />
<TagText tag="prop2" />
<TagText tag="prop1" />
<TagText tag="img" />
<TagText tag="xsl:attribute"
attributePatterns="name=src" />
</XMLRules>
</RuleSet>

撰寫規則的步驟

撰寫規則的一般程序如下:

規則集指導方針

建立規則集時,請記住:

定義規則集根元素

規則集根元素具有兩種屬性:

使用遞迴功能

Rewriter 使用遞迴功能在符合的字串式樣的結尾搜尋是否有相同的式樣。

例如,當 Rewriter 剖析下列字串時:

<a href="src=abc.jpg,src=bcd.jpg,src=xyz.jpg>

規則

<Attribute name="href" valuePatterns="*src=**"/>

僅會重寫第一個出現的式樣,其形式如下:

<a href="src=http://jane.sun.com/abc.jpg>

如果您使用遞迴選項

<Attribute name="href" valuePatterns="REC:*src=**"/>;

Rewriter 會搜尋相同的式樣,直至符合字串式樣的結尾,因此輸出將會是:

<a href="src=http://jane.sun.com/abc.jpg,src=http://jane.sun.com/bcd.jpg,src=http://jane.sun.com/xyz.jpg>