You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Gerzabek <mi...@gmx.net> on 2008/08/11 12:38:43 UTC
[T5][FAQ] How to configure a service that likely will be overriden
by an AliasContribution?
Usecase:
tapestry-spring-security offers integration between Tapestry 5 an Spring
Security [1]. It's implemented as a Tapestry IoC/Core module.
This module uses a PasswordEncoder shipped by Spring Security (they ship
also a couple of standard implementations of PasswordEncoder).
For the module to function correctly an implementation class of
PasswordEncoder (the service in charge) is needed. Now, there are two
ways to configure the module:
1.) gracefully: The module declares a standard service for
PasswordEncoder and assumes the main module will define an
AliasContribution to override with whatever specific instance is needed.
2.) tough: The module doesn't declare a standard service for
PasswordEncoder. It rather assumes that the user of the module will do
so. If the user of the module doesn't provide an implementation a
RuntimeException is thrown and the container won't start up.
Obviously there are arguments for both directions. In
tapestry-spring-security we wanted to follow line 1.) This leads us to
the FAQ.
[FAQ] How to configure a service that likely will be overriden by an
AliasContribution?
i. Supplier: The only thing the supplier of a module has to do is to
bind the interface (PasswordEncoder) to the default class
(PlaintextPasswordEncoder) - or provide a build method if he needs to
set it up.
public static void bind(final ServiceBinder binder) {
binder.bind( PasswordEncoder.class,
PlaintextPasswordEncoder.class ).withMarker(
SpringSecurityServices.class);
}
ii. User: Now if you want to use a supplied module and you want to
override a service defined there the only thing you have to do is to
contribute to the Alias service.
public static void contributeAlias(
Configuration<AliasContribution<PasswordEncoder>> configuration ) {
configuration.add( AliasContribution.create(
PasswordEncoder.class,
new ShaPasswordEncoder() ) );
}
--
Crowd,
Is this correct? Do I miss something?
Regards,
Michael
[1] http://www.localhost.nu/java/tapestry5-acegi/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5][FAQ] How to configure a service that likely will be overriden
by an AliasContribution?
Posted by Michael Gerzabek <mi...@gmx.net>.
Hi,
Oh, I see, you're right. In case you want to contribute a bunch of
services to AliasService you have to ommit the type you're about to
contribute because otherwise the compiler won't eat the code.
Thanks.
Filip S. Adamsen schrieb:
> Hi,
>
> I wouldn't use Configuration<AliasContribution<PasswordEncoder>>, but
> rather Configuration<AliasContribution>. Otherwise you won't be able
> to configure multiple alias overrides at once.
>
> Apart from that, everything looks fine.
>
> -Filip
>
> Michael Gerzabek skrev:
>> Usecase:
>> tapestry-spring-security offers integration between Tapestry 5 an
>> Spring Security [1]. It's implemented as a Tapestry IoC/Core module.
>>
>> This module uses a PasswordEncoder shipped by Spring Security (they
>> ship also a couple of standard implementations of PasswordEncoder).
>>
>> For the module to function correctly an implementation class of
>> PasswordEncoder (the service in charge) is needed. Now, there are two
>> ways to configure the module:
>>
>> 1.) gracefully: The module declares a standard service for
>> PasswordEncoder and assumes the main module will define an
>> AliasContribution to override with whatever specific instance is needed.
>>
>> 2.) tough: The module doesn't declare a standard service for
>> PasswordEncoder. It rather assumes that the user of the module will
>> do so. If the user of the module doesn't provide an implementation a
>> RuntimeException is thrown and the container won't start up.
>>
>> Obviously there are arguments for both directions. In
>> tapestry-spring-security we wanted to follow line 1.) This leads us
>> to the FAQ.
>>
>> [FAQ] How to configure a service that likely will be overriden by an
>> AliasContribution?
>>
>> i. Supplier: The only thing the supplier of a module has to do is to
>> bind the interface (PasswordEncoder) to the default class
>> (PlaintextPasswordEncoder) - or provide a build method if he needs to
>> set it up.
>>
>> public static void bind(final ServiceBinder binder) {
>>
>> binder.bind( PasswordEncoder.class,
>> PlaintextPasswordEncoder.class ).withMarker(
>> SpringSecurityServices.class);
>> }
>>
>> ii. User: Now if you want to use a supplied module and you want to
>> override a service defined there the only thing you have to do is to
>> contribute to the Alias service.
>>
>> public static void contributeAlias(
>> Configuration<AliasContribution<PasswordEncoder>> configuration ) {
>>
>> configuration.add( AliasContribution.create(
>> PasswordEncoder.class,
>> new ShaPasswordEncoder() ) );
>> }
>>
>> --
>> Crowd,
>>
>> Is this correct? Do I miss something?
>>
>> Regards,
>> Michael
>>
>> [1] http://www.localhost.nu/java/tapestry5-acegi/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5][FAQ] How to configure a service that likely will be overriden
by an AliasContribution?
Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
When you put @Local on a service injection Tapestry looks for a service
match in the local (current) module only. That means you can override,
say, RequestExceptionHandler without having to qualify your injection.
Without @Local:
public static void bind(ServiceBinder binder) {
binder.bind(MyRequestExceptionHandler.class).withId("MyRequestExceptionHandler");
}
public static void
contributeAliasOverride(Configuration<AliasContribution> configuration,
@InjectService("MyRequestExceptionHandler")
RequestExceptionHandler
myRequestExceptionHandler) {
configuration.add(AliasContribution.create(RequestExceptionHandler.class,
myRequestExceptionHandler));
}
With @Local:
public static void bind(ServiceBinder binder) {
binder.bind(MyRequestExceptionHandler.class).withId("MyRequestExceptionHandler");
}
public static void
contributeAliasOverride(Configuration<AliasContribution> configuration,
@Local
RequestExceptionHandler myRequestExceptionHandler) {
configuration.add(AliasContribution.create(RequestExceptionHandler.class,
myRequestExceptionHandler));
}
So it saves you some typing, provided there's only one matching service
in the module.
-Filip
Michael Gerzabek skrev:
> Now I don't understand exactly what that means.
>
> In my case I have two modules. Module one ships with an interface and a
> default implementation that is preconfigured. As a user of module one,
> in my module two, I contributeAlias(..) to override the preconfigured
> default implementation. The application as whole will now use the
> service configured and 'implemented' in module two.
>
> What would be the usecase of @Local? When I have only one module and
> want to override via an AliasContribution ..? Why would I d that?
>
>
> Howard Lewis Ship schrieb:
>> Looks good to me too.
>>
>> I'm working on adding @Local which will make it easier to contribute
>> Alias contributions that are services from within the same module.
>> But often you can get by, as you did, with just an instance.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5][FAQ] How to configure a service that likely will be overriden
by an AliasContribution?
Posted by Michael Gerzabek <mi...@gmx.net>.
Now I don't understand exactly what that means.
In my case I have two modules. Module one ships with an interface and a
default implementation that is preconfigured. As a user of module one,
in my module two, I contributeAlias(..) to override the preconfigured
default implementation. The application as whole will now use the
service configured and 'implemented' in module two.
What would be the usecase of @Local? When I have only one module and
want to override via an AliasContribution ..? Why would I d that?
Howard Lewis Ship schrieb:
> Looks good to me too.
>
> I'm working on adding @Local which will make it easier to contribute
> Alias contributions that are services from within the same module.
> But often you can get by, as you did, with just an instance.
>
> On Mon, Aug 11, 2008 at 4:06 AM, Filip S. Adamsen <fs...@fsadev.com> wrote:
>
>> Hi,
>>
>> I wouldn't use Configuration<AliasContribution<PasswordEncoder>>, but rather
>> Configuration<AliasContribution>. Otherwise you won't be able to configure
>> multiple alias overrides at once.
>>
>> Apart from that, everything looks fine.
>>
>> -Filip
>>
>> Michael Gerzabek skrev:
>>
>>> Usecase:
>>> tapestry-spring-security offers integration between Tapestry 5 an Spring
>>> Security [1]. It's implemented as a Tapestry IoC/Core module.
>>>
>>> This module uses a PasswordEncoder shipped by Spring Security (they ship
>>> also a couple of standard implementations of PasswordEncoder).
>>>
>>> For the module to function correctly an implementation class of
>>> PasswordEncoder (the service in charge) is needed. Now, there are two ways
>>> to configure the module:
>>>
>>> 1.) gracefully: The module declares a standard service for PasswordEncoder
>>> and assumes the main module will define an AliasContribution to override
>>> with whatever specific instance is needed.
>>>
>>> 2.) tough: The module doesn't declare a standard service for
>>> PasswordEncoder. It rather assumes that the user of the module will do so.
>>> If the user of the module doesn't provide an implementation a
>>> RuntimeException is thrown and the container won't start up.
>>>
>>> Obviously there are arguments for both directions. In
>>> tapestry-spring-security we wanted to follow line 1.) This leads us to the
>>> FAQ.
>>>
>>> [FAQ] How to configure a service that likely will be overriden by an
>>> AliasContribution?
>>>
>>> i. Supplier: The only thing the supplier of a module has to do is to bind
>>> the interface (PasswordEncoder) to the default class
>>> (PlaintextPasswordEncoder) - or provide a build method if he needs to set it
>>> up.
>>>
>>> public static void bind(final ServiceBinder binder) {
>>>
>>> binder.bind( PasswordEncoder.class,
>>> PlaintextPasswordEncoder.class ).withMarker(
>>> SpringSecurityServices.class);
>>> }
>>>
>>> ii. User: Now if you want to use a supplied module and you want to
>>> override a service defined there the only thing you have to do is to
>>> contribute to the Alias service.
>>>
>>> public static void contributeAlias(
>>> Configuration<AliasContribution<PasswordEncoder>> configuration ) {
>>>
>>> configuration.add( AliasContribution.create(
>>> PasswordEncoder.class,
>>> new ShaPasswordEncoder() ) );
>>> }
>>>
>>> --
>>> Crowd,
>>>
>>> Is this correct? Do I miss something?
>>>
>>> Regards,
>>> Michael
>>>
>>> [1] http://www.localhost.nu/java/tapestry5-acegi/
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5][FAQ] How to configure a service that likely will be overriden by an AliasContribution?
Posted by Howard Lewis Ship <hl...@gmail.com>.
Looks good to me too.
I'm working on adding @Local which will make it easier to contribute
Alias contributions that are services from within the same module.
But often you can get by, as you did, with just an instance.
On Mon, Aug 11, 2008 at 4:06 AM, Filip S. Adamsen <fs...@fsadev.com> wrote:
> Hi,
>
> I wouldn't use Configuration<AliasContribution<PasswordEncoder>>, but rather
> Configuration<AliasContribution>. Otherwise you won't be able to configure
> multiple alias overrides at once.
>
> Apart from that, everything looks fine.
>
> -Filip
>
> Michael Gerzabek skrev:
>>
>> Usecase:
>> tapestry-spring-security offers integration between Tapestry 5 an Spring
>> Security [1]. It's implemented as a Tapestry IoC/Core module.
>>
>> This module uses a PasswordEncoder shipped by Spring Security (they ship
>> also a couple of standard implementations of PasswordEncoder).
>>
>> For the module to function correctly an implementation class of
>> PasswordEncoder (the service in charge) is needed. Now, there are two ways
>> to configure the module:
>>
>> 1.) gracefully: The module declares a standard service for PasswordEncoder
>> and assumes the main module will define an AliasContribution to override
>> with whatever specific instance is needed.
>>
>> 2.) tough: The module doesn't declare a standard service for
>> PasswordEncoder. It rather assumes that the user of the module will do so.
>> If the user of the module doesn't provide an implementation a
>> RuntimeException is thrown and the container won't start up.
>>
>> Obviously there are arguments for both directions. In
>> tapestry-spring-security we wanted to follow line 1.) This leads us to the
>> FAQ.
>>
>> [FAQ] How to configure a service that likely will be overriden by an
>> AliasContribution?
>>
>> i. Supplier: The only thing the supplier of a module has to do is to bind
>> the interface (PasswordEncoder) to the default class
>> (PlaintextPasswordEncoder) - or provide a build method if he needs to set it
>> up.
>>
>> public static void bind(final ServiceBinder binder) {
>>
>> binder.bind( PasswordEncoder.class,
>> PlaintextPasswordEncoder.class ).withMarker(
>> SpringSecurityServices.class);
>> }
>>
>> ii. User: Now if you want to use a supplied module and you want to
>> override a service defined there the only thing you have to do is to
>> contribute to the Alias service.
>>
>> public static void contributeAlias(
>> Configuration<AliasContribution<PasswordEncoder>> configuration ) {
>>
>> configuration.add( AliasContribution.create(
>> PasswordEncoder.class,
>> new ShaPasswordEncoder() ) );
>> }
>>
>> --
>> Crowd,
>>
>> Is this correct? Do I miss something?
>>
>> Regards,
>> Michael
>>
>> [1] http://www.localhost.nu/java/tapestry5-acegi/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [T5][FAQ] How to configure a service that likely will be overriden
by an AliasContribution?
Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi,
I wouldn't use Configuration<AliasContribution<PasswordEncoder>>, but
rather Configuration<AliasContribution>. Otherwise you won't be able to
configure multiple alias overrides at once.
Apart from that, everything looks fine.
-Filip
Michael Gerzabek skrev:
> Usecase:
> tapestry-spring-security offers integration between Tapestry 5 an Spring
> Security [1]. It's implemented as a Tapestry IoC/Core module.
>
> This module uses a PasswordEncoder shipped by Spring Security (they ship
> also a couple of standard implementations of PasswordEncoder).
>
> For the module to function correctly an implementation class of
> PasswordEncoder (the service in charge) is needed. Now, there are two
> ways to configure the module:
>
> 1.) gracefully: The module declares a standard service for
> PasswordEncoder and assumes the main module will define an
> AliasContribution to override with whatever specific instance is needed.
>
> 2.) tough: The module doesn't declare a standard service for
> PasswordEncoder. It rather assumes that the user of the module will do
> so. If the user of the module doesn't provide an implementation a
> RuntimeException is thrown and the container won't start up.
>
> Obviously there are arguments for both directions. In
> tapestry-spring-security we wanted to follow line 1.) This leads us to
> the FAQ.
>
> [FAQ] How to configure a service that likely will be overriden by an
> AliasContribution?
>
> i. Supplier: The only thing the supplier of a module has to do is to
> bind the interface (PasswordEncoder) to the default class
> (PlaintextPasswordEncoder) - or provide a build method if he needs to
> set it up.
>
> public static void bind(final ServiceBinder binder) {
>
> binder.bind( PasswordEncoder.class,
> PlaintextPasswordEncoder.class ).withMarker(
> SpringSecurityServices.class);
> }
>
> ii. User: Now if you want to use a supplied module and you want to
> override a service defined there the only thing you have to do is to
> contribute to the Alias service.
>
> public static void contributeAlias(
> Configuration<AliasContribution<PasswordEncoder>> configuration ) {
>
> configuration.add( AliasContribution.create(
> PasswordEncoder.class,
> new ShaPasswordEncoder() ) );
> }
>
> --
> Crowd,
>
> Is this correct? Do I miss something?
>
> Regards,
> Michael
>
> [1] http://www.localhost.nu/java/tapestry5-acegi/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org