You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@knox.apache.org by Christopher Jackson <ja...@gmail.com> on 2018/07/27 17:02:55 UTC

Possible to rewrite query parameter value?

Hi All,

Curious if it is possible to rewrite a query parameter value to append a string to the original value? I tried the below configuration but I don’t think its valid as requests to the resource were just hanging.

Entry from service.xml for the particular path:

<rewrite apply=“MYSERVICE/myapp/outbound/redirect/headers" to="response.headers"/>


Entries in rewrite.xml:

<rule dir="OUT" name="MYSERVICE/myapp/outbound/redirect/headers/location">
    <match pattern=“*://*:*/myapp?originalUrl={originalurl}&{**}"/>
    <rewrite template="{$frontend[url]}/myservice/myapp?originalUrl={originalurl}&{**}"/>
</rule>

<filter name="MYSERVICE/myapp/outbound/redirect/headers">
    <content type="application/x-http-headers">
        <apply path="Location" rule="MYSERVICE/myapp/outbound/redirect/headers/location"/>
    </content>
</filter>

An additional concern I have with the above attempted approach is I don’t think that I can guarantee the order of the query parameters.



An example of what I would like to see happen is the header content of a 302 response with a Location header value of:

https://host.example.com:9443/myapp?originalUrl=/some/path/&mode=EI&wrongRole=true

to be rewritten to:

https://host.example.com:8443/gateway/default/myservice/myapp?originalUrl=/gateway/default/myservice/myapp/some/path/&mode=EI&wrongRole=true

In summary the result would have the frontend[url] replace the internal destination and the originalUrl query parameter would have the frontend[path] appended to its original value.

Anyone have any ideas on how to achieve this?

Regards,
Christopher Jackson

Re: Possible to rewrite query parameter value?

Posted by Sandeep Moré <mo...@gmail.com>.
You can avoid using those functions, you can do something like this

<match
> pattern=“{scheme}://{host}:{port}/{gateway}/{topology}/myapp?originalUrl={originalurl}&{**}"/>
>



>   <rewrite
> template="{$frontend[url]}/myservice/myapp?originalUrl=/{gateway}/{topology}/{originalurl}&{**}"/>


The prefix, postfix are a variation of frontend, they just help to add
content around URL. The limitation with these variables (postfix, prefix,
frontend) is that they have to be at the beginning of the template.

Hope this helps.
Sandeep

On Fri, Jul 27, 2018 at 3:18 PM Christopher Jackson <
jackson.christopher.lee@gmail.com> wrote:

> Hi Sandeep,
>
> Unfortunately that function is only available in 1.10 or 0.13 or later
> which I don’t have access to. Do the $postfix, $prefix, and $infix also
> work with frontend ‘path’ instead of ‘url’?
>
> Regards,
> Christopher Jackson
>
>
> On Jul 27, 2018, at 2:16 PM, Sandeep Moré <mo...@gmail.com> wrote:
>
> It should be possible using parameterized rewrite variables, this is an
> example from Spark History rewrite rules
>
> <!-- re-write rule for location when SHS redirects to Knox SSO login page
> -->
> <rule dir="OUT"
> name="SPARKHISTORYUI/sparkhistory/outbound/headers/location/sso">
>   <match
> pattern="{scheme}://{host}:{port}/{gateway}/{knoxsso}/{api}/{v}/websso?originalUrl={**}"/>
>   <rewrite
> template="{scheme}://{host}:{port}/{gateway}/{knoxsso}/{api}/{v}/websso?originalUrl={$postfix[url,/sparkhistory/]}"/>
> </rule>
> <filter name="SPARKHISTORYUI/sparkhistory/outbound/headers/sso/filter">
>   <content type="application/x-http-headers">
>     <apply path="Location"
> rule="SPARKHISTORYUI/sparkhistory/outbound/headers/location/sso"/>
>   </content>
> </filter>
>
> or in the above example
>
> <rewrite template="{$frontend[url]}/api/v1/websso?originalUrl=
> {scheme}://{host}:{port}/{gateway}/{knoxsso}/"/>
>
> Best,
> Sandeep
>
>
>
> On Fri, Jul 27, 2018 at 1:03 PM Christopher Jackson <
> jackson.christopher.lee@gmail.com> wrote:
>
>> Hi All,
>>
>> Curious if it is possible to rewrite a query parameter value to append a
>> string to the original value? I tried the below configuration but I don’t
>> think its valid as requests to the resource were just hanging.
>>
>> Entry from service.xml for the particular path:
>>
>> <rewrite apply=“MYSERVICE/myapp/outbound/redirect/headers"
>> to="response.headers"/>
>>
>>
>> Entries in rewrite.xml:
>>
>> <rule dir="OUT" name="MYSERVICE/myapp/outbound/redirect/headers/location">
>>     <match pattern=“*://*:*/myapp?originalUrl={originalurl}&{**}"/>
>>     <rewrite
>> template="{$frontend[url]}/myservice/myapp?originalUrl={originalurl}&{**}"/>
>> </rule>
>>
>> <filter name="MYSERVICE/myapp/outbound/redirect/headers">
>>     <content type="application/x-http-headers">
>>         <apply path="Location"
>> rule="MYSERVICE/myapp/outbound/redirect/headers/location"/>
>>     </content>
>> </filter>
>>
>> An additional concern I have with the above attempted approach is I don’t
>> think that I can guarantee the order of the query parameters.
>>
>>
>>
>> An example of what I would like to see happen is the header content of a
>> 302 response with a Location header value of:
>>
>>
>> https://host.example.com:9443/myapp?originalUrl=/some/path/&mode=EI&wrongRole=true
>>
>> to be rewritten to:
>>
>>
>> https://host.example.com:8443/gateway/default/myservice/myapp?originalUrl=/gateway/default/myservice/myapp/some/path/&mode=EI&wrongRole=true
>>
>> In summary the result would have the frontend[url] replace the internal
>> destination and the originalUrl query parameter would have the
>> frontend[path] appended to its original value.
>>
>> Anyone have any ideas on how to achieve this?
>>
>> Regards,
>> Christopher Jackson
>
>
>

