Package org.atomojo.www.apps.login

Source Code of org.atomojo.www.apps.login.LoginApplication

/*
* LoginApplication.java
*
* Created on September 7, 2007, 10:05 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package org.atomojo.www.apps.login;

import org.atomojo.www.util.ClassResourceFinder;
import org.atomojo.www.util.IdentityManager;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import org.restlet.routing.Template;

/**
*
* This application uses the following constructs:
*   * a link called 'auth-service' that points to the authentication service,
*   * the identity manager attribute in the context to maintain sessions,
*   * a parameter 'login.type' that can be "google.ClientLogin" or empty,
*   * a parameter 'login.name' an optional name to be sent to the authentication service,
*   * a parameter 'login.cookie.name' used to save authentication.  If set, a cookie will be sent to the client,
*   * a parameter 'login.cookie.path' for the path to set the cookie for authentication,
*   * a parameter 'login.view' that contains a boolean to control enabling login form.  Defaults to true.
* @author alex
*/
public class LoginApplication extends Application
{
  
   public static final String LINKS_ATTR = "org.atomojo.www.app.links";
  
   /**
    * Creates a new instance of LoginApplication
    */
   public LoginApplication(Context context)
   {
      super(context);
      getTunnelService().setEnabled(false);
     
      Object links = context.getAttributes().get(LINKS_ATTR);
      if (links==null) {
         getLogger().warning("The "+LINKS_ATTR+" attribute is missing for "+this.getClass().getName());
      } else {
         getContext().getAttributes().put(LINKS_ATTR,links);
      }
      Object idManager = context.getAttributes().get(IdentityManager.ATTR);
      if (idManager==null) {
         getLogger().warning("There is no "+IdentityManager.ATTR+" attribute.");
      } else {
         getContext().getAttributes().put(IdentityManager.ATTR,idManager);
      }
   }
  
   public Restlet createRoot() {
      String viewValue = getContext().getParameters().getFirstValue("login.view");
      boolean viewEnabled = viewValue==null || "true".equals(viewValue.trim());
     
      Router router = new Router(getContext());
      if (viewEnabled) {
         getLogger().info("Enabling view on login.");
         router.attach("/",LoginView.class);
         router.attach("/js/",new ClassResourceFinder(getContext(),LoginApplication.class,"js")).getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
         router.attach("/logout",LogoutView.class);
     
      router.attach("/auth",LoginAction.class);
      router.attach("/status/check",CheckAction.class);
      router.attach("/status",StatusAction.class);
      router.attach("/expire",LogoutAction.class);
      return router;
   }
  
}
TOP

Related Classes of org.atomojo.www.apps.login.LoginApplication

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.