Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Advice on abstracting authentication information into a superclass
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ravi M  
View profile  
 More options Jan 17 2010, 1:36 pm
From: Ravi M <mund...@gmail.com>
Date: Sun, 17 Jan 2010 10:36:12 -0800 (PST)
Local: Sun, Jan 17 2010 1:36 pm
Subject: Advice on abstracting authentication information into a superclass
I'm starting to play around with gwt-dispatcher and have the following
question. I have several actions GetFoo, GetBar etc. defined in my
application. Every time I want to perform an action on the server, I
also want to make sure that the browser session requesting the action
is authentic, valid etc. and for this in addition to whatever data is
needed for the action, I pass a token (say AuthToken) to the server
(which I've previously created by doing a login op on the server).

I can do

public class GetFoo implements Action<GetFooResult> {
  private String id;
  private AuthToken authToken;

  public GetFoo( String id , AuthToken authToken) {
    this.id = id;
    this.authToken = authToken;
  }
... etc.

Since I have to do this in every Action, I'd rather put this sort of
thing in an abstract superclass for all Actions, for easier
maintainability etc. I'd appreciate some pointers on how best to do
this? Is there some way I can define the parent class so that when
instantiating the child, I'm _forced_ to make sure that the AuthToken
is set etc.

Thanks and regards
Ravi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Syntax  
View profile  
 More options Jan 18 2010, 10:04 pm
From: Syntax <j.dixon...@gmail.com>
Date: Mon, 18 Jan 2010 19:04:59 -0800 (PST)
Local: Mon, Jan 18 2010 10:04 pm
Subject: Re: Advice on abstracting authentication information into a superclass
As far as I'm concerned your spot on.

1) Make your class abstract
2) Ensure you provide the constructor which takes both id and auth
token; all derived classes will be required to provide the same
constructor.
3) Annotate the id and authToken members with @NonNull (from Findbugs)

I use the above solution and it works perfectly. I called my
superclass SecureAction<Result>...

On Jan 18, 2:36 am, Ravi M <mund...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Peterson  
View profile  
 More options Jan 18 2010, 10:42 pm
From: David Peterson <da...@randombits.org>
Date: Tue, 19 Jan 2010 13:42:58 +1000
Local: Mon, Jan 18 2010 10:42 pm
Subject: Re: [gwt-dispatch] Advice on abstracting authentication information into a superclass

Hi Ravi,

Sorry for the delay. The approach I've taken in the API is to have different implementations of the DispatchService. There is the StandardDispatchService, which has no security built in, or the SecureDispatchService, which is passed both an ID (provided by you) and the Action being performed. The SecureDispatchServiceServlet on the other end will then check that ID before executing the Action as per normal.

So, in code, you need to do the following:

Client:
1. SecureDispatchAsync: Implementation of DispatchAsync, which you actually use in your code.
2. SecureDispatchService/SecureDispatchServiceAsync: The actual RPC interface, used by SecureDispatchAsync
3. SecureSessionAccessor: This interface is used by SecureDispatchService to retrieve the 'security token' for the application. You need to provide an implementation to retrieve the appropriate token for your app. The 'CookieSecureSessionAccessor' might be a useful class - it grabs the ID from a specific cookie value. If you're using GAE, the 'AppEngineSecureSessionAccessor' would work.

Server:
1. A servlet implementing SecureDispatchServiceAsync. The 'AbstractSecureDispatchServlet', GuiceSecureDispatchServlet, or SpringSecureDispatchServlet may be useful here, depending on your context.
2. SecureSessionValidator: An implementation of this interface must be provided if you're using 'AbstractSevureDispatchServlet' or subclasses. It will do the actual test to check if the ID is valid.

If you're using GIN/Guice, there are a couple of support modules to make life a little simpler. You will need something like this:

Client:
1. MySecureDispatchModule:

