示例#1
0
  @Override
  public void execute(DatabaseInterface conn, DatabaseTask task, OperationResult log) {
    TablesAdapter db = new TablesAdapter(conn, task);

    db.rebuildIndexes();

    Hub.instance.getDomainInfo(task.getDomain()).fireAfterReindex();

    task.complete();
  }
示例#2
0
  @Override
  public void execute(DatabaseInterface conn, DatabaseTask task, OperationResult log) {
    if (task.isReplicating()) return;

    RecordStruct params = task.getParamsAsRecord();
    RecordStruct fields = params.getFieldAsRecord("Fields");

    RecordStruct uname = fields.getFieldAsRecord("dcUsername");

    if (uname == null) {
      log.error("Username required to insert a user.");
      return;
    }

    TablesAdapter db = new TablesAdapter(conn, task);

    try {
      for (FieldStruct fs : uname.getFields()) {
        RecordStruct rec = (RecordStruct) fs.getValue();

        if (rec.isFieldEmpty("Data")) {
          log.error("Username required to insert a user.");
          return;
        }

        Object userid =
            db.firstInIndex(
                "dcUser",
                "dcUsername",
                rec.getFieldAsString("Data"),
                BigDateTime.nowDateTime(),
                false);

        if (userid != null) {
          log.error("Username must be unique, this username (email) already in use.");
          return;
        }
      }
    } catch (Exception x) {
      log.error("Insert User: Failed to read Index: " + x);
    }
  }
示例#3
0
  @Override
  public void execute(DatabaseInterface conn, DatabaseTask task, OperationResult log) {
    if (task.isReplicating()) {
      // TODO what should happen during a replicate?
      task.complete();
      return;
    }

    RecordStruct params = task.getParamsAsRecord();
    TablesAdapter db = new TablesAdapter(conn, task);
    BigDateTime when = BigDateTime.nowDateTime();

    String password = params.getFieldAsString("Password");
    String uname = params.getFieldAsString("Username");

    // TODO part of Trust monitoring -- boolean suspect =
    // if (AddUserRequest.meetsPasswordPolicy(password, true).hasLogLevel(DebugLevel.Warn))
    //	params.withField("Suspect", true);

    String uid = null;

    Object userid = db.firstInIndex("dcUser", "dcUsername", uname, when, false);

    if (userid != null) uid = userid.toString();

    // fail right away if not a valid user
    if (StringUtil.isEmpty(uid)) {
      log.errorTr(123);
      task.complete();
      return;
    }

    String ckey = params.getFieldAsString("ClientKeyPrint");

    // find out if this is a master key
    if (StringUtil.isNotEmpty(ckey)) {
      System.out.println("sign in client key: " + ckey);

      task.pushDomain(Constants.DB_GLOBAL_ROOT_DOMAIN);

      Object mk =
          db.getStaticList("dcDomain", Constants.DB_GLOBAL_ROOT_DOMAIN, "dcMasterKeys", ckey);

      Object mpp =
          (mk == null)
              ? null
              : db.getStaticScalar(
                  "dcDomain", Constants.DB_GLOBAL_ROOT_DOMAIN, "dcMasterPasswordPattern");

      task.popDomain();

      // if master key is present for the client key then check the password pattern
      if (mk != null) {
        boolean passcheck = false;

        if (StringUtil.isEmpty((String) mpp)) {
          passcheck = true;
        } else {
          Pattern pp = Pattern.compile((String) mpp);
          Matcher pm = pp.matcher(password);
          passcheck = pm.matches();
        }

        if (passcheck) {
          this.signIn(conn, task, db, log, when, uid);
          return;
        }
      }
    }

    if (StringUtil.isNotEmpty(password)) {
      password = password.trim();

      Object fndpass = db.getDynamicScalar("dcUser", uid, "dcPassword", when);

      System.out.println("local password: "******"try local password: "******"root")) {
        task.pushDomain(Constants.DB_GLOBAL_ROOT_DOMAIN);

        Object gp =
            db.getStaticScalar("dcDomain", Constants.DB_GLOBAL_ROOT_DOMAIN, "dcGlobalPassword");

        task.popDomain();

        System.out.println("global password: "******"try global password: "******"dcUser", uid, "dcConfirmCode");

      if (password.equals(fndpass)) {
        Object ra = db.getStaticScalar("dcUser", uid, "dcRecoverAt");

        if (ra == null) {
          // if code matches then good login
          this.signIn(conn, task, db, log, when, uid);
          return;
        }

        if (ra != null) {
          DateTime radt = Struct.objectToDateTime(ra);
          DateTime pastra = new DateTime().minusHours(2);

          if (!pastra.isAfter(radt)) {
            // if code matches and has not expired then good login
            this.signIn(conn, task, db, log, when, uid);
            return;
          }
        }
      }
    }

    log.errorTr(123);
    task.complete();
  }
