Maven setup

The latest stable release 2.0.6


Setup your Web App

In the /WEB-INF/ file, set the that point to your Guice App Module

# The Application Guice Modules (1 or more, comma seperated)

# TODO: need to change the "com.example.starter.MyAppModule" to the application package 
#       and application module class name. 

# NOTE: Any property in this file can be injected via Google using 
#        @Named(propertyName)String propertyValue
# So, if we have here: 
# myApp.prop1=value1
# Then, in any Guice managed class, we can have
# @Inject
# private @Named(myApp.prop1) String value

In the /WEB-INF/web.xml, make all pages point to web.xml

<web-app id="WebApp_ID" version="2.4" 

Guice Module class

Snow applications are configured via one or more Google Guice modules. At initialization time, Snow gets the list of application Guice modules from the snow.webApplicationModules property from the WEB-INF/ file.

Create your src/main/java/com/example/ as something like:

package com.example;

public class MyAppConfig extends AbstractModule {
    protected void configure() {
        // some bindings

Note: The first Google Guice module defined in the snow.webApplicationModules property (here the only AppConfig ) specifies the base package from where Snow scans classes for Snow method annotations (e.g., @WebGet, @WebModelHandler, ...) to do the appropriate "Web bindings." So, make sure that the first Guice module is at the root package of your application.

Authentication & Login

Implementing login and authentication in Snow is dead simple. The only things needed are to bind a AuthRequest implementation, which will attempt to authenticate any incoming request, and implement the @WebPost for the for the login and logoff REST api (in this application, we use "/api/user-login" for login, and "/api/user-logoff") to perform the login and logoff.

So, the request authentication and login/logoff request flow will look like:

The AuthRequest.authRequest returns null until the user does a POST at the "/api/user-login" with the appropriate credential.

To implement AuthRequest we just need to "Google Guice" bind AuthRequest.class interface to an application implementation, such as:

package com.example.samplebookmarks;

public class AppConfig extends AbstractModule {
  protected void configure() {

This AuthRequest interface just have one method, AuthRequest.authRequest which takes a RequestContext object (a Snow convenient wrapper of HttpServletRequest and HttpServletResponse), and need to return a AuthToken with a given user when the user has been logged-in, or just return null (meaning, no user authenticated for this request).


public class AppAuthRequest implements AuthRequest<User> {

  public AuthToken<User> authRequest(RequestContext rc) {
      // Note for this sample app, we store the user in the session, 
      // but for production application, use stateless authentication mechanism for 
      // better sclability.
      // RequestContext is a convenient Snow wrapper on top of HttpServletRequest, 
      //  and HttpServletResponse
      // rc.getReq() return the HttpServletRequest 
      User user = (User) rc.getReq().getSession().getAttribute("user");
      if (user != null){
          AuthToken authToken = new AuthToken();
          return authToken;
          return null;


Note: Below the generic type User belong to the application, and not to Snow. This allows developer to have any User model they think is the most appropriate to their application. See AuthRequest documentation for more information.

Doing a login API is as simple as annotating the login and logoff with @WebPost as:

public class LoginWebHandlers {

    private UserDao userDao;
     * Note: Here the RequestContext will be injected by Snow 
    public WebResponse login(@WebParam("userName")String userName, 
                             @WebParam("pwd")String pwd, 
                             RequestContext rc){
        User user = userDao.getUserByUserName(userName);
        if (user != null && pwd != null && pwd.equals(user.getPassword())){
            rc.getReq().getSession().setAttribute("user", user);
            return WebResponse.success();
            return"Wrong username or password.");


     * Note: Here we show how we can inject HttpServletRequest directly
     * @param req
    public void logoff(HttpServletRequest req){