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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations