-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-24023 Added test for SonarqubeRelyingPartyRegistrationRepositor…
…y + refactoring
- Loading branch information
1 parent
c72279c
commit 8cbbdde
Showing
16 changed files
with
348 additions
and
1,022 deletions.
There are no files selected for viewing
409 changes: 0 additions & 409 deletions
409
server/sonar-auth-saml/src/main/java/org/sonar/auth/saml/JakartaToJavaxRequestWrapper.java
This file was deleted.
Oops, something went wrong.
226 changes: 0 additions & 226 deletions
226
server/sonar-auth-saml/src/main/java/org/sonar/auth/saml/JakartaToJavaxResponseWrapper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
server/sonar-auth-saml/src/main/java/org/sonar/auth/saml/SamlCertificateConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.sonar.auth.saml; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.CertificateFactory; | ||
import java.security.cert.X509Certificate; | ||
import java.util.Base64; | ||
import org.sonar.api.server.ServerSide; | ||
|
||
@ServerSide | ||
class SamlCertificateConverter { | ||
|
||
X509Certificate toX509Certificate(String certificateString) { | ||
String cleanedCertificateString = sanitizeCertificateString(certificateString); | ||
|
||
byte[] decoded = Base64.getDecoder().decode(cleanedCertificateString); | ||
try { | ||
CertificateFactory factory = CertificateFactory.getInstance("X.509"); | ||
return (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(decoded)); | ||
} catch (CertificateException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String sanitizeCertificateString(String certificateString) { | ||
return certificateString | ||
.replace("-----BEGIN CERTIFICATE-----", "") | ||
.replace("-----END CERTIFICATE-----", "") | ||
.replaceAll("\\s+", ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
server/sonar-auth-saml/src/main/java/org/sonar/auth/saml/SamlPrivateKeyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.sonar.auth.saml; | ||
|
||
import java.security.KeyFactory; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.PrivateKey; | ||
import java.security.spec.InvalidKeySpecException; | ||
import java.security.spec.PKCS8EncodedKeySpec; | ||
import java.util.Base64; | ||
import org.sonar.api.server.ServerSide; | ||
|
||
@ServerSide | ||
class SamlPrivateKeyConverter { | ||
PrivateKey toPrivateKey(String privateKeyString) { | ||
String cleanedPrivateKeyString = sanitizePrivateKeyString(privateKeyString); | ||
|
||
byte[] decoded = Base64.getDecoder().decode(cleanedPrivateKeyString); | ||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decoded); | ||
try { | ||
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); | ||
return keyFactory.generatePrivate(keySpec); | ||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String sanitizePrivateKeyString(String privateKeyString) { | ||
return privateKeyString | ||
.replace("-----BEGIN PRIVATE KEY-----", "") | ||
.replace("-----END PRIVATE KEY-----", "") | ||
.replaceAll("\\s+", ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.