Search in sources :

Example 1 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class PasswordCredentialVersion method rotate.

public void rotate() {
    String decryptedPassword = this.getPassword();
    StringGenerationParameters decryptedGenerationParameters = this.getGenerationParameters();
    this.setPasswordAndGenerationParameters(decryptedPassword, decryptedGenerationParameters);
}
Also used : StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters)

Example 2 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class PasswordCredentialVersion method getGenerationParameters.

public StringGenerationParameters getGenerationParameters() {
    String password = getPassword();
    Assert.notNull(password, "Password length generation parameter cannot be restored without an existing password");
    if (delegate.getEncryptedGenerationParameters() == null) {
        return null;
    }
    String parameterJson = encryptor.decrypt(delegate.getEncryptedGenerationParameters());
    if (parameterJson == null) {
        return null;
    }
    try {
        StringGenerationParameters passwordGenerationParameters = jsonObjectMapper.deserializeBackwardsCompatibleValue(parameterJson, StringGenerationParameters.class);
        passwordGenerationParameters.setLength(password.length());
        return passwordGenerationParameters;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters)

Example 3 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class UserCredentialVersion method getGenerationParameters.

public StringGenerationParameters getGenerationParameters() {
    String parameterJson = encryptor.decrypt(delegate.getEncryptedGenerationParameters());
    String password = this.password == null ? getPassword() : this.password;
    if (parameterJson == null) {
        return null;
    }
    try {
        StringGenerationParameters generationParameters = jsonObjectMapper.deserializeBackwardsCompatibleValue(parameterJson, StringGenerationParameters.class);
        generationParameters.setLength(password.length());
        return generationParameters;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters)

Example 4 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class UserCredentialVersion method matchesGenerationParameters.

@Override
public boolean matchesGenerationParameters(GenerationParameters generationParameters) {
    final StringGenerationParameters existingGenerationParameters = getGenerationParameters();
    final StringGenerationParameters newGenerationParameters = (StringGenerationParameters) generationParameters;
    final boolean lengthsMatch = newGenerationParameters.getLength() == existingGenerationParameters.getLength();
    final boolean usernamesMatch = getUsername().equals(newGenerationParameters.getUsername()) || existingGenerationParameters.getUsername() == newGenerationParameters.getUsername();
    final boolean passwordGenerationParamsMatch = existingGenerationParameters.passwordOptionsEqual(newGenerationParameters);
    return lengthsMatch && usernamesMatch && passwordGenerationParamsMatch;
}
Also used : StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters)

Example 5 with StringGenerationParameters

use of org.cloudfoundry.credhub.request.StringGenerationParameters in project credhub by cloudfoundry-incubator.

the class UserCredentialVersion method rotate.

@Override
public void rotate() {
    String decryptedPassword = getPassword();
    StringGenerationParameters decryptedGenerationParameters = getGenerationParameters();
    setPassword(decryptedPassword);
    setGenerationParameters(decryptedGenerationParameters);
}
Also used : StringGenerationParameters(org.cloudfoundry.credhub.request.StringGenerationParameters)

Aggregations

StringGenerationParameters (org.cloudfoundry.credhub.request.StringGenerationParameters)40 Test (org.junit.Test)24 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)8 CharacterRule (org.passay.CharacterRule)7 StringCredentialValue (org.cloudfoundry.credhub.credential.StringCredentialValue)6 EncryptedValue (org.cloudfoundry.credhub.entity.EncryptedValue)5 PasswordCredentialVersionData (org.cloudfoundry.credhub.entity.PasswordCredentialVersionData)5 Before (org.junit.Before)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 UserCredentialVersion (org.cloudfoundry.credhub.domain.UserCredentialVersion)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)2 UserContext (org.cloudfoundry.credhub.auth.UserContext)2 UserCredentialVersionData (org.cloudfoundry.credhub.entity.UserCredentialVersionData)2 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)2 PermissionService (org.cloudfoundry.credhub.service.PermissionService)2 PermissionedCredentialService (org.cloudfoundry.credhub.service.PermissionedCredentialService)2