users@jersey.java.net

[Jersey] Re: Injecting Principal best practices

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Tue, 8 Mar 2011 15:39:46 -0500

I am finally getting back to fix this and I realized something. My module is:

    public class HubServletModule extends JerseyServletModule { ... }


what this means is that when I try to
bind(SecurityContext.class).to(HubSecurityContext.class) I get an
exception saying HubSecurityContext is already bound. That's beacuse,
in JerseyServletModule, there exists this:


    @RequestScoped
    @Provides
    public SecurityContext securityContext(WebApplication wa) {
        return wa.getThreadLocalHttpContext().getRequest();
    }

Extending JerseyServletModule is pretty useful. I'm wondering if I
should just override that provider method (will that work?) in my
subclass of JerseyServletModule so I don't have to copy all of JSM's
usefulness?

-C





On Wed, Feb 23, 2011 at 11:02 AM, Pavel Bucek <pavel.bucek_at_oracle.com> wrote:
> see http://blogs.sun.com/sandoz/entry/301_moved_permanently
>
> Marek Potociar is the very same Marek who is mentioned as JAX-RS co-spec
> lead.
>
>
>
> On 02/23/2011 04:48 PM, Christopher Piggott wrote:
>>
>> I'm not sure who Marek Potociar is, but said person just checked in a
>> sample of using jersey-guice to directly inject what I need.  Thank
>> you!
>>
>>
>>
>> On Fri, Feb 18, 2011 at 6:10 AM, Jakub Podlesak
>> <jakub.podlesak_at_oracle.com>  wrote:
>>
>>>
>>> Hi Christopher,
>>>
>>> i am not a Guice expert, but just in case.
>>>
>>> There is a Jersey example [1] showing integration with Guice.
>>> You can then combine Jersey/Guice injection,
>>> so that not everything gets injected by Jersey.
>>>
>>> Would that help?
>>>
>>> ~Jakub
>>>
>>>
>>> [1]http://download.java.net/maven/2/com/sun/jersey/samples/guicefilter-webapp/1.6-ea03/guicefilter-webapp-1.6-ea03-project.zip
>>>
>>> On 02/16/2011 02:29 PM, Christopher Piggott wrote:
>>>
>>>>
>>>> Absolutely.  Hopefully what I wrote makes sense.
>>>>
>>>> The thing about this I'm not entirely sure of is where I should have
>>>> solved the problem some other way; for example, in some context
>>>> listener somewhere, find the context and inject the SpecificPrincipal
>>>> there.
>>>>
>>>> I am probably being thick but I really wish there were no @Context at
>>>> all and I could just handle everything via guice.  In the guice way, I
>>>> think that each request would get its own childInjector.  @Context
>>>> would, I think, be unnecessary.  (I could be wrong, I'm not super
>>>> knowledgable about @Context other than getting the few things I need
>>>> from it).
>>>>
>>>>
>>>>
>>>> On Tue, Feb 15, 2011 at 9:01 AM, Marek Potociar
>>>> <marek.potociar_at_oracle.com>    wrote:
>>>>
>>>>>
>>>>> can you please file an enhancement request here:
>>>>> http://java.net/jira/browse/jersey
>>>>>
>>>
>>>
>>
>>
>
>