Re: Possible to rewrite query parameter value?

Posted by Christopher Jackson <ja...@gmail.com>.
Hi Sandeep,

Unfortunately that function is only available in 1.10 or 0.13 or later which I don’t have access to. Do the $postfix, $prefix, and $infix also work with frontend ‘path’ instead of ‘url’?

Regards,
Christopher Jackson


> On Jul 27, 2018, at 2:16 PM, Sandeep Moré <mo...@gmail.com> wrote:
> 
> It should be possible using parameterized rewrite variables, this is an example from Spark History rewrite rules 
> 
> <!-- re-write rule for location when SHS redirects to Knox SSO login page -->
> <rule dir="OUT" name="SPARKHISTORYUI/sparkhistory/outbound/headers/location/sso">
>   <match pattern="{scheme}://{host}:{port}/{gateway}/{knoxsso}/{api}/{v}/websso?originalUrl={**}"/>
>   <rewrite template="{scheme}://{host}:{port}/{gateway}/{knoxsso}/{api}/{v}/websso?originalUrl={$postfix[url,/sparkhistory/]}"/>
> </rule>
> <filter name="SPARKHISTORYUI/sparkhistory/outbound/headers/sso/filter">
>   <content type="application/x-http-headers">
>     <apply path="Location" rule="SPARKHISTORYUI/sparkhistory/outbound/headers/location/sso"/>
>   </content>
> </filter>
> 
> or in the above example
> 
> <rewrite template="{$frontend[url]}/api/v1/websso?originalUrl={scheme}://{host}:{port}/{gateway}/{knoxsso}/"/>
> 
> Best,
> Sandeep
> 
> 
> 
> On Fri, Jul 27, 2018 at 1:03 PM Christopher Jackson <jackson.christopher.lee@gmail.com <ma...@gmail.com>> wrote:
> Hi All,
> 
> Curious if it is possible to rewrite a query parameter value to append a string to the original value? I tried the below configuration but I don’t think its valid as requests to the resource were just hanging.
> 
> Entry from service.xml for the particular path:
> 
> <rewrite apply=“MYSERVICE/myapp/outbound/redirect/headers" to="response.headers"/>
> 
> 
> Entries in rewrite.xml:
> 
> <rule dir="OUT" name="MYSERVICE/myapp/outbound/redirect/headers/location">
>     <match pattern=“*://*:*/myapp?originalUrl={originalurl}&{**}"/>
>     <rewrite template="{$frontend[url]}/myservice/myapp?originalUrl={originalurl}&{**}"/>
> </rule>
> 
> <filter name="MYSERVICE/myapp/outbound/redirect/headers">
>     <content type="application/x-http-headers">
>         <apply path="Location" rule="MYSERVICE/myapp/outbound/redirect/headers/location"/>
>     </content>
> </filter>
> 
> An additional concern I have with the above attempted approach is I don’t think that I can guarantee the order of the query parameters.
> 
> 
> 
> An example of what I would like to see happen is the header content of a 302 response with a Location header value of:
> 
> https://host.example.com:9443/myapp?originalUrl=/some/path/&mode=EI&wrongRole=true <https://host.example.com:9443/myapp?originalUrl=/some/path/&mode=EI&wrongRole=true>
> 
> to be rewritten to:
> 
> https://host.example.com:8443/gateway/default/myservice/myapp?originalUrl=/gateway/default/myservice/myapp/some/path/&mode=EI&wrongRole=true <https://host.example.com:8443/gateway/default/myservice/myapp?originalUrl=/gateway/default/myservice/myapp/some/path/&mode=EI&wrongRole=true>
> 
> In summary the result would have the frontend[url] replace the internal destination and the originalUrl query parameter would have the frontend[path] appended to its original value.
> 
> Anyone have any ideas on how to achieve this?
> 
> Regards,
> Christopher Jackson


