You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by CXFbanda <ch...@nortel.com> on 2009/02/18 12:38:01 UTC

Extracting HTTP authorization header

Hi,

I need to extract HTTP authorization header.
I am able to do it using @Context HttpHeader injection by CXF and then
extracting Authorization info from that.
However, i need to do that for all the resource mappings.
Is there any way I can avoid replicating code in each method?
Is there any way by which I can specify a particular method to be executed,
irrespective of the request?
(where I can have this extraction code, and then store the extracted header
in some instance variable.)

Thanks
-- 
View this message in context: http://www.nabble.com/Extracting-HTTP-authorization-header-tp22076857p22076857.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Extracting HTTP authorization header

Posted by CXFbanda <ch...@nortel.com>.
Hi Gabo,

All I mean is - how can the whole process be done at the class level.
As in, instead of having a method parameter, how can I get it in an instance
variable (and may be perform some operation on it)?

PS: CXF does support injection of HttpHeaders and SecurityContext but none
of these can help in achieving my goal, which is "injection of
Authorization" (manually, in this case)

Thanks


Gabo Manuel wrote:
> 
> Hi,
> 
> I am not sure what you mean by all resource mappings but the following 
> should work:
> 
> @HeaderParam("Authorization") on a method parameter of a service 
> implementation will extract the authorization header.
> 
> Hth.
> 
> Gabo
> 
> CXFbanda wrote:
>> Hi,
>>
>> I need to extract HTTP authorization header.
>> I am able to do it using @Context HttpHeader injection by CXF and then
>> extracting Authorization info from that.
>> However, i need to do that for all the resource mappings.
>> Is there any way I can avoid replicating code in each method?
>> Is there any way by which I can specify a particular method to be
>> executed,
>> irrespective of the request?
>> (where I can have this extraction code, and then store the extracted
>> header
>> in some instance variable.)
>>
>> Thanks
>>   
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com 
>> Version: 8.0.237 / Virus Database: 270.10.25/1957 - Release Date:
>> 02/17/09 07:07:00
>>
>>   
> 
> 

-- 
View this message in context: http://www.nabble.com/Extracting-HTTP-authorization-header-tp22076857p22077094.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Extracting HTTP authorization header

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi,

That was rather hard to understand... lemme rephrase that:

What do you mean by "i need to do that for all the resource mappings."?

Also, see sample below:

    @GET
    @Path("/somepath")
    public void someMethod(
            @HeaderParam("Authorization")
            String authorization) {

I hope that is better.

Gabo

Gabo Manuel wrote:
> Hi,
>
> I am not sure what you mean by all resource mappings but the following 
> should work:
>
> @HeaderParam("Authorization") on a method parameter of a service 
> implementation will extract the authorization header.
>
> Hth.
>
> Gabo
>
> CXFbanda wrote:
>> Hi,
>>
>> I need to extract HTTP authorization header.
>> I am able to do it using @Context HttpHeader injection by CXF and then
>> extracting Authorization info from that.
>> However, i need to do that for all the resource mappings.
>> Is there any way I can avoid replicating code in each method?
>> Is there any way by which I can specify a particular method to be 
>> executed,
>> irrespective of the request?
>> (where I can have this extraction code, and then store the extracted 
>> header
>> in some instance variable.)
>>
>> Thanks
>>   
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com Version: 8.0.237 / Virus Database: 
>> 270.10.25/1957 - Release Date: 02/17/09 07:07:00
>>
>>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.0.237 / Virus Database: 270.10.25/1957 - Release Date: 02/17/09 07:07:00
>
>   

Re: Extracting HTTP authorization header

Posted by Gabo Manuel <km...@solegysystems.com>.
Hi,

I am not sure what you mean by all resource mappings but the following 
should work:

@HeaderParam("Authorization") on a method parameter of a service 
implementation will extract the authorization header.

Hth.

Gabo

CXFbanda wrote:
> Hi,
>
> I need to extract HTTP authorization header.
> I am able to do it using @Context HttpHeader injection by CXF and then
> extracting Authorization info from that.
> However, i need to do that for all the resource mappings.
> Is there any way I can avoid replicating code in each method?
> Is there any way by which I can specify a particular method to be executed,
> irrespective of the request?
> (where I can have this extraction code, and then store the extracted header
> in some instance variable.)
>
> Thanks
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.0.237 / Virus Database: 270.10.25/1957 - Release Date: 02/17/09 07:07:00
>
>   

Re: Extracting HTTP authorization header

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi,

>
> Sorry for the cluttered message.
> Here I go again.
>
> Thanks for your replies.
> Having a custom @Context type is too much of a work for just to avoid
> extracting the auth data manually. (and I'm not sure how to do that either
> :-) )

I think I know how we can do it, some vague idea came to me during my lunch break...but I'll try to get to it later on and see how 
realistic it is...

> _______________________
> [thinking wild]
> Life can become so much easier if the framework can allow "@HeaderParam
> along with @Context" for instance variables.... :-)
> _______________________

