Package com.centraview.settings

Examples of com.centraview.settings.SiteInfo


public class LogoutHandler extends org.apache.struts.action.Action
{
  private static Logger logger = Logger.getLogger(LogoutHandler.class);
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws RuntimeException,Exception
  {
    SiteInfo siteInfo = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext()));
    try
    {
      HttpSession session = request.getSession();
      UserObject userObject = (UserObject)session.getAttribute("userobject");
     
      int individualID = userObject.getIndividualID();    // logged in user
      Timer userTimer = siteInfo.getUserTimer(individualID);
      if (userTimer != null)
      {
        userTimer.cancel();
      }
      if (session != null)
View Full Code Here


  /**
   * checks if the isAlive is bound to the session
   */
  public void valueBound(HttpSessionBindingEvent event)
  {
    SiteInfo siteInfo = Settings.getInstance().getSiteInfo(CVUtility.getHostName(event.getSession().getServletContext()));
    incrementConcurrentUser(siteInfo);
  }
View Full Code Here

   * checks if the isAlive is unbound from the session when session is
   * invalidated
   */
  public void valueUnbound(HttpSessionBindingEvent event)
  {
    SiteInfo siteInfo = Settings.getInstance().getSiteInfo(CVUtility.getHostName(event.getSession().getServletContext()));
    decrementConcurrentUser(siteInfo);
  }
View Full Code Here

   */
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws RuntimeException, CommunicationException, NamingException
  {
    String host = CVUtility.getHostName(super.getServlet().getServletContext());
    SettingsInterface settings = Settings.getInstance();
    SiteInfo siteInfo = settings.getSiteInfo(host);
    final String dataSource = siteInfo.getDataSource();
    HashMap usrResult;
    UserPrefererences up;
    String formUsername = "";
    String formPassword = "";
    String remember = request.getParameter("checkbox");
    String vistLoginPage = request.getParameter("vistLoginPage");

    // check to see if the user has clicked the "I Agree" checkbox
    String agreedTerms = request.getParameter("agreedTerms");
    if (agreedTerms != null && agreedTerms.equals("Yes")) {
      // checkbox has been checked, continue login
    } else {
      // checkbox was not checked, forward back to login page
      return(mapping.findForward(".view.login.failure"));
    }

    if (remember == null) {
      remember = "";
    }

    if (vistLoginPage == null) {
      vistLoginPage = "";
    }

    TreeMap errorMap = new TreeMap();
    String userType = null;
    UserObject userObject = null;
    HttpSession session = request.getSession();
    ModuleFieldRightMatrix mfrm = null;
    LoginHome lh = (LoginHome)CVUtility.getHomeObject("com.centraview.login.LoginHome","Login");

    try {
      // first, let's get the username and password from the HTML form
      DynaActionForm daf = (DynaActionForm)form;
      formUsername = (String)daf.get("username");
      formPassword = (String) daf.get("password");

      // next, let's check for the existence of the CVRMID cookie.
      boolean rmCookieExists = false;
      Cookie requestCookie = null;
      Cookie cookieList[] = request.getCookies();

      if (cookieList != null) {
        for (int i = 0; i < cookieList.length; i++) {
          Cookie tmpCookie = cookieList[i];
          if (tmpCookie.getName().equals("CVRMID")) {
            rmCookieExists = true;
            requestCookie = tmpCookie;
          }
        }
      }
      String cookieUsername = "";
      String cookiePassword = "";

      boolean useFormValues = false;

      // now, if the cookie exists, then get the content
      if (rmCookieExists) {
        // unencode the content of the cookie
        String unEncodedString = new String(Base64.decode(requestCookie.getValue()));

        // split the parts of the string on the "/" character
        String stringParts[] = unEncodedString.split("/");

        // get the username and password values and save for use
        cookieUsername = stringParts[0];
        cookiePassword = stringParts[1];

        // Note: In login.jsp, we checked to see if the cookie was set. If so, we
        // got the username and password from the cookie; we set the username form
        // value to the username from the cookie, and the password to "CVRMID-xxxxxxxx".
        // Therefore, we will check the form password value here; if it is NOT
        // "CVRMID-xxxxxxxx", the we know the user has manually typed in a different
        // password, and we will use the form password vs. the cookie password.
        if (formPassword != null && ! formPassword.equals("CVRMID-xxxxxxxx")) {
          useFormValues = true;
        }

        if (remember == null || remember.equals("")) {
          // if the user has *UN*-checked the Remember Me
          // checkbox, then get rid of their cookie
          this.forgetMe(response);
        }
      }

      String username = "";
      String password = "";

      if (rmCookieExists) {
        if (cookieUsername.equals(formUsername) && ! useFormValues) {
          // if the userName in the cookie equals the username in the form,
          // then, we'll authenticate on the cookie content
          username = cookieUsername;
          password = cookiePassword;
        } else {
          // if the username in the cookie does not match the username in the form,
          // then, we'll authenticate on the form content
          username = formUsername;
          password = formPassword;
        }
      } else {
        // if the cookie does not exist at all, authenticate on the form values
        username = formUsername;
        password = formPassword;
      }

      if (lh == null) {
        return (mapping.findForward("dataerror"));
      }

      Login remote = lh.create();
      remote.setDataSource(dataSource);
      usrResult = remote.authenticateUser(username, password);
      // Check to make sure the usrResult has all the fields we expect of it.
      // if so then it was a valid login, if not, then we will fail with a general
      // authentication error.
      if (usrResult.containsKey("individualid") && usrResult.containsKey("firstName") && usrResult.containsKey("lastName") && usrResult.containsKey("type")) {
        int individualId = Integer.parseInt((String)usrResult.get("individualid"));
        userType = (String)usrResult.get("type");
        String firstName = (String)usrResult.get("firstName");
        String lastName = (String)usrResult.get("lastName");

        if ((! userType.equalsIgnoreCase((String)daf.get("userType"))) && ! ("EMPLOYEE".equals(daf.get("userType")) && userType.equalsIgnoreCase("ADMINISTRATOR"))) {
          String errorHeader = "Error occurred during login.";
          errorMap.put(new Integer(0), errorHeader);
          String error = "The username or password was incorrect, or the user is disabled.";
          errorMap.put(new Integer(1), error);
          request.setAttribute("error", errorMap);
          FORWARD_final = GLOBAL_FORWARD_failure;
          return (mapping.findForward(FORWARD_final));
        }

        userObject = remote.getUserObject(individualId, firstName, lastName, userType);
        userObject.setLoginName(username);

        // In a certain case we will need a blank rights matrix, so prepare the remote connection now.
        AuthorizationHome ah = (AuthorizationHome)CVUtility.getHomeObject("com.centraview.administration.authorization.AuthorizationHome","Authorization");
        Authorization authorizationRemote = ah.create();
        authorizationRemote.setDataSource(dataSource);

        if (remember.equals("on")) {
          // the "Remember Me" cookie contains the a string in the format
          // "<userName>/<password>". This string is then encrypted.
          // We should probably store the SHA1 of the password, this is a major security risk!!
          // TODO: encode the SHA1 of the password in the cookie content, and not the password itself.
          // and write the corresponding login method to take the SHA1 directly.
          String cookieContent = username + "/" + password;
          String encodedString = Base64.encode(cookieContent.getBytes());
          Cookie rememberMeCookie = new Cookie("CVRMID", encodedString);
          // set the expire time - to the largest int possible
          rememberMeCookie.setMaxAge(2147483647);
          rememberMeCookie.setPath("/");
          response.addCookie(rememberMeCookie);
        }

        // get the real mfrm and put it on the UserObject
        mfrm = authorizationRemote.getUserSecurityProfileMatrix(individualId);
        up = userObject.getUserPref();
        up.setModuleAuthorizationMatrix(mfrm);
        userObject.setUserPref(up);
        session.setAttribute("userobject",userObject);

        // User Email Check - will schedule the recurring check
        // of all the user's email accounts, every x minutes where
        // x is defined by the user's preferences.
        int userInterval = userObject.getUserPref().getEmailCheckInterval();
        if (userInterval > 0) {
          // only start this job if the user wants their mail checked
          // automatically. A value of 0 means do not check mail automatically.

          // minutes to seconds, then seconds to miliseconds...
          Integer interval = new Integer(userInterval * 60 * 1000);
         
          // make sure this job isn't already scheduled for some unknown reason...
          // .. by "make sure", I mean blindly cancel the job registered for this user.
          Timer currentTimer = siteInfo.getUserTimer(individualId);
          if (currentTimer != null) {
            currentTimer.cancel();
          }

          TimerTask currentTask = siteInfo.getUserTask(individualId);
          if (currentTask != null) {
            currentTask.cancel();
          }

          Timer newTimer = new Timer(true);
          TimerTask userEmailCheck = new UserEmailCheck(individualId, session, dataSource, host);
          newTimer.schedule(userEmailCheck, 300000L, interval.longValue());
          siteInfo.setUserTimer(individualId, newTimer, userEmailCheck);
        }

        // code added for concurrent user maintinance
        session.setAttribute(SessionAlive.IS_ALIVE, new SessionAlive());

View Full Code Here

      }
    } catch(IllegalStateException ise) {
      // kill this job because the session is not
      // valid, so the user must not be logged in
      logger.debug("[run] Session is invalid, user must have logged out.  Remove the mail check timer.");
      SiteInfo siteInfo = Settings.getInstance().getSiteInfo(host);
      Timer currentTimer = siteInfo.getUserTimer(this.individualId);
      if (currentTimer != null)
      {
        logger.debug("[run] Calling cancel on the timer.");
        currentTimer.cancel();
      }
View Full Code Here

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
      HttpServletResponse response) throws RuntimeException, Exception
  {
    String host = CVUtility.getHostName(super.getServlet().getServletContext());
    SettingsInterface settings = Settings.getInstance();
    SiteInfo siteInfo = settings.getSiteInfo(host);
    final String dataSource = siteInfo.getDataSource();

    // Set up search bar
    request.setAttribute("showAdvancedSearch", new Boolean(false));
    request.setAttribute("showCustomViews", new Boolean(false));
    request.setAttribute("showComposeButton", new Boolean(false));
View Full Code Here

   * set the mime type on the output stream and stream out the image.
   */
  protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
    ServletContext servlet = super.getServletContext();
    SiteInfo siteInfo = Settings.getInstance().getSiteInfo(CVUtility.getHostName(servlet));
    File customerLogo = siteInfo.getCustomerLogo();
    byte[] buffer = null;
    // if size is still zero later, we will write out a hardcoded image.
    int size = 0;
    if (siteInfo.isCustomerLogoDirty())
    {
      // Catch the IOException on this FileInputStream constructor and
      // on the read method so we can set size to zero to fall back.
      DataInputStream customerLogoStream = null;
      FileInputStream fileInputStream = null;
      try
      {
        fileInputStream = new FileInputStream(customerLogo);
        customerLogoStream = new DataInputStream(fileInputStream);
        long length = customerLogo.length();
        // make sure the long isn't bigger than maximum int value.
        if (length <= Integer.MAX_VALUE)
        {
          buffer = new byte[(int)length];
          customerLogoStream.readFully(buffer);
          // Cache the data.
          siteInfo.setCustomerLogoData(buffer);
          siteInfo.setCustomerLogoDirty(false);
          size = buffer.length;
        }
      } catch (IOException e) {
        logger.error("[service] IOException Reading CustomerLogoFile, falling back to safe default.  "+e.toString());
        size = 0;
      } finally {
        try {
          customerLogoStream.close();
          fileInputStream.close();
        } catch (Exception e) {}
      }
    } else {
      buffer = siteInfo.getCustomerLogoData();
      size = buffer.length;
    }
    if (size > 0)
    {
      response.setContentType(this.getMimeType(customerLogo.getName()));
View Full Code Here

  private static final String FORWARD_save = ".forward.administration.customer_logo";
  private static String FORWARD_final = GLOBAL_FORWARD_failure;

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    SiteInfo siteInfo = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext()));
    String dataSource = siteInfo.getDataSource();
    String returnStatus = "";

    try {
      String typeOfSave = "save";
      if (request.getParameter("buttonpress") != null) {
        typeOfSave = request.getParameter("buttonpress");
        String fileName = "";
        File fsRoot = CVUtility.getCentraViewFileSystemRoot(dataSource);
        if (typeOfSave != null && typeOfSave.equals("save")) {
          FormFile fileUpload = ((CustomerLogoForm)form).getFile();
          File logoFile = new File(fsRoot.getAbsolutePath() + Constants.CUSTOMERLOGO_PATH + fileUpload.getFileName());
          FileOutputStream fos = new FileOutputStream(logoFile);
          InputStream fis = fileUpload.getInputStream();
          try {
            int i = 0;
            while ((i = fis.read()) != -1) {
              fos.write(i);
            }
            siteInfo.setCustomerLogo(logoFile);
            siteInfo.setCustomerLogoDirty(true);
          } catch (IOException e) {
            logger.error("[execute] Exception thrown.", e);
          } finally {
            fis.close();
            fos.close();
          }
          fileName = fileUpload.getFileName();
        } else if (typeOfSave != null && typeOfSave.equals("delete")) {
          fileName = "logo_customer.gif";
          File logoFile = new File(fsRoot.getAbsolutePath() + Constants.CUSTOMERLOGO_PATH + fileName);
          siteInfo.setCustomerLogo(logoFile);
          siteInfo.setCustomerLogoDirty(true);
        }
        AppSettingsHome appHome = (AppSettingsHome)CVUtility.getHomeObject("com.centraview.administration.applicationsettings.AppSettingsHome", "AppSettings");
        AppSettings appRemote = (AppSettings)appHome.create();
        appRemote.updateApplicationSettings("CUSTOMERLOGO", fileName);
      }
View Full Code Here

TOP

Related Classes of com.centraview.settings.SiteInfo

Copyright © 2018 www.massapicom. 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.