Search in sources :

Example 1 with TPPPolicy

use of com.venafi.vcert.sdk.policy.api.domain.TPPPolicy in project vcert-java by Venafi.

the class TppPolicyToPolicyConverter method convertToPolicy.

public PolicySpecification convertToPolicy(TPPPolicy tppPolicy) throws Exception {
    PolicySpecification policySpecification = new PolicySpecification();
    policySpecification.name(tppPolicy.policyName());
    policySpecification.users(tppPolicy.contact() != null && tppPolicy.contact().length > 0 ? tppPolicy.contact() : null);
    policySpecification.approvers(tppPolicy.approver() != null && tppPolicy.approver().length > 0 ? tppPolicy.approver() : null);
    if (tppPolicy.domainSuffixWhiteList() != null && tppPolicy.domainSuffixWhiteList().length > 0)
        getPolicyFromPolicySpecification(policySpecification).domains(tppPolicy.domainSuffixWhiteList());
    if (tppPolicy.prohibitWildcard() != null)
        getPolicyFromPolicySpecification(policySpecification).wildcardAllowed(!(tppPolicy.prohibitWildcard() == 1));
    if (tppPolicy.certificateAuthority() != null && !tppPolicy.certificateAuthority().equals(""))
        getPolicyFromPolicySpecification(policySpecification).certificateAuthority(tppPolicy.certificateAuthority());
    // resolving management type
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::managementType)) {
        case NORMAL:
            getPolicyFromPolicySpecification(policySpecification).autoInstalled(ManagementTypes.from(tppPolicy.managementType().values()[0]).psValue);
            break;
    }
    // resolving org/orgs
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::organization)) {
        case NORMAL:
            getSubjectFromPolicySpecification(policySpecification).orgs(tppPolicy.organization().values());
            break;
        case DEFAULT:
            getDefaultsSubjectFromPolicySpecification(policySpecification).org(tppPolicy.organization().values()[0]);
    }
    // resolving orgUnits
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::organizationalUnit)) {
        case NORMAL:
            getSubjectFromPolicySpecification(policySpecification).orgUnits(tppPolicy.organizationalUnit().values());
            break;
        case DEFAULT:
            getDefaultsSubjectFromPolicySpecification(policySpecification).orgUnits(tppPolicy.organizationalUnit().values());
    }
    // resolving localities/locality
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::city)) {
        case NORMAL:
            getSubjectFromPolicySpecification(policySpecification).localities(tppPolicy.city().values());
            break;
        case DEFAULT:
            getDefaultsSubjectFromPolicySpecification(policySpecification).locality(tppPolicy.city().values()[0]);
    }
    // resolving state/states
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::state)) {
        case NORMAL:
            getSubjectFromPolicySpecification(policySpecification).states(tppPolicy.state().values());
            break;
        case DEFAULT:
            getDefaultsSubjectFromPolicySpecification(policySpecification).state(tppPolicy.state().values()[0]);
    }
    // resolving country/countries
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::country)) {
        case NORMAL:
            getSubjectFromPolicySpecification(policySpecification).countries(tppPolicy.country().values());
            break;
        case DEFAULT:
            getDefaultsSubjectFromPolicySpecification(policySpecification).country(tppPolicy.country().values()[0]);
    }
    // resolve keyTypes
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::keyAlgorithm)) {
        case NORMAL:
            getKeyPairFromPolicySpecification(policySpecification).keyTypes(tppPolicy.keyAlgorithm().values());
            break;
        case DEFAULT:
            getDefaultsKeyPairFromPolicySpecification(policySpecification).keyType(tppPolicy.keyAlgorithm().values()[0]);
    }
    // resolve rsaKeySizes
    Integer[] keyBitStrength;
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::keyBitStrength)) {
        case NORMAL:
            keyBitStrength = Stream.of(tppPolicy.keyBitStrength().values()).mapToInt(Integer::parseInt).boxed().toArray(Integer[]::new);
            getKeyPairFromPolicySpecification(policySpecification).rsaKeySizes(keyBitStrength);
            break;
        case DEFAULT:
            keyBitStrength = Stream.of(tppPolicy.keyBitStrength().values()).mapToInt(Integer::parseInt).boxed().toArray(Integer[]::new);
            getDefaultsKeyPairFromPolicySpecification(policySpecification).rsaKeySize(keyBitStrength[0]);
    }
    // resolve ellipticCurves
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::ellipticCurve)) {
        case NORMAL:
            getKeyPairFromPolicySpecification(policySpecification).ellipticCurves(tppPolicy.ellipticCurve().values());
            break;
        case DEFAULT:
            getDefaultsKeyPairFromPolicySpecification(policySpecification).ellipticCurve(tppPolicy.ellipticCurve().values()[0]);
    }
    // resolve serviceGenerated
    switch(shouldCreateAttribute(tppPolicy, TPPPolicy::manualCsr)) {
        case NORMAL:
            getKeyPairFromPolicySpecification(policySpecification).serviceGenerated(tppPolicy.manualCsr().values()[0].equals("0"));
            break;
        case DEFAULT:
            getDefaultsKeyPairFromPolicySpecification(policySpecification).serviceGenerated(tppPolicy.manualCsr().values()[0].equals("0"));
    }
    // so if one of these two values is set then apply the value to  ReuseAllowed
    if (shouldCreateAttribute(tppPolicy, TPPPolicy::allowPrivateKeyReuse) == TypePSAToCreate.NORMAL)
        getKeyPairFromPolicySpecification(policySpecification).reuseAllowed(tppPolicy.allowPrivateKeyReuse().values()[0].equals("1"));
    else if (shouldCreateAttribute(tppPolicy, TPPPolicy::wantRenewal) == TypePSAToCreate.NORMAL)
        getKeyPairFromPolicySpecification(policySpecification).reuseAllowed(tppPolicy.wantRenewal().values()[0].equals("1"));
    // resolve subjectAltNames
    resolveSubjectAltNames(tppPolicy, policySpecification);
    return policySpecification;
}
Also used : TPPPolicy(com.venafi.vcert.sdk.policy.api.domain.TPPPolicy) PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification)

