Search in sources :

Example 86 with GoCipher

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

the class PasswordDeserializerTest method shouldReturnTheEncryptedPasswordSentByUserIfValid.

@Test
public void shouldReturnTheEncryptedPasswordSentByUserIfValid() throws InvalidCipherTextException {
    String encryptedPassword = new GoCipher().encrypt("password");
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig();
    PasswordDeserializer passwordDeserializer = new PasswordDeserializer();
    String encrypted = passwordDeserializer.deserialize(null, encryptedPassword, svnMaterialConfig);
    assertThat(encrypted, is(encryptedPassword));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.Test)

Example 87 with GoCipher

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

the class MagicalGoConfigXmlLoader method fromXmlPartial.

public <T> T fromXmlPartial(InputStream inputStream, Class<T> o) throws Exception {
    Document document = new SAXBuilder().build(inputStream);
    Element element = document.getRootElement();
    return classParser(element, o, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) GoCipher(com.thoughtworks.go.security.GoCipher) Element(org.jdom2.Element) ConfigReferenceElements(com.thoughtworks.go.config.parser.ConfigReferenceElements) Document(org.jdom2.Document) XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument)

Example 88 with GoCipher

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

the class GoConfigClassLoader method parseCollection.

@SuppressWarnings("unchecked")
private void parseCollection(Collection collection) {
    ConfigCollection collectionAnnotation = annotationFor(aClass, ConfigCollection.class);
    Class<?> elementType = collectionAnnotation.value();
    for (Element childElement : (List<Element>) e.getChildren()) {
        if (isInCollection(childElement, elementType)) {
            Class<?> collectionType = findConcreteType(childElement, elementType);
            collection.add(classParser(childElement, collectionType, configCache, new GoCipher(), registry, configReferenceElements).parse());
        }
    }
    int minimumSize = collectionAnnotation.minimum();
    bombIf(collection.size() < minimumSize, "Required at least " + minimumSize + " subelements to '" + e.getName() + "'. " + "Found " + collection.size() + ".");
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Element(org.jdom2.Element) ConfigCollection(com.thoughtworks.go.config.ConfigCollection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 89 with GoCipher

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

the class GoConfigSubtagLoader method parse.

public Object parse() {
    Class<?> type = findTypeOfField();
    if (type == null) {
        return null;
    }
    ConfigTag tag = GoConfigClassLoader.configTag(type, configCache);
    if (configUtil.optionalAndMissingTag(e, tag, findSubTag(field).optional())) {
        return null;
    }
    return GoConfigClassLoader.classParser(configUtil.getChild(e, tag), type, configCache, new GoCipher(), registry, configReferenceElements).parse();
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigTag(com.thoughtworks.go.config.ConfigTag)

Example 90 with GoCipher

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

the class EnvironmentVariableConfig method deserialize.

public void deserialize(String name, String value, boolean isSecure, String encryptedValue) throws InvalidCipherTextException {
    setName(name);
    setIsSecure(isSecure);
    if (!isSecure && encryptedValue != null) {
        errors().add(ENCRYPTEDVALUE, "You may specify encrypted value only when option 'secure' is true.");
    }
    if (value != null && encryptedValue != null) {
        addError("value", "You may only specify `value` or `encrypted_value`, not both!");
        addError(ENCRYPTEDVALUE, "You may only specify `value` or `encrypted_value`, not both!");
    }
    if (encryptedValue != null) {
        setEncryptedValue(new EncryptedVariableValueConfig(encryptedValue));
    }
    if (isSecure) {
        if (value != null) {
            setEncryptedValue(new EncryptedVariableValueConfig(new GoCipher().encrypt(value)));
        }
    } else {
        setValue(new VariableValueConfig(value));
    }
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher)

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