You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Fabricio Pizzichillo <fp...@gmail.com> on 2011/08/05 00:15:39 UTC

Guice + Shiro + GWT

hello friends.
I am a beginner with shiro. I'm trying to integrate with an
application developed
with GWT + Guice + Postgresql. Can be oriented on how to configure the
servlet Guice as authenticating users database?
Thank you very much and greetings

Re: Guice + Shiro + GWT

Posted by Fabricio Pizzichillo <fp...@gmail.com>.
Thanks, I'll see.

2011/8/15 ryannelsonaz <mw...@hotmail.com>

> We're using the gwt-dispatch module (link below) to implement a
> command-pattern style RPC communication structure between the client and
> the
> server.  Essentially each "command" taken by the client is encapsulated in
> an Action class, which gets assigned to a corresponding ActionHandler.
>
> We have a Login action that gets sent to a LoginHandler where the current
> user is authenticated.  We then use annotations on the execute() method of
> the remaining handlers to do authorization.  For example, here's a little
> pseudo-code sample for a hypothetical "get list of bank accounts" request:
>
> public class LoginHandler {
>    public LoginResult execute( Login action ) {
>        Subject currentUser = SecurityUtils.getSubject();
>        currentUser.login( new UsernamePasswordToken( action.getUsername(),
> action.getPassword() ) );
>
>        return new LoginResult( ... );
>    }
> }
>
> public class GetBankAccountsHandler {
>
>    @RequiresPermissions("bankaccounts:read")
>    public GetBackAccountsResult execute( GetBackAccounts action ) {
>                ...
>    }
> }
>
> We have a LogoutHandler as well which simply invokes Shiro's logout()
> method.  Hope that helps you with some ideas.
>
> I don't know if I'd recommend having an RPC call on each presenter--you'll
> have to decide based on your architecture whether or not that would be too
> chatty.  However, if you really want to enforce authorization in the
> client,
> that's really your only option.  (Until someone decides to port Shiro for
> GWT!)
>
> gwt-dispatch home: http://code.google.com/p/gwt-dispatch/
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Guice-Shiro-GWT-tp6654452p6688447.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: Guice + Shiro + GWT

Posted by ryannelsonaz <mw...@hotmail.com>.
We're using the gwt-dispatch module (link below) to implement a
command-pattern style RPC communication structure between the client and the
server.  Essentially each "command" taken by the client is encapsulated in
an Action class, which gets assigned to a corresponding ActionHandler.

We have a Login action that gets sent to a LoginHandler where the current
user is authenticated.  We then use annotations on the execute() method of
the remaining handlers to do authorization.  For example, here's a little
pseudo-code sample for a hypothetical "get list of bank accounts" request:

public class LoginHandler {
    public LoginResult execute( Login action ) {
        Subject currentUser = SecurityUtils.getSubject();
        currentUser.login( new UsernamePasswordToken( action.getUsername(),
action.getPassword() ) );

        return new LoginResult( ... );
    }
}

public class GetBankAccountsHandler {

    @RequiresPermissions("bankaccounts:read")
    public GetBackAccountsResult execute( GetBackAccounts action ) {
		...
    }
}

We have a LogoutHandler as well which simply invokes Shiro's logout()
method.  Hope that helps you with some ideas.

I don't know if I'd recommend having an RPC call on each presenter--you'll
have to decide based on your architecture whether or not that would be too
chatty.  However, if you really want to enforce authorization in the client,
that's really your only option.  (Until someone decides to port Shiro for
GWT!)

gwt-dispatch home: http://code.google.com/p/gwt-dispatch/

--
View this message in context: http://shiro-user.582556.n2.nabble.com/Guice-Shiro-GWT-tp6654452p6688447.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Guice + Shiro + GWT

Posted by Fabricio Pizzichillo <fp...@gmail.com>.
Hi Rian.
Can you help me to setup in server-side?
Was trying to do, but fails to work. I think that every presenter should I
run an RPC method that validates if the user is authenticated.
Thanks!

Fabricio
2011/8/12 ryannelsonaz <mw...@hotmail.com>