Example 2 with TPPPolicy

use of com.venafi.vcert.sdk.policy.api.domain.TPPPolicy in project vcert-java by Venafi.

the class PolicyToTppPolicyConverter method setManualCsr.

private void setManualCsr(TPPPolicy tppPolicy, PolicySpecification policySpecification) {
    Policy policy = policySpecification.policy();
    Defaults defaults = policySpecification.defaults();
    if (policy != null && policy.keyPair() != null && policy.keyPair().serviceGenerated() != null)
        tppPolicy.manualCsr(policy.keyPair().serviceGenerated() ? "0" : "1", true);
    else if (defaults != null && defaults.keyPair() != null && defaults.keyPair().serviceGenerated() != null)
        tppPolicy.manualCsr(defaults.keyPair().serviceGenerated() ? "0" : "1", false);
}
Also used : TPPPolicy(com.venafi.vcert.sdk.policy.api.domain.TPPPolicy)

Example 3 with TPPPolicy

use of com.venafi.vcert.sdk.policy.api.domain.TPPPolicy in project vcert-java by Venafi.

the class PolicyToTppPolicyConverter method setManagementType.

private void setManagementType(TPPPolicy tppPolicy, PolicySpecification policySpecification) {
    Policy policy = policySpecification.policy();
    Defaults defaults = policySpecification.defaults();
    if (policy != null && policy.autoInstalled() != null)
        tppPolicy.managementType(ManagementTypes.from(policy.autoInstalled()).value, true);
}
Also used : TPPPolicy(com.venafi.vcert.sdk.policy.api.domain.TPPPolicy)

Example 4 with TPPPolicy

use of com.venafi.vcert.sdk.policy.api.domain.TPPPolicy in project vcert-java by Venafi.

the class TppConnector method getPolicy.

