コード例 #1
0
 @Override
 public String getPassword() {
   try {
     return PublicEncryptionFactory.decryptString(
         APILocator.getUserAPI().getSystemUser().getPassword());
   } catch (DotDataException e) {
     return "";
   }
 }
コード例 #2
0
ファイル: PushPublisher.java プロジェクト: xxg2/dotCMS
  private String retriveKeyString(String token) throws IOException {
    String key = null;
    if (token.contains(File.separator)) {
      File tokenFile = new File(token);
      if (tokenFile != null && tokenFile.exists())
        key = FileUtils.readFileToString(tokenFile, "UTF-8").trim();
    } else {
      key = token;
    }

    return PublicEncryptionFactory.encryptString(key);
  }
コード例 #3
0
ファイル: PushPublisher.java プロジェクト: xxg2/dotCMS
  @Override
  public PublisherConfig process(final PublishStatus status) throws DotPublishingException {
    if (LicenseUtil.getLevel() < 400)
      throw new RuntimeException("need an enterprise prime license to run this bundler");

    PublishAuditHistory currentStatusHistory = null;
    try {
      // Compressing bundle
      File bundleRoot = BundlerUtil.getBundleRoot(config);

      ArrayList<File> list = new ArrayList<File>(1);
      list.add(bundleRoot);
      File bundle =
          new File(
              bundleRoot + File.separator + ".." + File.separator + config.getId() + ".tar.gz");
      PushUtils.compressFiles(list, bundle, bundleRoot.getAbsolutePath());

      // Retriving enpoints and init client
      List<PublishingEndPoint> endpoints = ((PushPublisherConfig) config).getEndpoints();
      Map<String, List<PublishingEndPoint>> endpointsMap =
          new HashMap<String, List<PublishingEndPoint>>();
      List<PublishingEndPoint> buffer = null;
      // Organize the endpoints grouping them by groupId
      for (PublishingEndPoint pEndPoint : endpoints) {

        String gid =
            UtilMethods.isSet(pEndPoint.getGroupId()) ? pEndPoint.getGroupId() : pEndPoint.getId();

        if (endpointsMap.get(gid) == null) buffer = new ArrayList<PublishingEndPoint>();
        else buffer = endpointsMap.get(gid);

        buffer.add(pEndPoint);

        // put in map with either the group key or the id if no group is set
        endpointsMap.put(gid, buffer);
      }

      ClientConfig cc = new DefaultClientConfig();

      if (Config.getStringProperty("TRUSTSTORE_PATH") != null
          && !Config.getStringProperty("TRUSTSTORE_PATH").trim().equals(""))
        cc.getProperties()
            .put(
                HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
                new HTTPSProperties(tFactory.getHostnameVerifier(), tFactory.getSSLContext()));
      Client client = Client.create(cc);

      // Updating audit table
      currentStatusHistory = pubAuditAPI.getPublishAuditStatus(config.getId()).getStatusPojo();

      currentStatusHistory.setPublishStart(new Date());
      pubAuditAPI.updatePublishAuditStatus(
          config.getId(), PublishAuditStatus.Status.SENDING_TO_ENDPOINTS, currentStatusHistory);
      // Increment numTries
      currentStatusHistory.addNumTries();

      boolean hasError = false;
      int errorCounter = 0;

      for (String group : endpointsMap.keySet()) {
        List<PublishingEndPoint> groupList = endpointsMap.get(group);

        boolean sent = false;
        for (PublishingEndPoint endpoint : groupList) {
          EndpointDetail detail = new EndpointDetail();
          try {
            FormDataMultiPart form = new FormDataMultiPart();
            form.field(
                "AUTH_TOKEN",
                retriveKeyString(
                    PublicEncryptionFactory.decryptString(endpoint.getAuthKey().toString())));

            form.field(
                "GROUP_ID",
                UtilMethods.isSet(endpoint.getGroupId())
                    ? endpoint.getGroupId()
                    : endpoint.getId());

            form.field("ENDPOINT_ID", endpoint.getId());
            form.bodyPart(
                new FileDataBodyPart("bundle", bundle, MediaType.MULTIPART_FORM_DATA_TYPE));

            // Sending bundle to endpoint
            WebResource resource =
                client.resource(endpoint.toURL() + "/api/bundlePublisher/publish");

            ClientResponse response =
                resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);

            if (response.getClientResponseStatus().getStatusCode() == HttpStatus.SC_OK) {
              detail.setStatus(PublishAuditStatus.Status.BUNDLE_SENT_SUCCESSFULLY.getCode());
              detail.setInfo("Everything ok");
              sent = true;
            } else {
              detail.setStatus(PublishAuditStatus.Status.FAILED_TO_SENT.getCode());
              detail.setInfo(
                  "Returned "
                      + response.getClientResponseStatus().getStatusCode()
                      + " status code "
                      + "for the endpoint "
                      + endpoint.getId()
                      + "with address "
                      + endpoint.getAddress());
            }
          } catch (Exception e) {
            hasError = true;
            detail.setStatus(PublishAuditStatus.Status.FAILED_TO_SENT.getCode());

            String error =
                "An error occured for the endpoint "
                    + endpoint.getId()
                    + " with address "
                    + endpoint.getAddress()
                    + ".  Error: "
                    + e.getMessage();

            detail.setInfo(error);

            Logger.error(this.getClass(), error);
          }

          currentStatusHistory.addOrUpdateEndpoint(group, endpoint.getId(), detail);

          if (sent) break;
        }

        if (!sent) {
          hasError = true;
          errorCounter++;
        }
      }

      if (!hasError) {
        // Updating audit table
        currentStatusHistory.setPublishEnd(new Date());
        pubAuditAPI.updatePublishAuditStatus(
            config.getId(),
            PublishAuditStatus.Status.BUNDLE_SENT_SUCCESSFULLY,
            currentStatusHistory);

        // Deleting queue records
        // pubAPI.deleteElementsFromPublishQueueTable(config.getId());
      } else {
        if (errorCounter == endpointsMap.size()) {
          pubAuditAPI.updatePublishAuditStatus(
              config.getId(),
              PublishAuditStatus.Status.FAILED_TO_SEND_TO_ALL_GROUPS,
              currentStatusHistory);
        } else {
          pubAuditAPI.updatePublishAuditStatus(
              config.getId(),
              PublishAuditStatus.Status.FAILED_TO_SEND_TO_SOME_GROUPS,
              currentStatusHistory);
        }
      }

      return config;

    } catch (Exception e) {
      // Updating audit table
      try {
        pubAuditAPI.updatePublishAuditStatus(
            config.getId(), PublishAuditStatus.Status.FAILED_TO_PUBLISH, currentStatusHistory);
      } catch (DotPublisherException e1) {
        throw new DotPublishingException(e.getMessage());
      }

      Logger.error(this.getClass(), e.getMessage(), e);
      throw new DotPublishingException(e.getMessage());
    }
  }
