예제 #1
0
  /**
   * Display information about licensing. Implemented here because this is one of the few classes in
   * milton which is generally not replaceable.
   */
  private void displayCopyrightNotice() {
    Properties validatedLicenseProps = getValidatedLicenseProperties();
    System.out.println("Initializing Milton2 Webdav library. Checking for license file...");
    if (validatedLicenseProps == null) {
      System.out.println(
          "No license file found. By using this software you are agreeing to the terms of the Affero GPL - http://www.gnu.org/licenses/agpl-3.0.html");
      System.out.println(
          "For non-FOSS/commercial usage you should obtain a commercial license. Please see http://milton.io/license for details");
      System.out.println("Copyright McEvoy Software Limited");
      try {
        URL url = new URL("http://milton.io/downloads/version.txt");
        InputStream in = url.openStream();
        if (in != null) {
          ByteArrayOutputStream bout = new ByteArrayOutputStream();
          IOUtils.copy(in, bout);
          String latestVersion = bout.toString("UTF-8").trim();
          in =
              LockHandler.class.getResourceAsStream(
                  "/META-INF/maven/io.milton/milton-server-ent/pom.properties");
          // in = LockHandler.class.getResourceAsStream("/test/pom.properties");
          if (in != null) {
            Properties props = new Properties();
            props.load(in);
            in.close();
            String localVersion = props.getProperty("version");
            if (localVersion != null) {
              localVersion = localVersion.trim();
              if (!localVersion.equals(latestVersion)) {
                System.out.println(
                    "A new version of Milton2 Webdav has been released: "
                        + latestVersion
                        + " - see http://milton.io/downloads");
              } else {
                System.out.println("using latest");
              }
            } else {
              System.out.println("no version prop");
            }
          } else {
            System.out.println("no meta information, can't check latest version");
          }
        }
      } catch (Throwable e) {

      }

    } else {
      System.out.println("Milton2 license found:");
      for (String key : validatedLicenseProps.stringPropertyNames()) {
        System.out.println(key + ": " + validatedLicenseProps.getProperty(key));
      }
    }
  }
예제 #2
0
파일: XmlWriter.java 프로젝트: saces/milton
 public void sample(InputStream in) {
   Logger.debug(this, "outputting sample");
   try {
     ByteArrayOutputStream out = FileUtils.readIn(in);
     writer.write(out.toString());
   } catch (FileNotFoundException ex) {
     Logger.error(this, "", ex);
   } catch (IOException ex) {
     Logger.error(this, "", ex);
   } finally {
     FileUtils.close(in);
   }
 }
예제 #3
0
 {
   ByteArrayOutputStream oStream = new ByteArrayOutputStream();
   PrintStream stream = new PrintStream(oStream);
   JourneyPattern jp = new JourneyPattern();
   ObjectReference objectRef = new ObjectReference(jp);
   objectRef.print(stream, new StringBuilder(), 1, true);
   String text = oStream.toString();
   JSONObject res = null;
   try {
     res = new JSONObject(text);
     Assert.assertEquals(
         res.getString("type"), TYPE.journey_pattern, "wrong object reference type");
     Assert.assertEquals(res.getString("id"), jp.getObjectId(), "wrong object referenced id");
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
예제 #4
0
 public ExecResponse exec(String command) {
   checkConnected();
   ChannelExec executor = null;
   try {
     try {
       executor = (ChannelExec) session.openChannel("exec");
       executor.setPty(true);
     } catch (JSchException e) {
       throw new SshException(
           String.format("%s@%s:%d: Error connecting to exec.", username, host, port), e);
     }
     executor.setCommand(command);
     ByteArrayOutputStream error = new ByteArrayOutputStream();
     executor.setErrStream(error);
     try {
       executor.connect();
       String outputString = Strings2.toStringAndClose(executor.getInputStream());
       String errorString = error.toString();
       int errorStatus = executor.getExitStatus();
       int i = 0;
       while ((errorStatus = executor.getExitStatus()) == -1 && i < this.sshRetries)
         backoffForAttempt(++i, String.format("%s@%s:%d: bad status: -1", username, host, port));
       if (errorStatus == -1)
         throw new SshException(
             String.format(
                 "%s@%s:%d: received exit status %d executing %s",
                 username, host, port, executor.getExitStatus(), command));
       return new ExecResponse(outputString, errorString, errorStatus);
     } catch (Exception e) {
       throw new SshException(
           String.format("%s@%s:%d: Error executing command: %s", username, host, port, command),
           e);
     }
   } finally {
     if (executor != null) executor.disconnect();
   }
 }
  @Test
  public void testCliFailure() throws Exception {
    prepareSecurity();

    FreeStyleProject srcProject = j.createFreeStyleProject();
    srcProject.addProperty(
        new AuthorizeProjectProperty(new SpecificUsersAuthorizationStrategy("admin", false)));
    srcProject.save();

    WebClient wc = j.createWebClient();
    wc.login("test1", "test1");

    // GET config.xml of srcProject (userid is set to admin)
    String configXml = null;
    {
      CLI cli = new CLI(j.getURL());
      ByteArrayOutputStream stdout = new ByteArrayOutputStream();
      ByteArrayOutputStream stderr = new ByteArrayOutputStream();
      int ret =
          cli.execute(
              Arrays.asList(
                  "get-job",
                  srcProject.getFullName(),
                  "--username",
                  "test1",
                  "--password",
                  "test1"),
              new NullInputStream(0),
              stdout,
              stderr);
      assertEquals(stderr.toString(), 0, ret);
      configXml = stdout.toString();
    }

    // POST config.xml of srcProject (userid is set to admin) to a new project.
    // This should fail.
    FreeStyleProject destProject = j.createFreeStyleProject();
    destProject.save();
    String projectName = destProject.getFullName();

    {
      CLI cli = new CLI(j.getURL());
      ByteArrayOutputStream stdout = new ByteArrayOutputStream();
      ByteArrayOutputStream stderr = new ByteArrayOutputStream();
      int ret =
          cli.execute(
              Arrays.asList(
                  "update-job",
                  destProject.getFullName(),
                  "--username",
                  "test1",
                  "--password",
                  "test1"),
              new ByteArrayInputStream(configXml.getBytes()),
              stdout,
              stderr);
      assertNotEquals(0, ret);
    }

    {
      FreeStyleProject p = j.jenkins.getItemByFullName(projectName, FreeStyleProject.class);
      assertNotNull(p);
      AuthorizeProjectProperty prop = p.getProperty(AuthorizeProjectProperty.class);
      assertTrue(prop == null || prop.getStrategy() == null);
    }

    j.jenkins.reload();

    {
      FreeStyleProject p = j.jenkins.getItemByFullName(projectName, FreeStyleProject.class);
      assertNotNull(p);
      AuthorizeProjectProperty prop = p.getProperty(AuthorizeProjectProperty.class);
      assertTrue(prop == null || prop.getStrategy() == null);
    }
  }
예제 #6
0
 /**
  * Get ICE template
  *
  * @return ice template
  * @throws IOException
  */
 private String getTemplate() throws IOException {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   IOUtils.copy(getClass().getResourceAsStream("/template.xhtml"), out);
   return out.toString("UTF-8");
 }