> Fabricio,
>
> FYI, I'm experimenting with Guice in a GWT application, and I may be able
> to
> answer some of your questions.  However, we're only using it server-side.
> GWT requires that any Java code must be translatable to Javascript, and
> Shiro isn't.  (Though, someone could undertake that effort.)
>
> Guice is also not translatable to Javascript, which is why the Gin project
> exists (basically, a subset of Guice for GWT).
>
> Ryan
>
>
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Guice-Shiro-GWT-tp6654452p6681823.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Re: Guice + Shiro + GWT

Posted by ryannelsonaz <mw...@hotmail.com>.
Fabricio,

FYI, I'm experimenting with Guice in a GWT application, and I may be able to
answer some of your questions.  However, we're only using it server-side. 
GWT requires that any Java code must be translatable to Javascript, and
Shiro isn't.  (Though, someone could undertake that effort.)

Guice is also not translatable to Javascript, which is why the Gin project
exists (basically, a subset of Guice for GWT).

Ryan



--
View this message in context: http://shiro-user.582556.n2.nabble.com/Guice-Shiro-GWT-tp6654452p6681823.html
Sent from the Shiro User mailing list archive at Nabble.com.

Re: Guice + Shiro + GWT

Posted by Kalle Korhonen <ka...@gmail.com>.
On Fri, Aug 5, 2011 at 7:25 AM, Jared Bunting
<ja...@peachjean.com> wrote:
> On 08/05/2011 09:05 AM, Fabricio Pizzichillo wrote:
> Where I can get the jar to integrate with Guice?
> Right now you'll need to build it locally, or get it from Apache's snapshot
> maven repository (https://repository.apache.org/).
> Please note though that this is works with the rest of 1.2.0-SNAPSHOT, and
> won't work with 1.1.0.

Specifically, the snapshot repository is at:
https://repository.apache.org/content/groups/snapshots/ (and the guice
libs at https://repository.apache.org/content/groups/snapshots/org/apache/shiro/shiro-guice/1.2.0-SNAPSHOT/
- bu like Jared said, need shiro-core at 1.2.0 as well).

Kalle


