In general, It's as easy as to create a HttpSession in the
RemoteServiceServlet.

I've created an abstract BaseService that only accepts RPC calls when
the child Service NOT "isSecured()" OR when (the child Service
"isSecured()" AND there's a HttpSession previously stablished).


abstract public class BaseService extends RemoteServiceServlet
{
        private static final Logger logger = Logger.getLogger
( BaseService.class);

        public abstract boolean isSecured( );

        @Override
        public String processCall( String payload) throws
SerializationException
        {
             HttpSession session = getThreadLocalRequest().getSession
(false);
             DatosThread.setSession( session);

             if( isSecured( )) {
                     if( (session == null) || (session.getAttribute
( "user") == null))
                     {
                         // User not authenticated!
                         logger.error( "User not authenticated!");
                         try {
                             getThreadLocalResponse().sendError( 401);
                         } catch (IOException e) {
                         logger.error("ERROR sending HTTP 401", e);
                    }
                    return "";
                }
        }
        String result = super.processCall( payload);
        return result;
     }
}


public class SecurityImpl
extends BaseService
implements Security
{
        private static final Logger logger = Logger.getLogger
( SecurityImpl.class);

        public User authenticateUser( String username, String password)
        {
               logger.debug( "INIT logging " + username);

               User user = findUser( username);
                if( (user != null) && user.getPassword( ).equals( password))
{
                        HttpSession session = getThreadLocalRequest( 
).getSession( true);
                        session.setAttribute("user", user);
                        logger.debug( "User logged");
                        return new User( user.getLogin( ), "", user.getProfile( 
));
                }
                logger.debug( "Logging rejected");
                return null;
        }

        @Override
        public boolean isSecured( )
        {
                return false;
        }
}


public class ModelImpl
extends BaseService
implements Model
{
       private static final Logger logger = Logger.getLogger
( ModelImpl.class);

       ...... rpc methods ...

        @Override
        public boolean isSecured( )
        {
                return true;
        }
}



On Mar 22, 11:13 pm, stsch <stsc...@schliwinski.de> wrote:
> Hi,
>
> I have just started with GWT. What are the approaches to develop a
> stateful GWT application? Could any of the experts please summarize
> this a bit for a beginner and maybe point me/us to some reference
> material?
>
> Thanks,
> -StSch-
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to