Re: Possible to rewrite query parameter value?

Posted by Sandeep Moré <mo...@gmail.com>.
It should be possible using parameterized rewrite variables, this is an
example from Spark History rewrite rules

<!-- re-write rule for location when SHS redirects to Knox SSO login page
-->
<rule dir="OUT"
name="SPARKHISTORYUI/sparkhistory/outbound/headers/location/sso">
  <match
pattern="{scheme}://{host}:{port}/{gateway}/{knoxsso}/{api}/{v}/websso?originalUrl={**}"/>
  <rewrite
template="{scheme}://{host}:{port}/{gateway}/{knoxsso}/{api}/{v}/websso?originalUrl={$postfix[url,/sparkhistory/]}"/>
</rule>
<filter name="SPARKHISTORYUI/sparkhistory/outbound/headers/sso/filter">
  <content type="application/x-http-headers">
    <apply path="Location"
rule="SPARKHISTORYUI/sparkhistory/outbound/headers/location/sso"/>
  </content>
</filter>

or in the above example

<rewrite template="{$frontend[url]}/api/v1/websso?originalUrl=
{scheme}://{host}:{port}/{gateway}/{knoxsso}/"/>

Best,
Sandeep



On Fri, Jul 27, 2018 at 1:03 PM Christopher Jackson <
jackson.christopher.lee@gmail.com> wrote:

> Hi All,
>
> Curious if it is possible to rewrite a query parameter value to append a
> string to the original value? I tried the below configuration but I don’t
> think its valid as requests to the resource were just hanging.
>
> Entry from service.xml for the particular path:
>
> <rewrite apply=“MYSERVICE/myapp/outbound/redirect/headers"
> to="response.headers"/>
>
>
> Entries in rewrite.xml:
>
> <rule dir="OUT" name="MYSERVICE/myapp/outbound/redirect/headers/location">
>     <match pattern=“*://*:*/myapp?originalUrl={originalurl}&{**}"/>
>     <rewrite
> template="{$frontend[url]}/myservice/myapp?originalUrl={originalurl}&{**}"/>
> </rule>
>
> <filter name="MYSERVICE/myapp/outbound/redirect/headers">
>     <content type="application/x-http-headers">
>         <apply path="Location"
> rule="MYSERVICE/myapp/outbound/redirect/headers/location"/>
>     </content>
> </filter>
>
> An additional concern I have with the above attempted approach is I don’t
> think that I can guarantee the order of the query parameters.
>
>
>
> An example of what I would like to see happen is the header content of a
> 302 response with a Location header value of:
>
>
> https://host.example.com:9443/myapp?originalUrl=/some/path/&mode=EI&wrongRole=true
>
> to be rewritten to:
>
>
> https://host.example.com:8443/gateway/default/myservice/myapp?originalUrl=/gateway/default/myservice/myapp/some/path/&mode=EI&wrongRole=true
>
> In summary the result would have the frontend[url] replace the internal
> destination and the originalUrl query parameter would have the
> frontend[path] appended to its original value.
>
> Anyone have any ideas on how to achieve this?
>
> Regards,
> Christopher Jackson