> 2011/8/5 Jared Bunting <ja...@peachjean.com>
>>
>> Yeah, that's a bit of an issue (well, it shouldn't affect the
>> application functionally, but I'd prefer not to use deprecated APIs).
>>
>> I've create SHIRO-318 (https://issues.apache.org/jira/browse/SHIRO-318)
>> to address this.
>>
>> Thanks for pointing this out.
>>
>> -Jared
>>
>> On 08/05/2011 06:32 AM, Filipe Sousa wrote:
>> > Aug 5, 2011 12:28:49 PM
>> >
>> > com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider
>> > get
>> > WARNING: You are attempting to use a deprecated API (specifically,
>> > attempting to @Inject ServletContext inside an eagerly created
>> > singleton. While we allow this for backwards compatibility, be warned
>> > that this MAY have unexpected behavior if you have more than one
>> > injector (with ServletModule) running in the same JVM. Please consult
>> > the Guice documentation at
>> > http://code.google.com/p/google-guice/wiki/Servlets for more
>> > information.
>>
>
>
>

Re: Guice + Shiro + GWT

Posted by Fabricio Pizzichillo <fp...@gmail.com>.
Thanks

2011/8/5 Jared Bunting <ja...@peachjean.com>

> **
>
> On 08/05/2011 09:05 AM, Fabricio Pizzichillo wrote:
>
> Where I can get the jar to integrate with Guice?
>
>
> Right now you'll need to build it locally, or get it from Apache's snapshot
> maven repository (https://repository.apache.org/).
>
> Please note though that this is works with the rest of 1.2.0-SNAPSHOT, and
> won't work with 1.1.0.
>
>
>  2011/8/5 Jared Bunting <ja...@peachjean.com>
>
>> Yeah, that's a bit of an issue (well, it shouldn't affect the
>> application functionally, but I'd prefer not to use deprecated APIs).
>>
>> I've create SHIRO-318 (https://issues.apache.org/jira/browse/SHIRO-318)
>> to address this.
>>
>> Thanks for pointing this out.
>>
>> -Jared
>>
>> On 08/05/2011 06:32 AM, Filipe Sousa wrote:
>> > Aug 5, 2011 12:28:49 PM
>> >
>> com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider
>> > get
>> > WARNING: You are attempting to use a deprecated API (specifically,
>> > attempting to @Inject ServletContext inside an eagerly created
>> > singleton. While we allow this for backwards compatibility, be warned
>> > that this MAY have unexpected behavior if you have more than one
>> > injector (with ServletModule) running in the same JVM. Please consult
>> > the Guice documentation at
>> > http://code.google.com/p/google-guice/wiki/Servlets for more
>> > information.
>>
>>
>
>

Re: Guice + Shiro + GWT

Posted by Jared Bunting <ja...@peachjean.com>.
On 08/05/2011 09:05 AM, Fabricio Pizzichillo wrote:
> Where I can get the jar to integrate with Guice?
>

Right now you'll need to build it locally, or get it from Apache's
snapshot maven repository (https://repository.apache.org/).

Please note though that this is works with the rest of 1.2.0-SNAPSHOT,
and won't work with 1.1.0.

> 2011/8/5 Jared Bunting <jared.bunting@peachjean.com
> <ma...@peachjean.com>>
>
>     Yeah, that's a bit of an issue (well, it shouldn't affect the
>     application functionally, but I'd prefer not to use deprecated APIs).
>
>     I've create SHIRO-318
>     (https://issues.apache.org/jira/browse/SHIRO-318)
>     to address this.
>
>     Thanks for pointing this out.
>
>     -Jared
>
>     On 08/05/2011 06:32 AM, Filipe Sousa wrote:
>     > Aug 5, 2011 12:28:49 PM
>     >
>     com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider
>     > get
>     > WARNING: You are attempting to use a deprecated API (specifically,
>     > attempting to @Inject ServletContext inside an eagerly created
>     > singleton. While we allow this for backwards compatibility, be
>     warned
>     > that this MAY have unexpected behavior if you have more than one
>     > injector (with ServletModule) running in the same JVM. Please
>     consult
>     > the Guice documentation at
>     > http://code.google.com/p/google-guice/wiki/Servlets for more
>     > information.
>
>


Re: Guice + Shiro + GWT

Posted by Fabricio Pizzichillo <fp...@gmail.com>.
Where I can get the jar to integrate with Guice?

2011/8/5 Jared Bunting <ja...@peachjean.com>

> Yeah, that's a bit of an issue (well, it shouldn't affect the
> application functionally, but I'd prefer not to use deprecated APIs).
>
> I've create SHIRO-318 (https://issues.apache.org/jira/browse/SHIRO-318)
> to address this.
>
> Thanks for pointing this out.
>
> -Jared
>
> On 08/05/2011 06:32 AM, Filipe Sousa wrote:
> > Aug 5, 2011 12:28:49 PM
> >
> com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider
> > get
> > WARNING: You are attempting to use a deprecated API (specifically,
> > attempting to @Inject ServletContext inside an eagerly created
> > singleton. While we allow this for backwards compatibility, be warned
> > that this MAY have unexpected behavior if you have more than one
> > injector (with ServletModule) running in the same JVM. Please consult
> > the Guice documentation at
> > http://code.google.com/p/google-guice/wiki/Servlets for more
> > information.
>
>

Re: Guice + Shiro + GWT

Posted by Jared Bunting <ja...@peachjean.com>.
Yeah, that's a bit of an issue (well, it shouldn't affect the
application functionally, but I'd prefer not to use deprecated APIs).

I've create SHIRO-318 (https://issues.apache.org/jira/browse/SHIRO-318)
to address this.

Thanks for pointing this out.

-Jared

On 08/05/2011 06:32 AM, Filipe Sousa wrote:
> Aug 5, 2011 12:28:49 PM
> com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider
> get
> WARNING: You are attempting to use a deprecated API (specifically,
> attempting to @Inject ServletContext inside an eagerly created
> singleton. While we allow this for backwards compatibility, be warned
> that this MAY have unexpected behavior if you have more than one
> injector (with ServletModule) running in the same JVM. Please consult
> the Guice documentation at
> http://code.google.com/p/google-guice/wiki/Servlets for more
> information.


Re: Guice + Shiro + GWT

Posted by Filipe Sousa <na...@gmail.com>.
Hi.

I didn't know there was a guice module being developed for shiro

I'm trying the examples on the documentation but I'm getting a warning

Aug 5, 2011 12:28:49 PM
com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider
get
WARNING: You are attempting to use a deprecated API (specifically,
attempting to @Inject ServletContext inside an eagerly created
singleton. While we allow this for backwards compatibility, be warned
that this MAY have unexpected behavior if you have more than one
injector (with ServletModule) running in the same JVM. Please consult
the Guice documentation at
http://code.google.com/p/google-guice/wiki/Servlets for more
information.

public class GuiceListener extends GuiceServletContextListener {
	private ServletContext servletContext;

	@Override
	protected Injector getInjector() {
		return Guice.createInjector(DEVELOPMENT, new
MyShiroWebModule(servletContext), new MyApplicationModule());
	}

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		servletContext = servletContextEvent.getServletContext();
		super.contextInitialized(servletContextEvent);
	}
}

public class MyShiroWebModule extends ShiroWebModule {
	public MyShiroWebModule(ServletContext servletContext) {
		super(servletContext);
	}

	@Override
	protected void configureShiroWeb() {
		bindRealm().to(IpbRealm.class);
		addFilterChain("/**", AUTHC_BASIC);
	}
}

public class MyApplicationModule extends ServletModule {
	@Override
	protected void configureServlets() {
		bind(Context.class).to(InitialContext.class);
		bind(DataSource.class).toProvider(fromJndi(DataSource.class, "jdbc/rad"));
	}
}


On Thu, Aug 4, 2011 at 11:38 PM, Jared Bunting
<ja...@peachjean.com> wrote:
> I don't know much about GWT, but I can help you with basic Guice
> integration.
>
> The current release of Shiro (1.1.0) doesn't have Guice support, but the
> trunk codebase does (1.2.0-SNAPSHOT).  To get started, have a look at the
> documentation here: http://shiro.apache.org/guice.html.
>
> Once you've done that, I'd be happy to answer any more specific questions
> that you may have.
>
> -Jared
>
> On 08/04/2011 05:15 PM, Fabricio Pizzichillo wrote:
>
> hello friends.
> I am a beginner with shiro. I'm trying to integrate with an
> application developed with GWT + Guice + Postgresql. Can be oriented on how
> to configure the servlet Guice as authenticating users database?
> Thank you very much and greetings
>



-- 
Filipe Sousa

Re: Guice + Shiro + GWT

Posted by Fabricio Pizzichillo <fp...@gmail.com>.
Thanks Jared for the quick response.
I read the documentation and then you wonder.
regards

2011/8/4 Jared Bunting <ja...@peachjean.com>

> **
> I don't know much about GWT, but I can help you with basic Guice
> integration.
>
> The current release of Shiro (1.1.0) doesn't have Guice support, but the
> trunk codebase does (1.2.0-SNAPSHOT).  To get started, have a look at the
> documentation here: http://shiro.apache.org/guice.html.
>
> Once you've done that, I'd be happy to answer any more specific questions
> that you may have.
>
> -Jared
>
>
> On 08/04/2011 05:15 PM, Fabricio Pizzichillo wrote:
>
> hello friends.
> I am a beginner with shiro. I'm trying to integrate with an application developed
> with GWT + Guice + Postgresql. Can be oriented on how to configure the
> servlet Guice as authenticating users database?
> Thank you very much and greetings
>
>
>

Re: Guice + Shiro + GWT

Posted by Jared Bunting <ja...@peachjean.com>.
I don't know much about GWT, but I can help you with basic Guice
integration.

The current release of Shiro (1.1.0) doesn't have Guice support, but the
trunk codebase does (1.2.0-SNAPSHOT).  To get started, have a look at
the documentation here: http://shiro.apache.org/guice.html.

Once you've done that, I'd be happy to answer any more specific
questions that you may have.

-Jared

On 08/04/2011 05:15 PM, Fabricio Pizzichillo wrote:
> hello friends.
> I am a beginner with shiro. I'm trying to integrate with an
> application developed with GWT + Guice + Postgresql. Can be
> oriented on how to configure the
> servlet Guice as authenticating users database?
> Thank you very much and greetings