Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar lint fixes #682

Merged
merged 15 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import com.google.common.net.InetAddresses
import com.google.common.net.InternetDomainName
import org.apache.commons.lang3.StringUtils.isEmpty
import org.cloudfoundry.credhub.ErrorMessages
import org.cloudfoundry.credhub.exceptions.InvalidAlternateNameCertificateException
import org.cloudfoundry.credhub.exceptions.InvalidDurationCertificateException
import org.cloudfoundry.credhub.exceptions.InvalidKeyLengthCertificateException
import org.cloudfoundry.credhub.exceptions.MissingSigningCACertificateException
import org.cloudfoundry.credhub.exceptions.NoSubjectCertificateException
import org.cloudfoundry.credhub.exceptions.ParameterizedValidationException
import org.cloudfoundry.credhub.exceptions.SelfSignedCACertificateException
import java.util.Arrays
import java.util.regex.Pattern

Expand Down Expand Up @@ -83,25 +89,25 @@ class CertificateGenerationRequestParameters {
isEmpty(commonName) &&
isEmpty(country)
) {
throw ParameterizedValidationException(ErrorMessages.MISSING_CERTIFICATE_PARAMETERS)
throw NoSubjectCertificateException()
}

if (isEmpty(caName) && !selfSigned && !isCa) {
hsinn0 marked this conversation as resolved.
Show resolved Hide resolved
throw ParameterizedValidationException(ErrorMessages.MISSING_SIGNING_CA)
throw MissingSigningCACertificateException()
}

if (!isEmpty(caName) && selfSigned) {
throw ParameterizedValidationException(ErrorMessages.CA_AND_SELF_SIGN)
throw SelfSignedCACertificateException()
}

if (!validKeyLengths.contains(keyLength)) {
throw ParameterizedValidationException(ErrorMessages.INVALID_KEY_LENGTH)
throw InvalidKeyLengthCertificateException()
}

if (alternativeNames != null) {
for (name in alternativeNames!!) {
if (!InetAddresses.isInetAddress(name) && !(InternetDomainName.isValid(name) || DNS_WILDCARD_PATTERN.matcher(name).matches())) {
throw ParameterizedValidationException(ErrorMessages.INVALID_ALTERNATE_NAME)
throw InvalidAlternateNameCertificateException()
}
}
}
Expand Down Expand Up @@ -129,7 +135,7 @@ class CertificateGenerationRequestParameters {
}

if (duration < ONE_DAY || duration > TEN_YEARS) {
throw ParameterizedValidationException(ErrorMessages.INVALID_DURATION)
throw InvalidDurationCertificateException()
}

validateParameterLength(commonName, "common name", 64)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.cloudfoundry.credhub.exceptions

import org.cloudfoundry.credhub.ErrorMessages

class InvalidAlternateNameCertificateException @JvmOverloads
constructor(messageCode: String = ErrorMessages.INVALID_ALTERNATE_NAME, parameters: Array<Any> = arrayOf())
hsinn0 marked this conversation as resolved.
Show resolved Hide resolved
: ParameterizedValidationException(messageCode) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.cloudfoundry.credhub.exceptions

import org.cloudfoundry.credhub.ErrorMessages

open class InvalidDurationCertificateException @JvmOverloads constructor(messageCode: String = ErrorMessages.INVALID_DURATION, parameters: Array<Any> = arrayOf())
: ParameterizedValidationException(messageCode)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.cloudfoundry.credhub.exceptions

import org.cloudfoundry.credhub.ErrorMessages

class InvalidKeyLengthCertificateException @JvmOverloads
constructor(messageCode: String = ErrorMessages.INVALID_KEY_LENGTH, parameters: Array<Any> = arrayOf())
: ParameterizedValidationException(messageCode) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.cloudfoundry.credhub.exceptions

import org.cloudfoundry.credhub.ErrorMessages

class MissingSigningCACertificateException @JvmOverloads
constructor(messageCode: String = ErrorMessages.MISSING_SIGNING_CA, parameters: Array<Any> = arrayOf())
: ParameterizedValidationException(messageCode) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.cloudfoundry.credhub.exceptions

import org.cloudfoundry.credhub.ErrorMessages

class NoSubjectCertificateException @JvmOverloads
constructor(messageCode: String = ErrorMessages.MISSING_CERTIFICATE_PARAMETERS, parameters: Array<Any> = arrayOf())
: ParameterizedValidationException(messageCode) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.common.collect.Lists
import java.util.stream.Collectors
import javax.validation.ValidationException

class ParameterizedValidationException @JvmOverloads constructor(messageCode: String, parameters: Array<Any> = arrayOf()) : ValidationException(messageCode) {
open class ParameterizedValidationException @JvmOverloads constructor(messageCode: String, parameters: Array<Any> = arrayOf()) : ValidationException(messageCode) {

private val parameters: List<Any>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.cloudfoundry.credhub.exceptions

import org.cloudfoundry.credhub.ErrorMessages

class SelfSignedCACertificateException @JvmOverloads
constructor(messageCode: String = ErrorMessages.CA_AND_SELF_SIGN, parameters: Array<Any> = arrayOf())
: ParameterizedValidationException(messageCode) {
}