[Join-cvs] join/src/main/org/figure8/join/control JoinAction.java,NONE,1.1 JoinServlet.java,NONE,1.1
Brought to you by:
lbroudoux
|
From: <lbr...@us...> - 2003-07-30 09:13:23
|
Update of /cvsroot/join/join/src/main/org/figure8/join/control
In directory sc8-pr-cvs1:/tmp/cvs-serv32197
Added Files:
JoinAction.java JoinServlet.java UserContainer.java
Log Message:
Initial checkin
--- NEW FILE: JoinAction.java ---
/*
* JoinAction.java
*
* Created on 10 september 2002, 17:08
*/
package org.figure8.join.control;
import org.apache.struts.action.Action;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
/**
* An abstract Action class that all Join action classes must extend.
* @author <a href="mailto:lau...@fr...">Laurent Broudoux</a>
*/
public abstract class JoinAction extends Action{
// Static -------------------------------------------------------------------
public static final String GUI_KEY = "gui";
// Public -------------------------------------------------------------------
/**
* Check if user tied to the HttpServletRequest is logged
* in Join application (ie : has a non empty UserContainer).
*/
public static boolean isLoggedIn(HttpServletRequest request){
UserContainer container = getUserContainer(request);
return (container != null && container.getView() != null);
}
/**
* Retrieve the user container for the user tied to the HttpServletRequest.
* Creates an empty container if one doesn't exist already.
*/
public static UserContainer getUserContainer(HttpServletRequest request){
HttpSession session = request.getSession();
UserContainer container = (UserContainer)session.getAttribute("user.container");
// Create a UserContainer if one doesn't exist already.
if (container == null){
container = new UserContainer();
session.setAttribute("user.container", container);
}
return container;
}
}
--- NEW FILE: JoinServlet.java ---
/*
* JoinServlet.java
*
* Created on 11 september 2002, 15:09
*/
package org.figure8.join.control;
import org.figure8.join.view.ConfigurationView;
import org.figure8.join.service.UserCache;
import org.figure8.join.service.UserManagerHome;
import org.figure8.join.service.UserManagerFactory;
import org.figure8.join.businessfacades.interfaces.*;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.naming.InitialContext;
/**
* Controller servlet of Join application. This servlet is an extension
* of the Struts ActionServlet.
* @author <a href="mailto:lau...@fr...">Laurent Broudoux</a>
*/
public class JoinServlet extends org.apache.struts.action.ActionServlet{
// Override of ActionServlet ------------------------------------------------
/**
* Override of Struts ActionServlet init() method. Call super.init()
* and then retrieve and store into servlet context objects sharedd by
* the whole application.
*/
public void init() throws ServletException{
// Make sure to always call the super's init() first.
super.init();
// Retrieve objects that are shared across application.
try{
// Get context parameters.
String cacheFqn = (String)getServletContext().getInitParameter("user.cache.fqn");
String builPatt = (String)getServletContext().getInitParameter("build.name.pattern");
String versPatt = (String)getServletContext().getInitParameter("version.name.pattern");
String reposPath = (String)getServletContext().getInitParameter("deliverable.repository.path");
String docReposUrl = (String)getServletContext().getInitParameter("deliverable.docrepository.url");
String docReposPath = (String)getServletContext().getInitParameter("deliverable.docrepository.path");
String authorizationFailureUrl = (String)getServletContext().getInitParameter("authorization.failure.url");
getServletContext().setAttribute("build.pattern", builPatt);
getServletContext().setAttribute("version.pattern", versPatt);
getServletContext().setAttribute("deliverable.repos.path", reposPath);
getServletContext().setAttribute("deliverable.docrepos.url", docReposUrl);
getServletContext().setAttribute("deliverable.docrepos.path", docReposPath);
getServletContext().setAttribute("authorization.fails.url", authorizationFailureUrl);
// Get EJB references.
InitialContext ctx = new InitialContext();
UserManagerHome userHome = UserManagerFactory.createUserManagerHome("java:comp/env/ejb/UserManagerLocal");
ISystemManagerLocalHome isHome = (ISystemManagerLocalHome)ctx.lookup("java:comp/env/ejb/ISystemManagerLocal");
JoinCycleManagerLocalHome cycleHome = (JoinCycleManagerLocalHome)ctx.lookup("java:comp/env/ejb/JoinCycleManagerLocal");
ResourceManagerLocalHome resourceHome = (ResourceManagerLocalHome)ctx.lookup("java:comp/env/ejb/ResourceManagerLocal");
ComponentManagerLocalHome componentHome = (ComponentManagerLocalHome)ctx.lookup("java:comp/env/ejb/ComponentManagerLocal");
ReportingManagerLocalHome reportingHome = (ReportingManagerLocalHome)ctx.lookup("java:comp/env/ejb/ReportingManagerLocal");
EnvironmentManagerLocalHome environmentHome = (EnvironmentManagerLocalHome)ctx.lookup("java:comp/env/ejb/EnvironmentManagerLocal");
ConfigurationManagerLocalHome configurationHome = (ConfigurationManagerLocalHome)ctx.lookup("java:comp/env/ejb/ConfigurationManagerLocal");
getServletContext().setAttribute("user.manager.home", userHome);
getServletContext().setAttribute("is.manager.home", isHome);
getServletContext().setAttribute("cycle.manager.home", cycleHome);
getServletContext().setAttribute("resource.manager.home", resourceHome);
getServletContext().setAttribute("component.manager.home", componentHome);
getServletContext().setAttribute("reporting.manager.home", reportingHome);
getServletContext().setAttribute("environment.manager.home", environmentHome);
getServletContext().setAttribute("configuration.manager.home", configurationHome);
// Build the users cache.
Class cacheClazz = Thread.currentThread().getContextClassLoader().loadClass(cacheFqn);
UserCache cache = (UserCache)cacheClazz.newInstance();
cache.initialize(userHome);
getServletContext().setAttribute("user.cache", cache);
// Get Active Configuration.
ConfigurationManagerLocal manager = configurationHome.create();
ConfigurationView config = manager.getActiveConfiguration();
getServletContext().setAttribute("config", config);
manager.remove();
// Build Mapping Handler.
MappingHandler handler = new MappingHandler();
getServletContext().setAttribute("mapping.handler", handler);
}
catch (Exception e){
e.printStackTrace();
throw new UnavailableException("One or more services are unavailable");
}
}
}
--- NEW FILE: UserContainer.java ---
/*
* UserContainer.java
*
* Created on 10 september 2002, 17:08
*/
package org.figure8.join.control;
import org.figure8.join.view.UserView;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import java.util.Iterator;
import java.util.Collection;
/**
* Used to store information about a specific user. This class is used so that
* the information is not scattered throughout the HttpSession. Only this object
* is stored in the session for the user. This class implements the HttpSession
* BindingListener so that it can be notified of session timeoutand perform cleanup.
* @author <a href="mailto:lau...@fr...">Laurent Broudoux</a>
*/
public class UserContainer implements java.io.Serializable, HttpSessionBindingListener{
// Attributes ---------------------------------------------------------------
private UserView view = null;
// Constructors -------------------------------------------------------------
/** Creates a new instance of UserContainer */
public UserContainer(){
super();
}
// Public -------------------------------------------------------------------
/** Get the user view */
public UserView getView() {return view;}
/** Set the user view */
public void setView(UserView view) {this.view = view;}
/**
* Check if user has the required role.
* @param role String representation of Role
*/
public boolean isUserInRole(String role){
if (view != null && view.getHabilitations().get(role) != null)
return true;
else
return false;
}
/**
* Check if user has the required role for given resource.
* @param role String representation of Role
* @param resource String representation of resource
*/
public boolean isUserInRoleForResource(String role, String resource){
if (isUserInRole(role)){
Iterator it = ((Collection)view.getHabilitations().get(role)).iterator();
while (it != null && it.hasNext()){
String res = (String)it.next();
if (res.equals(resource))
return true;
}
}
return false;
}
/**
* Get the resources for this role if user has the given role.
* Resources can represents deliverables, environments on which user
* has rights, depending on the role.
* @param role String representation of Role
*/
public Collection getResources(String role){
if (isUserInRole(role))
return (Collection)view.getHabilitations().get(role);
else
return null;
}
// Protected ----------------------------------------------------------------
/** Cleanup any opened resources */
protected void cleanup(){
this.view = null;
}
// Implementation of HttpSessionBindingListener -----------------------------
/**
* The container calls this method when this object is
* being bound to the user's session.
*/
public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent){
}
/**
* The container calls this method when this object is
* being unbound from the user's session.
*/
public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent){
cleanup();
}
}
|