Search in sources :

Example 66 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class PluggableSCMMaterialTest method shouldConvertPluggableSCMMaterialToJsonFormatToBeStoredInDb.

@Test
public void shouldConvertPluggableSCMMaterialToJsonFormatToBeStoredInDb() {
    GoCipher cipher = new GoCipher();
    ConfigurationProperty secureSCMProperty = new ConfigurationProperty(new ConfigurationKey("secure-key"), null, new EncryptedConfigurationValue("hnfcyX5dAvd82AWUyjfKCQ\u003d\u003d"), cipher);
    ConfigurationProperty scmProperty = new ConfigurationProperty(new ConfigurationKey("non-secure-key"), new ConfigurationValue("value"), null, cipher);
    SCM scmConfig = SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(secureSCMProperty, scmProperty));
    PluggableSCMMaterial pluggableSCMMaterial = new PluggableSCMMaterial();
    pluggableSCMMaterial.setSCMConfig(scmConfig);
    String json = JsonHelper.toJsonString(pluggableSCMMaterial);
    String expected = "{\"scm\":{\"plugin\":{\"id\":\"plugin-id\",\"version\":\"1.0\"},\"config\":[{\"configKey\":{\"name\":\"secure-key\"},\"encryptedConfigValue\":{\"value\":\"hnfcyX5dAvd82AWUyjfKCQ\\u003d\\u003d\"}},{\"configKey\":{\"name\":\"non-secure-key\"},\"configValue\":{\"value\":\"value\"}}]}}";
    assertThat(json, is(expected));
    assertThat(JsonHelper.fromJson(expected, PluggableSCMMaterial.class), is(pluggableSCMMaterial));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) GoCipher(com.thoughtworks.go.security.GoCipher) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SCM(com.thoughtworks.go.domain.scm.SCM) Test(org.junit.Test)

Example 67 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method shouldWriteMultipleSearchBases.

@Test
public void shouldWriteMultipleSearchBases() throws Exception {
    BaseConfig base1 = new BaseConfig("base1");
    BaseConfig base2 = new BaseConfig("base2");
    BasesConfig basesConfig = new BasesConfig(base1, base2);
    LdapConfig ldapConfig = new LdapConfig("url", "managerDn", "managerPassword", "managerPassword", false, basesConfig, "filter");
    SecurityConfig securityConfig = new SecurityConfig(ldapConfig, new PasswordFileConfig("some_path"), false);
    ServerConfig serverConfig = new ServerConfig(securityConfig, new MailHost(new GoCipher()));
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setServerConfig(serverConfig);
    xmlWriter.write(cruiseConfig, output, false);
    GoConfigHolder holder = xmlLoader.loadConfigHolder(output.toString());
    BasesConfig actualBasesConfig = holder.config.server().security().ldapConfig().getBasesConfig();
    assertThat(actualBasesConfig.size(), is(2));
    assertThat(actualBasesConfig, hasItems(base1, base2));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 68 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class SecurityConfigTest method security.

public static SecurityConfig security(LdapConfig ldap, PasswordFileConfig pwordFile, AdminsConfig admins) {
    ldap = ldap == null ? new LdapConfig(new GoCipher()) : ldap;
    pwordFile = pwordFile == null ? new PasswordFileConfig() : pwordFile;
    SecurityConfig security = new SecurityConfig(ldap, pwordFile, true, admins);
    for (Role role : DEFAULT_ROLES) {
        security.addRole(role);
    }
    return security;
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher)

Example 69 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class SecurityConfigTest method shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull.

@Test
public void shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull() throws InvalidCipherTextException {
    SecurityConfig securityConfig = new SecurityConfig();
    securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "p", null, true, new BasesConfig(new BaseConfig("")), ""));
    assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
    assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
    String encryptedPassword = new GoCipher().encrypt("p");
    assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
    securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "notP", null, false, new BasesConfig(new BaseConfig("")), ""));
    assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
    assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
    assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
    securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "", null, true, new BasesConfig(new BaseConfig("")), ""));
    assertThat(securityConfig.ldapConfig().managerPassword(), is(""));
    assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(nullValue()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 70 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class ServerConfigServiceIntegrationTest method shouldUseTheEncryptedPasswordWhenPasswordIsNotChanged.

@Test
public void shouldUseTheEncryptedPasswordWhenPasswordIsNotChanged() throws InvalidCipherTextException {
    String encryptedPassword = new GoCipher().encrypt("encrypted_password");
    LdapConfig ldapConfig = new LdapConfig(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, encryptedPassword, false, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
    DefaultSpringSecurityContextSource source = serverConfigService.ldapContextSource(ldapConfig);
    assertThat(source.getAuthenticationSource().getCredentials(), is("encrypted_password"));
}
Also used : DefaultSpringSecurityContextSource(org.springframework.security.ldap.DefaultSpringSecurityContextSource) GoCipher(com.thoughtworks.go.security.GoCipher) StringContains.containsString(org.hamcrest.core.StringContains.containsString) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)149 Test (org.junit.Test)128 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)36 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)16 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HashMap (java.util.HashMap)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)10 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)10 Configuration (com.thoughtworks.go.domain.config.Configuration)9 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)8 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)7 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)7 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)7 Map (java.util.Map)7 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)6 File (java.io.File)6