@Parameters
public static Collection<Object[]> getTestParameters() throws Exception
{
final Collection<Object[]> params = new ArrayList<Object[]>();
X509CredentialsAuthenticationHandler handler;
// Test case #1
// Unsupported credentials type
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
params.add(new Object[] {
handler,
new UsernamePasswordCredentials(),
false,
false,
});
// Test case #2
// Valid certificate
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-valid.crt")),
true,
true,
});
// Test case #3
// Expired certificate
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-expired.crt")),
true,
false,
});
// Test case #4
// Untrusted issuer
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern("CN=\\w+,OU=CAS,O=Jasig,L=Westminster,ST=Colorado,C=US");
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("snake-oil.crt")),
true,
false,
});
// Test case #5
// Disallowed subject
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
handler.setSubjectDnPattern("CN=\\w+,OU=CAS,O=Jasig,L=Westminster,ST=Colorado,C=US");
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("snake-oil.crt")),
true,
false,
});
// Test case #6
// Check key usage on a cert without keyUsage extension
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
handler.setCheckKeyUsage(true);
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-valid.crt")),
true,
true,
});
// Test case #7
// Require key usage on a cert without keyUsage extension
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
handler.setCheckKeyUsage(true);
handler.setRequireKeyUsage(true);
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-valid.crt")),
true,
false,
});
// Test case #8
// Require key usage on a cert with acceptable keyUsage extension values
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
handler.setCheckKeyUsage(true);
handler.setRequireKeyUsage(true);
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-valid-keyUsage.crt")),
true,
true,
});
// Test case #9
// Require key usage on a cert with unacceptable keyUsage extension values
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
handler.setCheckKeyUsage(true);
handler.setRequireKeyUsage(true);
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-invalid-keyUsage.crt")),
true,
false,
});
//===================================
// Revocation tests
//===================================
ResourceCRLRevocationChecker checker;
// Test case #10
// Valid certificate with CRL checking
handler = new X509CredentialsAuthenticationHandler();
checker = new ResourceCRLRevocationChecker(new ClassPathResource("userCA-valid.crl"));
checker.afterPropertiesSet();
handler.setRevocationChecker(checker);
handler.setTrustedIssuerDnPattern(".*");
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-valid.crt")),
true,
true,
});
// Test case #11
// Revoked end user certificate
handler = new X509CredentialsAuthenticationHandler();
checker = new ResourceCRLRevocationChecker(new ClassPathResource("userCA-valid.crl"));
checker.afterPropertiesSet();
handler.setRevocationChecker(checker);
handler.setTrustedIssuerDnPattern(".*");
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-revoked.crt")),
true,
false,
});
// Test case #12
// Valid certificate on expired CRL data
final ThresholdExpiredCRLRevocationPolicy zeroThresholdPolicy = new ThresholdExpiredCRLRevocationPolicy();
zeroThresholdPolicy.setThreshold(0);
handler = new X509CredentialsAuthenticationHandler();
handler.setTrustedIssuerDnPattern(".*");
checker = new ResourceCRLRevocationChecker(new ClassPathResource("userCA-expired.crl"));
checker.setExpiredCRLPolicy(zeroThresholdPolicy);
checker.afterPropertiesSet();
handler.setRevocationChecker(checker);
params.add(new Object[] {
handler,
new X509CertificateCredentials(createCertificates("user-valid.crt")),
true,
false,