Yea, that's what you can do too. Unfortunately @HeaderParam are not thread safe, when injected into a field, but again let us think 
a bit more what can we do in this regard...You might want to try injecting it as a beanProperty

@HeaderParam
public void setAuthorization(String value) {
     AuthorizationData ad = fromString(value);
     threadLocalAuthorization.put(ad);
}

it might work actually...

Cheers, Sergey

> Coming back to the topic, please let me know if there is a possibility of
> adding pre/post methods. (as Sergey mentioned) That will surely help my
> purpose.
> -- 
> View this message in context: http://www.nabble.com/Extracting-HTTP-authorization-header-tp22076857p22078097.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


Re: Extracting HTTP authorization header

Posted by CXFbanda <ch...@nortel.com>.
Sorry for the cluttered message.
Here I go again.

Thanks for your replies.
Having a custom @Context type is too much of a work for just to avoid
extracting the auth data manually. (and I'm not sure how to do that either
:-) )
_______________________
[thinking wild]
Life can become so much easier if the framework can allow "@HeaderParam
along with @Context" for instance variables.... :-)
_______________________
Coming back to the topic, please let me know if there is a possibility of
adding pre/post methods. (as Sergey mentioned) That will surely help my
purpose. 
-- 
View this message in context: http://www.nabble.com/Extracting-HTTP-authorization-header-tp22076857p22078097.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Extracting HTTP authorization header

Posted by CXFbanda <ch...@nortel.com>.
Thanks for your replies.

Having a custom @Context type is too much of a work for just to avoid
extracting the auth data manually. (and I'm not sure how to do that either
:-) )

_______________________
[thinking wild]
Life can become so much easier if the framework can allow "@HeaderParam
along with @Context" for instance variables.... :-)
_______________________

Coming back to the topic, please let me know if there is a possibility of
adding pre/post methods. (as Sergey mentioned)
That will surely help my purpose. 


-- 
View this message in context: http://www.nabble.com/Extracting-HTTP-authorization-header-tp22076857p22078006.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Extracting HTTP authorization header

Posted by Sergey Beryozkin <sb...@progress.com>.
Actually, if you do depend on say Tomcat role definition then you probably can do
@Context SecurityContext sc;

sc.isUserInRole(...)

Cheers, Sergey

> Hi,
>
> I think having a custom @Context types supported will be one way to do it :
> @Context AuthorizationData data;
>
> I know Jersey does it but I need to think how something like this can be done in as a trivial way as possible...
> I'm not sure how else this can be done - I need to think. In principle it would be possible to add pre/post methods configuration 
> in jaxrs:server - but I'm not certain yet... If you have any ideas then let me know please.
>
> Would you be open to moving the Authorization check out of the resource class code to a RequestFilter ? You can get an access to 
> the OperationResourceInfo about to be invoked in a filter and check the authorization details too. We also have system tests and a 
> demo (in Fuse though) showing how Spring Security can be applied - but it might not work in 2.1.3 due to a double proxy bug - 
> though I believe some users have managed to escape it in 2.1.3 :-)
>
> Cheers, Sergey
>
>>
>> Hi,
>>
>> I need to extract HTTP authorization header.
>> I am able to do it using @Context HttpHeader injection by CXF and then
>> extracting Authorization info from that.
>> However, i need to do that for all the resource mappings.
>> Is there any way I can avoid replicating code in each method?
>> Is there any way by which I can specify a particular method to be executed,
>> irrespective of the request?
>> (where I can have this extraction code, and then store the extracted header
>> in some instance variable.)
>>
>> Thanks
>> -- 
>> View this message in context: http://www.nabble.com/Extracting-HTTP-authorization-header-tp22076857p22076857.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
> 


Re: Extracting HTTP authorization header

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi,

I think having a custom @Context types supported will be one way to do it :
@Context AuthorizationData data;

I know Jersey does it but I need to think how something like this can be done in as a trivial way as possible...
I'm not sure how else this can be done - I need to think. In principle it would be possible to add pre/post methods configuration in 
jaxrs:server - but I'm not certain yet... If you have any ideas then let me know please.

Would you be open to moving the Authorization check out of the resource class code to a RequestFilter ? You can get an access to the 
OperationResourceInfo about to be invoked in a filter and check the authorization details too. We also have system tests and a demo 
(in Fuse though) showing how Spring Security can be applied - but it might not work in 2.1.3 due to a double proxy bug - though I 
believe some users have managed to escape it in 2.1.3 :-)

Cheers, Sergey

>
> Hi,
>
> I need to extract HTTP authorization header.
> I am able to do it using @Context HttpHeader injection by CXF and then
> extracting Authorization info from that.
> However, i need to do that for all the resource mappings.
> Is there any way I can avoid replicating code in each method?
> Is there any way by which I can specify a particular method to be executed,
> irrespective of the request?
> (where I can have this extraction code, and then store the extracted header
> in some instance variable.)
>
> Thanks
> -- 
> View this message in context: http://www.nabble.com/Extracting-HTTP-authorization-header-tp22076857p22076857.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>