public class MySecureDispatchModule extends SecureDispatchModule {
        public MySecureDispatchModule() {
                super( MyExceptionHandler.class );
        }

        @Override
        protected void configure() {
                super();
                bind( SecureSessionAccessor.class ).to( MySecureSessionAccessor.class );
        }

}

2. Install 'MySecureDispatchModule' in your GInjector.

Server:

1. MySecureModule

public class MySecureValidatorModule extends AbstractModule {
        @Override
        protected void configure() {
                bind( SecureSessionValidator.class ).to( MySecureSessionValidator.class );
        }

}

2. Install 'MySecureValidatorModule' and 'ServerDispatchModule'.

Easy, right? Ok, not so much....sorry about that.

David

On 18/01/2010, at 4:36 AM, Ravi M wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Syntax  
View profile  
 More options Jan 19 2010, 3:37 am
From: Syntax <j.dixon...@gmail.com>
Date: Tue, 19 Jan 2010 00:37:03 -0800 (PST)
Local: Tues, Jan 19 2010 3:37 am
Subject: Re: Advice on abstracting authentication information into a superclass
I much prefer your dispatch service solution to the one I have in
place, It reduces obfuscation on the Action classes and removes the
need for each handler to validate the security model itself before
executing! :)

I am currently only using published artifacts for dispatch and
presenter.

After reading your post I have reviewed the trunk and can see your
secure dispatch service work, very nice! Any idea on when the next
release of Dispatch will be made?

On Jan 19, 11:42 am, David Peterson <da...@randombits.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ravi M  
View profile  
 More options Jan 19 2010, 12:12 pm
From: Ravi M <mund...@gmail.com>
Date: Tue, 19 Jan 2010 09:12:25 -0800 (PST)
Local: Tues, Jan 19 2010 12:12 pm
Subject: Re: Advice on abstracting authentication information into a superclass
Thanks for your replies David and Syntax. Truth be told, I'm still
wading my way around Guice and GIN, so will need a little time to
absorb and make sense of it all. Initially I wasn't even planning to
use Guice on the server, I was going to use the framework provided by
gwt-dispatch to model Actions, Results, and ActionHandlers and write
my own servlet to handle the RPCs on the server, more in the interest
of getting something working out of the door sooner rather than later,
but it looks like I do need to take a full-fledged leap into the
dependency injection world. I hope it isn't rocket science, gulp :-)

The other problem I'm facing is that I haven't really used generics in
any non-trivial way (other than in parameterizing Collections and
Maps), so am trying to wrap my mind around the whole how-to-abstractly-
implement-interfaces-which-take-type-parameters and then extend-the-
abstract-class sort of stuff. Am stuck at the moment, but am sure I
can figure things out with a little bit of time, which unfortunately I
don't have too much of!

Anyway, I'll post back on this thread if I'm really marooned, maybe
with code snippets that you guys can make sense of.

Thanks again,
Ravi

On Jan 19, 1:37 pm, Syntax <j.dixon...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ravi M  
View profile  
 More options Jan 19 2010, 11:55 pm
From: Ravi M <mund...@gmail.com>
Date: Tue, 19 Jan 2010 20:55:28 -0800 (PST)
Local: Tues, Jan 19 2010 11:55 pm
Subject: Re: Advice on abstracting authentication information into a superclass
One further question: Does using gwt-dispatch and/or Guice impact
one's ability to debug server side code in an IDE? Any implications
there?

Thanks
Ravi

On Jan 19, 10:12 pm, Ravi M <mund...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Peterson  
View profile  
 More options Jan 20 2010, 12:29 am
From: David Peterson <da...@randombits.org>
Date: Wed, 20 Jan 2010 15:29:33 +1000
Local: Wed, Jan 20 2010 12:29 am
Subject: Re: [gwt-dispatch] Re: Advice on abstracting authentication information into a superclass
No, debugging works great. You might want to link your IDE to the gwt-dispatch source code though.