コード例 #4
0
  private void createAccount(WebForm form, HttpServletRequest request) throws Exception {

    User user =
        APILocator.getUserAPI()
            .loadByUserByEmail(form.getEmail(), APILocator.getUserAPI().getSystemUser(), false);
    User defaultUser = APILocator.getUserAPI().getDefaultUser();
    Date today = new Date();

    if (user.isNew() || (!user.isNew() && user.getLastLoginDate() == null)) {

      // ### CREATE USER ###
      Company company = PublicCompanyFactory.getDefaultCompany();
      user.setEmailAddress(form.getEmail().trim().toLowerCase());
      user.setFirstName(form.getFirstName() == null ? "" : form.getFirstName());
      user.setMiddleName(form.getMiddleName() == null ? "" : form.getMiddleName());
      user.setLastName(form.getLastName() == null ? "" : form.getLastName());
      user.setNickName("");
      user.setCompanyId(company.getCompanyId());
      user.setPasswordEncrypted(true);
      user.setGreeting("Welcome, " + user.getFullName() + "!");

      // Set defaults values
      if (user.isNew()) {
        // if it's a new user we set random password
        String pass = PublicEncryptionFactory.getRandomPassword();
        user.setPassword(PublicEncryptionFactory.digestString(pass));
        user.setLanguageId(defaultUser.getLanguageId());
        user.setTimeZoneId(defaultUser.getTimeZoneId());
        user.setSkinId(defaultUser.getSkinId());
        user.setDottedSkins(defaultUser.isDottedSkins());
        user.setRoundedSkins(defaultUser.isRoundedSkins());
        user.setResolution(defaultUser.getResolution());
        user.setRefreshRate(defaultUser.getRefreshRate());
        user.setLayoutIds("");
        user.setActive(true);
        user.setCreateDate(today);
      }
      APILocator.getUserAPI().save(user, APILocator.getUserAPI().getSystemUser(), false);
      // ### END CREATE USER ###

      // ### CREATE USER_PROXY ###
      UserProxy userProxy =
          com.dotmarketing.business.APILocator.getUserProxyAPI()
              .getUserProxy(user.getUserId(), APILocator.getUserAPI().getSystemUser(), false);
      userProxy.setPrefix("");
      userProxy.setTitle(form.getTitle());
      userProxy.setOrganization(form.getOrganization());
      userProxy.setUserId(user.getUserId());
      com.dotmarketing.business.APILocator.getUserProxyAPI()
          .saveUserProxy(userProxy, APILocator.getUserAPI().getSystemUser(), false);
      // ### END CRETE USER_PROXY ###

      // saving user inode on web form
      form.setUserInode(userProxy.getInode());
      if (UtilMethods.isSet(form.getFormType())) {
        HibernateUtil.saveOrUpdate(form);
      }

      ///// WE CAN DO THIS! BUT WE NEED TO ADD CATEGORIES TO WEBFORM AND ALSO CHANGE THE PROCESSES
      // THAT
      //// CREATE THE EXCEL DOWNLOAD FROM WEB FORMS. I DIDN'T ADD IT SO I COMMENTED THIS CODE FOR
      // NOW
      // get the old categories, wipe them out
      /*
      List<Category> categories = InodeFactory.getParentsOfClass(userProxy, Category.class);
      for (int i = 0; i < categories.size(); i++) {
      	categories.get(i).deleteChild(userProxy);
      }
       */
      // Save the new categories
      /*String[] arr = form.getCategories();
      if (arr != null) {
      	for (int i = 0; i < arr.length; i++) {
      		Category node = (Category) InodeFactory.getInode(arr[i], Category.class);
      		node.addChild(userProxy);
      	}
      }*/

      // ### CREATE ADDRESS ###
      try {
        List<Address> addresses = PublicAddressFactory.getAddressesByUserId(user.getUserId());
        Address address =
            (addresses.size() > 0 ? addresses.get(0) : PublicAddressFactory.getInstance());
        address.setStreet1(form.getAddress1() == null ? "" : form.getAddress1());
        address.setStreet2(form.getAddress2() == null ? "" : form.getAddress2());
        address.setCity(form.getCity() == null ? "" : form.getCity());
        address.setState(form.getState() == null ? "" : form.getState());
        address.setZip(form.getZip() == null ? "" : form.getZip());
        String phone = form.getPhone();
        address.setPhone(phone == null ? "" : phone);
        address.setUserId(user.getUserId());
        address.setCompanyId(company.getCompanyId());
        PublicAddressFactory.save(address);
      } catch (Exception ex) {
        Logger.error(this, ex.getMessage(), ex);
      }

      Role defaultRole =
          com.dotmarketing.business.APILocator.getRoleAPI()
              .loadRoleByKey(Config.getStringProperty("CMS_VIEWER_ROLE"));
      String roleId = defaultRole.getId();
      if (InodeUtils.isSet(roleId)) {
        com.dotmarketing.business.APILocator.getRoleAPI().addRoleToUser(roleId, user);
      }
    }
    // ### END CREATE ADDRESS ###

    // ### BUILD THE USER COMMENT ###
    addUserComments(user.getUserId(), form, request);
    // ### END BUILD THE USER COMMENT ###

    /* associate user with their clickstream request */
    if (Config.getBooleanProperty("ENABLE_CLICKSTREAM_TRACKING", false)) {
      ClickstreamFactory.setClickStreamUser(user.getUserId(), request);
    }
  }