org.sonar.api.config.Encryption.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中org.sonar.api.config.Encryption.<init>()方法的一些代码示例,展示了Encryption.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Encryption.<init>()方法的具体详情如下:
包路径:org.sonar.api.config.Encryption
类名称:Encryption
方法名:<init>

Encryption.<init>介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

public MapSettings(PropertyDefinitions definitions) {
 super(definitions, new Encryption(null));
 configurationBridge = new ConfigurationBridge(this);
}

代码示例来源:origin: SonarSource/sonarqube

public ScannerProperties(Map<String, String> properties) {
 encryption = new Encryption(properties.get(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
 Map<String, String> decryptedProps = new HashMap<>(properties.size());
 for (Map.Entry<String, String> entry : properties.entrySet()) {
  String value = entry.getValue();
  if (value != null && encryption.isEncrypted(value)) {
   try {
    value = encryption.decrypt(value);
   } catch (Exception e) {
    throw new IllegalStateException("Fail to decrypt the property " + entry.getKey() + ". Please check your secret key.", e);
   }
  }
  decryptedProps.put(entry.getKey(), value);
 }
 this.properties = decryptedProps;
}

代码示例来源:origin: SonarSource/sonarqube

@VisibleForTesting
ThreadLocalSettings(PropertyDefinitions definitions, Properties props, SettingLoader settingLoader) {
 super(definitions, new Encryption(null));
 this.settingLoader = settingLoader;
 props.forEach((k, v) -> systemProps.put(k, v == null ? null : v.toString().trim()));
 // TODO something wrong about lifecycle here. It could be improved
 getEncryption().setPathToSecretKey(props.getProperty(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void scramble() {
 Encryption encryption = new Encryption(null);
 assertThat(encryption.scramble("foo")).isEqualTo("{b64}Zm9v");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void decrypt() {
 Encryption encryption = new Encryption(null);
 assertThat(encryption.decrypt("{b64}Zm9v")).isEqualTo("foo");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void decrypt_unknown_algorithm() {
 Encryption encryption = new Encryption(null);
 assertThat(encryption.decrypt("{xxx}Zm9v")).isEqualTo("{xxx}Zm9v");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void decrypt_uncrypted_text() {
  Encryption encryption = new Encryption(null);
  assertThat(encryption.decrypt("foo")).isEqualTo("foo");
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void isEncrypted() {
 Encryption encryption = new Encryption(null);
 assertThat(encryption.isEncrypted("{aes}ADASDASAD")).isTrue();
 assertThat(encryption.isEncrypted("{b64}ADASDASAD")).isTrue();
 assertThat(encryption.isEncrypted("{abc}ADASDASAD")).isTrue();
 assertThat(encryption.isEncrypted("{}")).isFalse();
 assertThat(encryption.isEncrypted("{foo")).isFalse();
 assertThat(encryption.isEncrypted("foo{aes}")).isFalse();
}

代码示例来源:origin: SonarSource/sonarqube

private String[] getStringArray(String value) {
  return new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
   PropertyDefinition.builder("multi").multiValues(true).build())), new Encryption(null),
   ImmutableMap.of("multi", value)) {
  }.getStringArray("multi");
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void migrateOldProperties() {
  Map<String, String> settings = new HashMap<>();
  settings.put(GenericCoverageSensor.OLD_REPORT_PATH_PROPERTY_KEY, "old.xml");
  settings.put(GenericCoverageSensor.OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old1.xml,old2.xml");
  settings.put(GenericCoverageSensor.OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old3.xml,old4.xml,old.xml");
  settings.put(GenericCoverageSensor.OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old5.xml,old6.xml");

  PropertyDefinitions defs = new PropertyDefinitions(GenericCoverageSensor.properties());
  DefaultConfiguration config = new ProjectConfiguration(defs, new Encryption(null), settings);

  Set<String> reportPaths = new GenericCoverageSensor(config).loadReportPaths();

  assertThat(logTester.logs(LoggerLevel.WARN)).contains(
   "Property 'sonar.genericcoverage.reportPath' is deprecated. Please use 'sonar.coverageReportPaths' instead.",
   "Property 'sonar.genericcoverage.reportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.",
   "Property 'sonar.genericcoverage.itReportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.",
   "Property 'sonar.genericcoverage.overallReportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.");

  assertThat(reportPaths).containsOnly(
   "old.xml", "old1.xml", "old2.xml", "old3.xml", "old4.xml", "old5.xml", "old6.xml");
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void logWhenDeprecatedPropsAreUsed() throws IOException {
  File basedir = temp.newFolder();
  File report = new File(basedir, "report.xml");
  FileUtils.write(report, "<unitTest version=\"1\"><file path=\"A.java\"><testCase name=\"test1\" duration=\"500\"/></file></unitTest>", StandardCharsets.UTF_8);
  SensorContextTester context = SensorContextTester.create(basedir);

  Map<String, String> settings = new HashMap<>();
  settings.put(GenericTestExecutionSensor.OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, "report.xml");
  PropertyDefinitions defs = new PropertyDefinitions(GenericTestExecutionSensor.properties());
  DefaultConfiguration config = new ProjectConfiguration(defs, new Encryption(null), settings);

  new GenericTestExecutionSensor(mock(TestPlanBuilder.class), config).execute(context);
  assertThat(logTester.logs(LoggerLevel.WARN)).contains(
   "Using 'unitTest' as root element of the report is deprecated. Please change to 'testExecutions'.",
   "Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.");

  assertThat(logTester.logs(LoggerLevel.INFO)).contains(
   "Imported test execution data for 0 files",
   "Test execution data ignored for 1 unknown files, including:\nA.java");
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void getDefaultValues() {
 Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
  PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(),
  PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null),
  ImmutableMap.of()) {
 };
 assertThat(config.get("multiA")).hasValue("foo,bar");
 assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar");
 assertThat(config.get("single")).hasValue("default");
 assertThat(config.getStringArray("single")).containsExactly("default");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void accessingPropertySetPropertiesShouldBeConsistentWithDeclaration() {
 Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
  PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())),
  new Encryption(null),
  ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) {
 };
 assertThat(config.get("props")).hasValue("1,2");
 assertThat(logTester.logs(LoggerLevel.WARN))
  .contains(
   "Access to the multi-values/property set property 'props' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
 logTester.clear();
 assertThat(config.getStringArray("props")).containsExactly("1", "2");
 assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void accessingMultiValuedPropertiesShouldBeConsistentWithDeclaration() {
 Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
  PropertyDefinition.builder("single").multiValues(false).build(),
  PropertyDefinition.builder("multiA").multiValues(true).build())), new Encryption(null),
  ImmutableMap.of("single", "foo", "multiA", "a,b", "notDeclared", "c,d")) {
 };
 assertThat(config.get("multiA")).hasValue("a,b");
 assertThat(logTester.logs(LoggerLevel.WARN))
  .contains(
   "Access to the multi-values/property set property 'multiA' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
 logTester.clear();
 assertThat(config.getStringArray("single")).containsExactly("foo");
 assertThat(logTester.logs(LoggerLevel.WARN))
  .contains(
   "Property 'single' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.");
 logTester.clear();
 assertThat(config.get("notDeclared")).hasValue("c,d");
 assertThat(config.getStringArray("notDeclared")).containsExactly("c", "d");
 assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}

代码示例来源:origin: stackoverflow.com

public String getEncryptWord(String txt) {
  return new Encryption().base64encode(txt);
}

代码示例来源:origin: org.codehaus.sonar/sonar-plugin-api

public Settings(PropertyDefinitions definitions) {
 this.properties = Maps.newHashMap();
 this.definitions = definitions;
 this.encryption = new Encryption(null);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api

public MapSettings(PropertyDefinitions definitions) {
 super(definitions, new Encryption(null));
 configurationBridge = new ConfigurationBridge(this);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

public UserProperties(Map<String, String> properties, @Nullable String pathToSecretKey) {
 encryption = new Encryption(pathToSecretKey);
 Map<String, String> decryptedProps = Maps.newHashMap();
 for (Map.Entry<String, String> entry : properties.entrySet()) {
  String value = entry.getValue();
  if (value != null && encryption.isEncrypted(value)) {
   try {
    value = encryption.decrypt(value);
   } catch (Exception e) {
    throw new IllegalStateException("Fail to decrypt the property " + entry.getKey() + ". Please check your secret key.", e);
   }
  }
  decryptedProps.put(entry.getKey(), value);
 }
 this.properties = Maps.newHashMap(decryptedProps);
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

public UserProperties(Map<String, String> properties, @Nullable String pathToSecretKey) {
 encryption = new Encryption(pathToSecretKey);
 Map<String, String> decryptedProps = Maps.newHashMap();
 for (Map.Entry<String, String> entry : properties.entrySet()) {
  String value = entry.getValue();
  if (value != null && encryption.isEncrypted(value)) {
   try {
    value = encryption.decrypt(value);
   } catch (Exception e) {
    throw new IllegalStateException("Fail to decrypt the property " + entry.getKey() + ". Please check your secret key.", e);
   }
  }
  decryptedProps.put(entry.getKey(), value);
 }
 this.properties = Maps.newHashMap(decryptedProps);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

@VisibleForTesting
ThreadLocalSettings(PropertyDefinitions definitions, Properties props, SettingLoader settingLoader) {
 super(definitions, new Encryption(null));
 this.settingLoader = settingLoader;
 this.systemProps = new Properties();
 props.forEach((k, v) -> systemProps.put(k, v == null ? null : v.toString().trim()));
 // TODO something wrong about lifecycle here. It could be improved
 getEncryption().setPathToSecretKey(props.getProperty(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
}

相关文章