Exemplo n.º 1
0
  public boolean execute(CommandLine cmdLine) {
    ICustomerManager cm = m_container.getCustomerManager();
    List<String> domains = Collections.singletonList(ICustomerManager.EPA_CUSTOMER_DOMAIN);
    IIslandManager im = m_container.getIslandManager();
    int defaultIslandID = im.getDefaultIsland().getId();

    Customer cust =
        cm.createCustomer(
            ICustomerManager.EPA_CUSTOMER_NAME,
            "System", // fromAddress
            "System", // backendID
            "System", // templateID
            "System", // channel
            domains,
            "emsRootPW", // emsRootPassword
            false, // isPartialEnabled
            "System", // activeBrandKey
            "System", // externalID
            defaultIslandID,
            defaultIslandID,
            false);

    PasswordPolicy policy = new PasswordPolicy();
    policy.setUseStrongPasswords(true);
    cust.setPasswordPolicy(policy);
    cm.updateCustomers(Collections.singletonList(cust));

    IUserManager um = ManagementContainer.getInstance().getUserManager();
    UserAccount emsRoot = um.getUser("emsroot@" + ICustomerManager.EPA_CUSTOMER_DOMAIN);
    IAuthenticationManager am = ManagementContainer.getInstance().getAuthenticationManager();
    long seconds = 31556926; // Seconds in a year
    long time =
        System.currentTimeMillis() + (seconds * 100 * 1000L); // Lock the account for 100 years
    am.lockUserAccount(
        cust.getCustID(), emsRoot.getUserID(), "Locked from user details", "Unknown", time);

    return (cust != null);
  }
Exemplo n.º 2
0
  // Use this to set headers that are required on all responses.
  protected void setResponseHeaders(
      ActionForm actionForm, HttpServletResponse response, UserAccount user, Device device)
      throws IOException {

    // The url is static across all devices in a customer.
    ICustomerManager customerManager = ManagementContainer.getInstance().getCustomerManager();
    Customer cust = customerManager.getCustomer(user.getCustomerID());
    IRimManager rimManager = ManagementContainer.getInstance().getRimManager();
    String cappUrl = cust.getCappUrl();
    if (m_devDebug) { // Our dev boxes use http and specifcy a port, this conflicts with the https
      // assumption of getCappUrl()
      cappUrl = "http://turbodog.austin.messageone.com:8080/";
    }

    URL url = null;
    try {
      url = new URL(cappUrl);
    } catch (MalformedURLException e) {

      LogMessageGen lmg = new LogMessageGen();
      lmg.setSubject("Bad URL");
      lmg.param(LoggingConsts.URL, cappUrl);
      lmg.param(LoggingConsts.USER_ID, device.getUserId());
      lmg.param(LoggingConsts.CUSTOMER_ID, device.getCustomerId());
      lmg.param(LoggingConsts.PIN, device.getPin());

      // This would come from the customer config, so it's bad.
      m_logCategory.error(lmg.toString(), e);
      response.setHeader(SUCCESS, "false");
      return;
    }
    int deviceCheckin =
        cust.getCapabilities().getIntCapability(Capabilities.CAP_RIM_DEVICE_PERIODIC_CHECKIN, 30);

    response.setHeader("rim-access-url-protocol", url.getProtocol());
    response.setHeader("rim-access-url-hostname", url.getHost());
    if (url.getPort() > 0) {
      response.setHeader("rim-access-url-port", Integer.toString(url.getPort()));
    }

    response.setHeader(EMS_RIM_DISPLAY_NAME, device.getDisplayName());
    response.setHeader("get-mail-path", "wfe/getRimMail.do");
    response.setHeader("send-mail-path", "wfe/sendRimMail.do");
    response.setHeader("get-display-name-path", "wfe/rimGetDisplayName.do");
    response.setHeader("checkin-path", "wfe/rimCheckin.do");

    response.setHeader("periodic-checkin", Integer.toString(deviceCheckin));

    CustomerState state = user.getUserState();
    String stateString = "ready";
    if (CustomerState.ACTIVE.equals(state) || CustomerState.TEST.equals(state)) {
      stateString = "active";

      String activationId = rimManager.getActivationId(device.getPin());
      if (StringUtils.isEmptyOrNull(activationId)) {
        // EMSDEV-4722
        // If an old agent is installed during activation, the dat_rim_user_connection_status
        // won't exist and thus no activation ID.  If needed, create one on the fly.
        // Incidently, this will fix most of the problems we've had with activationId's
        // disappearing for various reasons.
        LogMessageGen.log(
                "Old agent activationId not found; will create one on the fly", m_logCategory)
            .param(LoggingConsts.PIN, device.getPin())
            .param(LoggingConsts.USER_ID, device.getUserId())
            .info();

        activationId = rimManager.activateOldAgent(device.getPin(), device.getCustomerId());

        // Try again.
        if (StringUtils.isEmptyOrNull(activationId)) {

          LogMessageGen.log("Unable to create activationId for old agent", m_logCategory)
              .param(LoggingConsts.PIN, device.getPin())
              .param(LoggingConsts.USER_ID, device.getUserId())
              .error();
        }
      } // no activationId

      response.setHeader("activation-id", activationId);
    } // active.
    response.setHeader("application-state", stateString);

    response.setHeader(SUCCESS, "true");
  }