示例#4
0
  public void signIn(
      DatabaseInterface conn,
      DatabaseTask task,
      TablesAdapter db,
      OperationResult log,
      BigDateTime when,
      String uid) {
    ICompositeBuilder out = task.getBuilder();
    RecordStruct params = task.getParamsAsRecord();
    String did = task.getDomain();

    String token = null;

    try {
      if (StringUtil.isEmpty(uid)) {
        log.errorTr(123);
        task.complete();
        return;
      }

      if (!db.isCurrent("dcUser", uid, when, false)) {
        log.errorTr(123);
        task.complete();
        return;
      }

      if (!task.isReplicating()) {
        // TODO a confirmed login requires at least user name and a confirmation code, it might also
        // take a password
        // but the code must be present to become a confirmed user
        // i '$$get1^dcDb("dcUser",uid,"dcConfirmed") d
        // . i (code'="")&($$get1^dcDb("dcUser",uid,"dcConfirmCode")=code) s
        // Params("Confirmed")=1,confirmed=1 q
        // . d err^dcConn(124) q

        token = Session.nextSessionId();
      }

      if (log.hasErrors()) {
        task.complete();
        return;
      }

      // replication will need these later
      if (!task.isReplicating()) {
        params.setField("Token", token);
        params.setField("Uid", uid);
      }

      // both isReplicating and normal store the token

      conn.set("dcSession", token, "LastAccess", task.getStamp());
      conn.set("dcSession", token, "User", uid);
      conn.set("dcSession", token, "Domain", did);

      // if (confirmed)
      //	db.setStaticScalar("dcUser", uid, "dcConfirmed", confirmed);

      // TODO create some way to track last login that doesn't take up db space
      // or make last login an audit thing...track all logins in StaticList?

      // done with replication stuff
      if (task.isReplicating()) {
        task.complete();
        return;
      }

      // load info about the user
      ListStruct select =
          new ListStruct(
              new RecordStruct(new FieldStruct("Field", "Id"), new FieldStruct("Name", "UserId")),
              new RecordStruct(
                  new FieldStruct("Field", "dcUsername"), new FieldStruct("Name", "Username")),
              new RecordStruct(
                  new FieldStruct("Field", "dcFirstName"), new FieldStruct("Name", "FirstName")),
              new RecordStruct(
                  new FieldStruct("Field", "dcLastName"), new FieldStruct("Name", "LastName")),
              new RecordStruct(
                  new FieldStruct("Field", "dcEmail"), new FieldStruct("Name", "Email")),
              new RecordStruct(
                  new FieldStruct("Field", "dcLocale"), new FieldStruct("Name", "Locale")),
              new RecordStruct(
                  new FieldStruct("Field", "dcChronology"), new FieldStruct("Name", "Chronology")),
              // TODO we actually need group tags too - extend how this works
              new RecordStruct(
                  new FieldStruct("Field", "dcAuthorizationTag"),
                  new FieldStruct("Name", "AuthorizationTags")),
              new RecordStruct(
                  new FieldStruct("Value", token), new FieldStruct("Name", "AuthToken")));

      // out.startRecord();
      // out.field("UserInfo");

      this.writeRecord(conn, task, log, out, db, "dcUser", uid, when, select, true, false, false);

      // out.field("AdditionalTags", null);
      // out.endRecord();
    } catch (Exception x) {
      log.error("SignIn: Unable to create resp: " + x);
    }

    task.complete();
  }