Package com.cosmo.security

Examples of com.cosmo.security.User


      }

      try
      {
         // Recopilaci�n de datos
         User user = new User();
         user.setLogin(HttpRequestUtils.getValue(request, FIELD_LOGIN));
         user.setMail(HttpRequestUtils.getValue(request, FIELD_MAIL));
         user.setName(HttpRequestUtils.getValue(request, FIELD_NAME));

         // Acciones
         PostgreSqlAuthenticationImpl up = (PostgreSqlAuthenticationImpl) AuthenticationFactory.getInstance(getWorkspace());
         up.add(user, HttpRequestUtils.getValue(request, FIELD_PASSWORD));
View Full Code Here


    *
    * @throws AuthenticationException
    */
   private User validate(String serviceUrl, String serviceTicket) throws AuthenticationException
   {
      User user = null;
     
      URL url = new URL(agent.getParamString(AGENT_PARAM_CASSERVICE));
      url.addFolderOrFile(SERVICE_VALIDATE_URL_PART);
     
      String toUrl = url.toString();
View Full Code Here

   public User getUserDataFromValidation(String responseData) throws AuthenticationException
   {
      Node nNode;
      NodeList nList;
      SimpleEntry<String, String> attrib = null;
      User user = null;
     
      try
      {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setNamespaceAware(true);

         DocumentBuilder builder = factory.newDocumentBuilder();
         Document doc = builder.parse(new InputSource(new StringReader(responseData)));
         doc.getDocumentElement().normalize();
        
         // Obtiene el LOGIN del usuario
         nList = doc.getElementsByTagNameNS("*", TAG_CAS_USER);
         for (int temp = 0; temp < nList.getLength(); temp++)
         {
            nNode = nList.item(0);
            if (nNode.getNodeType() == Node.ELEMENT_NODE)
            {
               user = new User();
               user.setLogin(nNode.getFirstChild().getNodeValue());
               break;
            }
         }
        
         // Si no se ha podido extraer el usuario, se devuelve null
View Full Code Here

    */
   @Override
   public User login(String login, String password) throws UserNotFoundException, AuthenticationException
   {
      String sql;
      User user = null;
      // DataSource ds;
      DataAgent conn = null;
     
      // Comprobaci�n de cuenta bloqueada
      if (agent.getParamBoolean(PARAM_LOCKCONTROL, false))
      {
         // Obtiene la configuraci�n del agente
         int attemps = agent.getParamInteger(PARAM_ATTEMPTS, 5);
         int timeout = agent.getParamInteger(PARAM_TIMEOUT, 30);

         // Determina si la cuenta del usuario est� o no bloqueada
         if (isLocked(login, attemps, timeout))
         {
            throw new AuthenticationException("La cuenta " + login + " est� bloqueada.");
         }
      }

      try
      {
         sql = "SELECT * " +
               "FROM  " + TABLE_NAME + " " +
               "WHERE Lower(usrlogin) = '" + login.trim().toLowerCase() + "' And " +
               "      usrpwd = '" + CryptoUtils.encrypt(password) + "'";

         conn = DataFactory.getInstance(workspace);
         // ds = this.workspace.getProperties().getDataProperties().getDataSource();
         // conn = new DataConnection(ds);
         // conn.connect();
         ResultSet rs = conn.executeSql(sql);
         if (rs.next())
         {
            user = new User();
            user.setLogin(rs.getString("usrlogin"));
            user.setMail(rs.getString("usrmail"));
            user.setName(rs.getString("usrname"));
            user.setCreated(rs.getDate("usrcreated"));
            user.setLastLogin(rs.getDate("usrlastlogin"));
            user.setLogonCount(rs.getInt("usrlogoncount"));
         }
         else
         {
            // Si tiene el control de bloqueo activado, actualiza la informaci�n de bloqueo
            if (agent.getParamBoolean(PARAM_LOCKCONTROL, false))
View Full Code Here

    *
    * @throws SQLException
    */
   private User readUser(ResultSet rs) throws SQLException
   {
      User user = new User();
      user.setLogin(rs.getString("usrlogin"));
      user.setMail(rs.getString("usrmail"));
      user.setName(rs.getString("usrname"));
      user.setCreated(rs.getDate("usrcreated"));
      user.setLastLogin(rs.getDate("usrlastlogin"));
      user.setLogonCount(rs.getInt("usrlogoncount"));

      return user;
   }
View Full Code Here

    * @throws AuthenticationException
    */
   private User authenticate(String login, String password) throws UserNotFoundException, AuthenticationException
   {
      String attrValue;
      User user = null;
     
      try
      {
         Hashtable<String, String> env = new Hashtable<String, String>();
         env.put(Context.INITIAL_CONTEXT_FACTORY, agent.getParamString(PARAM_CONTEXTFACTORY));
         env.put(Context.PROVIDER_URL, "ldap://" + agent.getParamString(PARAM_HOSTURL) + ":" + agent.getParamString(PARAM_HOSTPORT));
         env.put(Context.SECURITY_AUTHENTICATION, "simple");
         env.put(Context.SECURITY_PRINCIPAL, getFormattedLogin(login));
         env.put(Context.SECURITY_CREDENTIALS, password);
        
         DirContext ctx = new InitialDirContext(env);
         SearchControls constraints = new SearchControls();
         constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        
         // Realiza la b�squeda del usuario en el directorio y se autentica
         NamingEnumeration<?> results = ctx.search(agent.getParamString(PARAM_SEARCHBASE), "cn=" + login, constraints);
        
         // Verifica si se ha encontrado la entrada en el directorio
         if (results == null || !results.hasMore())
         {
            throw new UserNotFoundException();
         }
         else
         {
            user = new User();
            user.setLogin(login);
            user.setLogonCount(1);
            user.setLastLogin(new Date());
           
            SearchResult sr = (SearchResult) results.next();
            Attributes attrs = sr.getAttributes();

            for (NamingEnumeration<?> nenum = attrs.getAll(); nenum.hasMoreElements();)
            {
               Attribute attrib = (Attribute) nenum.next();
              
               if (attrib.getID().trim().equalsIgnoreCase(agent.getParamString(PARAM_ATTR_MAIL)))
               {
                  attrValue = "";
                  for (Enumeration<?> vals = attrib.getAll(); vals.hasMoreElements();
                  {
                     attrValue += vals.nextElement();
                  }
                  user.setMail(attrValue);
               }
               else if (attrib.getID().trim().equalsIgnoreCase(agent.getParamString(PARAM_ATTR_NAME)))
               {
                  attrValue = "";
                  for (Enumeration<?> vals = attrib.getAll(); vals.hasMoreElements();
                  {
                     attrValue += vals.nextElement();
                  }
                  user.setName(attrValue);
               }
               else if (attrib.getID().trim().equalsIgnoreCase(agent.getParamString(PARAM_ATTR_SURNAME)))
               {
                  attrValue = "";
                  for (Enumeration<?> vals = attrib.getAll(); vals.hasMoreElements();
                  {
                     attrValue += vals.nextElement();
                  }
                  user.setName(user.getName() + " " + attrValue);
               }
            }
         }
      }
      catch (NamingException ex)
View Full Code Here

      }
     
      try
      {
         // Recopilaci�n de datos
         User user = new User();
         user.setLogin(HttpRequestUtils.getValue(request, FIELD_LOGIN));
         user.setMail(HttpRequestUtils.getValue(request, FIELD_MAIL));
         user.setName(HttpRequestUtils.getValue(request, FIELD_NAME));

         // Acciones
         PostgreSqlAuthenticationImpl up = (PostgreSqlAuthenticationImpl) AuthenticationFactory.getInstance(getWorkspace());
         up.add(user, HttpRequestUtils.getValue(request, FIELD_PASSWORD));
View Full Code Here

TOP

Related Classes of com.cosmo.security.User

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.