Example #1
0
  public UserDTO doLdapAuthentication(UserDTO dto) throws Exception {
    log.info("INSIDE LDAP AUTHENTICATION 2");
    UserDTO ldapDTO = null;
    String url = "ldap://172.18.20.0:10389";
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, url);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
    env.put(Context.SECURITY_CREDENTIALS, "secret");

    try {
      ldapDTO = new UserDTO();
      DirContext ctx = new InitialDirContext(env);
      Attributes attrs = ctx.getAttributes("cn=" + dto.getUsername() + ",ou=users,ou=system");
      Attribute userPassword = attrs.get("userPassword");
      String ldapPasswordFromDB = new String((byte[]) userPassword.get());
      String md5EncryptedPassword = encryptLdapPassword("md5", dto.getPassword());
      if (md5EncryptedPassword.equalsIgnoreCase(ldapPasswordFromDB)) {
        ldapDTO.setEmployeeId((String) (attrs.get("employeeNumber").get()));
        ldapDTO.setEmployeeType((String) (attrs.get("employeeType").get()));
        ldapDTO.setUsername((String) (attrs.get("cn").get()));
      }
      ctx.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return ldapDTO;
  }
Example #2
0
  public String getViewersOf(Integer photo_id) throws Exception {
    Connection db;
    Statement st;
    String query, out = "";

    try {
      db = getDBConn();
    } catch (Exception e) {
      throw new Exception("Can't get database connection: " + e.getMessage());
    }

    query =
        "select wwwusers.username, log.remote_addr,\n"
            + "   user_agent.user_agent, log.cached, log.ts\n"
            + "  from wwwusers, photo_log log, user_agent\n"
            + "  where log.wwwuser_id = wwwusers.id and\n"
            + "    log.photo_id = "
            + photo_id
            + " and\n"
            + "    user_agent.user_agent_id = log.user_agent\n"
            + "  order by log.ts\n";
    try {
      st = db.createStatement();
      ResultSet rs = st.executeQuery(query);

      Hashtable htmp = new Hashtable();
      htmp.put("PHOTO_ID", photo_id.toString());
      out = PhotoUtil.tokenize(photosession, "log/viewers_top.inc", htmp);

      while (rs.next()) {
        try {
          Hashtable h = new Hashtable();
          h.put("USERNAME", rs.getString(1));
          h.put("REMOTE_ADDR", rs.getString(2));
          h.put("USER_AGENT", rs.getString(3));
          h.put("CACHED", rs.getString(4));
          h.put("TS", rs.getString(5));
          out += PhotoUtil.tokenize(photosession, "log/viewers_match.inc", h);
        } catch (Exception e) {
          log("Error reporting log entry for " + photo_id.toString() + " from " + rs.getString(5));
        }
      }

      out += PhotoUtil.tokenize(photosession, "log/viewers_bottom.inc", new Hashtable());

    } catch (Exception e) {
      throw new Exception(e.getMessage());
    } finally {
      freeDBConn(db);
    }

    return (out);
  }