@Override
public PolicySpecification getPolicy(String policyName) throws VCertException {
    PolicySpecification policySpecification;
    try {
        TPPPolicy tppPolicy = getTPPPolicy(policyName);
        policySpecification = TPPPolicySpecificationConverter.INSTANCE.convertToPolicySpecification(tppPolicy);
    } catch (Exception e) {
        throw new VCertException(e);
    }
    return policySpecification;
}
Also used : TPPPolicy(com.venafi.vcert.sdk.policy.api.domain.TPPPolicy) PolicySpecification(com.venafi.vcert.sdk.policy.domain.PolicySpecification) VCertException(com.venafi.vcert.sdk.VCertException) RetrieveCertificateTimeoutException(com.venafi.vcert.sdk.connectors.ConnectorException.RetrieveCertificateTimeoutException) TppRequestCertificateNotAllowedException(com.venafi.vcert.sdk.connectors.ConnectorException.TppRequestCertificateNotAllowedException) CertificateDNOrThumbprintWasNotProvidedException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException) RenewFailureException(com.venafi.vcert.sdk.connectors.ConnectorException.RenewFailureException) CertificateNotFoundByThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException) CSRNotProvidedByUserException(com.venafi.vcert.sdk.connectors.ConnectorException.CSRNotProvidedByUserException) MissingCredentialsException(com.venafi.vcert.sdk.connectors.ConnectorException.MissingCredentialsException) TppManualCSRNotEnabledException(com.venafi.vcert.sdk.connectors.ConnectorException.TppManualCSRNotEnabledException) CertificatePendingException(com.venafi.vcert.sdk.connectors.ConnectorException.CertificatePendingException) VCertException(com.venafi.vcert.sdk.VCertException) MoreThanOneCertificateWithSameThumbprintException(com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException) AttemptToRetryException(com.venafi.vcert.sdk.connectors.ConnectorException.AttemptToRetryException) RevokeFailureException(com.venafi.vcert.sdk.connectors.ConnectorException.RevokeFailureException) CouldNotParseRevokeReasonException(com.venafi.vcert.sdk.connectors.ConnectorException.CouldNotParseRevokeReasonException) TppPingException(com.venafi.vcert.sdk.connectors.ConnectorException.TppPingException)

Example 5 with TPPPolicy

use of com.venafi.vcert.sdk.policy.api.domain.TPPPolicy in project vcert-java by Venafi.

the class AbstractTppConnector method getTPPPolicy.

public TPPPolicy getTPPPolicy(String policyName) throws VCertException {
    TPPPolicy tppPolicy = new TPPPolicy();
    // ensuring that the policy name starts with the tpp_root_path
    if (!policyName.startsWith(TppPolicyConstants.TPP_ROOT_PATH))
        policyName = TppPolicyConstants.TPP_ROOT_PATH + policyName;
    tppPolicy.policyName(policyName);
    // populating the tppPolicy
    TppConnectorUtils.populatePolicy(tppPolicy, tppAPI);
    return tppPolicy;
}
Also used : TPPPolicy(com.venafi.vcert.sdk.policy.api.domain.TPPPolicy)

Aggregations

TPPPolicy (com.venafi.vcert.sdk.policy.api.domain.TPPPolicy)8 VCertException (com.venafi.vcert.sdk.VCertException)2 AttemptToRetryException (com.venafi.vcert.sdk.connectors.ConnectorException.AttemptToRetryException)2 CSRNotProvidedByUserException (com.venafi.vcert.sdk.connectors.ConnectorException.CSRNotProvidedByUserException)2 CertificateDNOrThumbprintWasNotProvidedException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateDNOrThumbprintWasNotProvidedException)2 CertificateNotFoundByThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificateNotFoundByThumbprintException)2 CertificatePendingException (com.venafi.vcert.sdk.connectors.ConnectorException.CertificatePendingException)2 CouldNotParseRevokeReasonException (com.venafi.vcert.sdk.connectors.ConnectorException.CouldNotParseRevokeReasonException)2 MissingCredentialsException (com.venafi.vcert.sdk.connectors.ConnectorException.MissingCredentialsException)2 MoreThanOneCertificateWithSameThumbprintException (com.venafi.vcert.sdk.connectors.ConnectorException.MoreThanOneCertificateWithSameThumbprintException)2 RenewFailureException (com.venafi.vcert.sdk.connectors.ConnectorException.RenewFailureException)2 RetrieveCertificateTimeoutException (com.venafi.vcert.sdk.connectors.ConnectorException.RetrieveCertificateTimeoutException)2 RevokeFailureException (com.venafi.vcert.sdk.connectors.ConnectorException.RevokeFailureException)2 TppManualCSRNotEnabledException (com.venafi.vcert.sdk.connectors.ConnectorException.TppManualCSRNotEnabledException)2 TppPingException (com.venafi.vcert.sdk.connectors.ConnectorException.TppPingException)2 TppRequestCertificateNotAllowedException (com.venafi.vcert.sdk.connectors.ConnectorException.TppRequestCertificateNotAllowedException)2 PolicySpecification (com.venafi.vcert.sdk.policy.domain.PolicySpecification)2