Package com.cosmo.data

Examples of com.cosmo.data.DataAgent


    * @throws AuthenticationException
    */
   public void setUserPassword(String login, String oldPassword, String newPassword) throws UserNotFoundException, AuthenticationException
   {
      String sSQL;
      DataAgent conn = null;

      try
      {
         // Comprueba que exista el usuario y que el password actual sea el correcto
         sSQL = "SELECT Count(*) " +
                "FROM  " + TABLE_NAME + " " +
                "WHERE Lower(usrlogin) = '" + login.trim().toLowerCase() + "' And " +
                "      usrpwd = '" + CryptoUtils.encrypt(oldPassword) + "'";

         conn = DataFactory.getInstance(workspace);
         if (conn.executeScalar(sSQL) <= 0)
         {
            throw new UserNotFoundException();
         }

         // Actualiza la contrase�a del usuario
         sSQL = "UPDATE " + TABLE_NAME + " " +
                "SET   usrpwd = '" + CryptoUtils.encrypt(newPassword) + "' " +
                "WHERE Lower(usrlogin) = '" + login.trim().toLowerCase() + "'";

         conn.execute(sSQL);

         // Confirma los cambios en la bbdd
         if (!conn.isAutoCommit()) conn.commit();
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here


    */
   public ArrayList<User> getUsers() throws AuthenticationException
   {
      String sSQL;
      ResultSet rs;
      DataAgent conn = null;

      ArrayList<User> users = new ArrayList<User>();

      try
      {
         sSQL = "SELECT   * " +
                "FROM     " + TABLE_NAME + " " +
                "ORDER BY usrlogin Asc";

         conn = DataFactory.getInstance(workspace);
         rs = conn.executeSql(sSQL);
         while (rs.next())
         {
            users.add(readUser(rs));
         }

         return users;
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    */
   public ArrayList<User> findUsers(String filter) throws AuthenticationException
   {
      String sSQL;
      ResultSet rs;
      DataAgent conn = null;

      ArrayList<User> users = new ArrayList<User>();

      try
      {
         sSQL = "SELECT   * " +
                "FROM     " + TABLE_NAME + " " +
                "WHERE usrlogin LIKE '%" + DataAgent.sqlFormatTextValue(filter) + "%' Or " +
                "      usrname  LIKE '%" + DataAgent.sqlFormatTextValue(filter) + "%' Or " +
                "      usrmail  LIKE '%" + DataAgent.sqlFormatTextValue(filter) + "%' " +
                "ORDER BY usrlogin Asc";

         conn = DataFactory.getInstance(workspace);
         rs = conn.executeSql(sSQL);
         while (rs.next())
         {
            users.add(readUser(rs));
         }

         return users;
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthenticationException
    */
   public ResultSet getUsersList() throws AuthenticationException
   {
      String sSQL;
      DataAgent conn = null;

      try
      {
         sSQL = "SELECT   usrlogin   As Login, " +
                "         usrname    As Nom, " +
                "         usrmail    As Mail, " +
                "         usrcreated As Creat " +
                "FROM " + TABLE_NAME + " " +
                "ORDER BY usrlogin Asc";

         conn = DataFactory.getInstance(workspace);
         return conn.executeSql(sSQL);
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthenticationException
    */
   private boolean isLocked(String login, int attempts, int timeout) throws AuthenticationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene y abre la conexi�n a BBDD
         conn = DataFactory.getInstance(workspace);

         // Limpia bloqueos caducados (de m�s de [timeout] minutos)
         sql = "DELETE FROM " + TABLE_LOCKS + " " +
               "WHERE ((DATE_PART('day', CURRENT_TIMESTAMP - lastattempt) * 24 + " +
               "        DATE_PART('hour', CURRENT_TIMESTAMP - lastattempt)) * 60 + " +
               "        DATE_PART('minute', CURRENT_TIMESTAMP - lastattempt) >= " + timeout + ")";
         conn.execute(sql);

         // Consulta si el usuario dispone de un registro bloqueado:
         // Dispone de N intentos (o m�s) y el �ltimo intento hace menos de M minutos que se produjo
         sql = "SELECT Count(*) " +
               "FROM " + TABLE_LOCKS + " " +
               "WHERE ((DATE_PART('day', CURRENT_TIMESTAMP - lastattempt) * 24 + " +
               "        DATE_PART('hour', CURRENT_TIMESTAMP - lastattempt)) * 60 + " +
               "        DATE_PART('minute', CURRENT_TIMESTAMP - lastattempt) < " + timeout + ") And " +
               "        lower(login) = '" + DataAgent.sqlFormatTextValue(login) + "' And " +
               "        fails >= " + attempts;
         int nregs = conn.executeScalar(sql);

         return (nregs > 0);
      }
      catch (DataException ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthenticationException
    */
   private void loginFail(String login) throws AuthenticationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene y abre la conexi�n a BBDD
         conn = DataFactory.getInstance(workspace);

         // Consulta si el login tiene un registro asociado
         sql = "SELECT Count(*) " +
               "FROM  " + TABLE_LOCKS + " " +
               "WHERE lower(login) = '" + DataAgent.sqlFormatTextValue(login) + "'";
         int nregs = conn.executeScalar(sql);

         if (nregs > 0)
         {
            sql = "UPDATE " + TABLE_LOCKS + " " +
                  "SET lastattempt = CURRENT_TIMESTAMP, fails = fails + 1 " +
                  "WHERE lower(login) = '" + DataAgent.sqlFormatTextValue(login) + "'";
            conn.execute(sql);
         }
         else if (nregs <= 0)
         {
            if (loginExist(login))
            {
               sql = "INSERT INTO " + TABLE_LOCKS + " (login, fails, lastattempt, ipaddress) " +
                     "VALUES ('" + DataAgent.sqlFormatTextValue(login) + "', 1, CURRENT_TIMESTAMP, '" + workspace.getServerRequest().getRemoteAddr() + "')";
               conn.execute(sql);
            }
         }

         // Confirma los cambios en la bbdd
         if (!conn.isAutoCommit()) conn.commit();
      }
      catch (DataException ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      catch (Exception ex)
      {
         throw new AuthenticationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

   }

   @Override
   public PageContext loadPageEvent(PageContext pc, HttpServletRequest request, HttpServletResponse response)
   {
      DataAgent conn;
      WeatherManager wm;

      try
      {
         conn = DataFactory.getInstance(getWorkspace());
View Full Code Here

   @Override
   public ArrayList<ListItem> getListItems(Workspace workspace) throws Exception
   {
      ListItem item;
      ResultSet rs;
      DataAgent conn = null;

      // Si existe cach� y ya est� cargada la lista la devuelve.
      if (this.cacheMode != CacheMode.None && this.isLoaded)
      {
         return items;
      }

      try
      {
         items.clear();

         conn = DataFactory.getInstance(workspace, this.connection);
         rs = conn.executeSql(sql);
         while (rs.next())
         {
            item = new ListItem(rs.getString(this.valueFieldName),
                                rs.getString(this.titleFieldName));
            items.add(item);
         }
        
         this.isLoaded = true;
      }
      catch (Exception ex)
      {
         throw ex;
      }
      finally
      {
         if (connection != null)
         {
            conn.disconnect();
         }
      }

      return items;
   }
View Full Code Here

   }

   @Override
   public PageContext formSendedEvent(PageContext pc, HttpServletRequest request, HttpServletResponse response)
   {
      DataAgent conn;
      WeatherManager wm;
     
      Weather weather = new Weather();
      weather.setCityName(HttpRequestUtils.getValue(request, "txtName"));
      weather.setTempMin(HttpRequestUtils.getInt(request, "txtTMin"));
View Full Code Here

   }
  
   @Override
   public PageContext loadPageEvent(PageContext pc, HttpServletRequest request, HttpServletResponse response)
   {
      DataAgent conn;
      WeatherManager wm;
     
      try
      {
         conn = DataFactory.getInstance(getWorkspace(), "cosmo.server");
View Full Code Here

TOP

Related Classes of com.cosmo.data.DataAgent

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.