David

On 20/01/2010, at 2:55 PM, Ravi M wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kyle Baley  
View profile  
 More options Feb 12 2010, 2:46 pm
From: Kyle Baley <kyle.ba...@gmail.com>
Date: Fri, 12 Feb 2010 11:46:22 -0800 (PST)
Local: Fri, Feb 12 2010 2:46 pm
Subject: Re: Advice on abstracting authentication information into a superclass
I was able to work my way through these steps and get authentication
checking working, I think. I didn't actually create my own
SecureDispatchAsync or SecureDispatchService classes. Just assumed
those would be used by default if I registered my
SecureDispatchModule. Anyway, if I'm following correctly, any action
you execute should throw an InvalidSessionException if the user isn't
logged in, yesno?

Assuming that's correct, what is the next step if you want to use this
to get users to log in? Should I use the ExceptionHandler to check for
InvalidSessionException and redirect to the login page from there? Or
create my own SecureDispatchAsync class that redirects?

Another question: what is a good way to secure only some actions? The
obvious one is the login, which I don't want to secure. I saw mention
on TurboManage that a @Secure annotation might be a good idea.

Also, let me know if I'm not using correct terminology. I'm a
seasoned .NET developer cutting his teeth on Java in general.

On Jan 18, 10:42 pm, David Peterson <da...@randombits.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Peterson  
View profile  
 More options Feb 14 2010, 9:02 pm
From: David Peterson <da...@randombits.org>
Date: Mon, 15 Feb 2010 12:02:53 +1000
Local: Sun, Feb 14 2010 9:02 pm
Subject: Re: [gwt-dispatch] Re: Advice on abstracting authentication information into a superclass
The SecureDispatchXXX classes don't actually require that a user is authenticated, and they don't do any authentication themselves. All they do is ensure that the user's token is sent to the server in a secure way. It's up to you to provide classes on both ends that a) provide the token (client side) and b) confirm the token is valid (server side). That token can equally be 'null', which would be for anonymous users. As such, I use the SecureDispatch for all actions, and simply assume that 'null' tokens are for anonymous users. There is then an extra check to determine if an Action is actually executable by an anonymous user.

Hope that helps.

David

On 13/02/2010, at 5:46 AM, Kyle Baley wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kyle Baley  
View profile  
 More options Feb 15 2010, 6:14 pm
From: Kyle Baley <kyle.ba...@gmail.com>
Date: Mon, 15 Feb 2010 15:14:31 -0800 (PST)
Local: Mon, Feb 15 2010 6:14 pm
Subject: Re: Advice on abstracting authentication information into a superclass
Okay, that makes sense. Where does the check for anonymous actions
occur? I thought my implementation of SecureSessionValidator would be
the logical place but I can't see how to determine which action is
being executed.

On Feb 14, 9:02 pm, David Peterson <da...@randombits.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kyle Baley  
View profile  
 More options Feb 15 2010, 10:39 pm
From: Kyle Baley <kyle.ba...@gmail.com>
Date: Mon, 15 Feb 2010 19:39:05 -0800 (PST)
Local: Mon, Feb 15 2010 10:39 pm
Subject: Re: Advice on abstracting authentication information into a superclass
I came up with something that works but it doesn't feel right. I
created my own SecureDispatchService implementation inheriting from
AbstractSecureDispatchServlet. It's essentially a duplicate of
GuiceSecureDispatchServlet but with the execute method overridden like
so:

    @Override
    public Result execute(String sessionId, Action<?> action) throws
ActionException,
            ServiceException {

        if ( anonymousActions.contains(action) ) {
            return getDispatch( ).execute( action );
        }

        return super.execute(sessionId, action);
    }

Where anonymousActions is a registry of actions that don't require
authentication.

This feels very much like I'm working around the framework instead of
with it though.

On Feb 15, 6:14 pm, Kyle Baley <kyle.ba...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »