Search in sources :

Example 1 with CertificateCredential

use of org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential in project airavata by apache.

the class CredentialsDAOTest method testDeleteCredentials.

@Test
public void testDeleteCredentials() throws Exception {
    addTestCredentials();
    Connection connection = getConnection();
    try {
        CertificateCredential certificateCredential = (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection);
        Assert.assertNotNull(certificateCredential);
        credentialsDAO.deleteCredentials("gw1", "tom", connection);
        certificateCredential = (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection);
        Assert.assertNull(certificateCredential);
    } finally {
        connection.close();
    }
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Connection(java.sql.Connection) Test(org.junit.Test)

Example 2 with CertificateCredential

use of org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential in project airavata by apache.

the class CredentialsDAOTest method testAddCredentials.

@Test
public void testAddCredentials() throws Exception {
    addTestCredentials();
    Connection connection = getConnection();
    try {
        CertificateCredential certificateCredential = (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection);
        // Test get gateway name
        String gateway = credentialsDAO.getGatewayID("tom", connection);
        Assert.assertNotNull(certificateCredential);
        Assert.assertEquals("jerry", certificateCredential.getPortalUserName());
        Assert.assertEquals("gw1", gateway);
        checkEquality(x509Certificates, certificateCredential.getCertificates());
        Assert.assertEquals(privateKey.getFormat(), certificateCredential.getPrivateKey().getFormat());
    } finally {
        connection.close();
    }
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Connection(java.sql.Connection) Test(org.junit.Test)

Example 3 with CertificateCredential

use of org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential in project airavata by apache.

the class CredentialsDAOTest method addTestCredentials.

private void addTestCredentials() throws Exception {
    Connection connection = getConnection();
    try {
        CertificateCredential certificateCredential = getTestCredentialObject();
        credentialsDAO.addCredentials(certificateCredential.getCommunityUser().getGatewayName(), certificateCredential, connection);
    } finally {
        connection.close();
    }
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Connection(java.sql.Connection)

Example 4 with CertificateCredential

use of org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential in project airavata by apache.

the class CredentialsDAOTest method testSerializationWithEncryption.

@Test
public void testSerializationWithEncryption() throws CredentialStoreException {
    URL url = this.getClass().getClassLoader().getResource("mykeystore.jks");
    String secretKeyAlias = "mykey";
    assert url != null;
    CertificateCredential certificateCredential = getTestCredentialObject();
    CredentialsDAO credentialsDAO1 = new CredentialsDAO(url.getPath(), secretKeyAlias, new TestACSKeyStoreCallback());
    byte[] array = credentialsDAO1.convertObjectToByteArray(certificateCredential);
    CertificateCredential readCertificateCredential = (CertificateCredential) credentialsDAO1.convertByteArrayToObject(array);
    checkEquality(certificateCredential.getCertificates(), readCertificateCredential.getCertificates());
    Assert.assertEquals(certificateCredential.getCertificateRequestedTime(), readCertificateCredential.getCertificateRequestedTime());
    Assert.assertEquals(certificateCredential.getCommunityUser().getGatewayName(), readCertificateCredential.getCommunityUser().getGatewayName());
    Assert.assertEquals(certificateCredential.getCommunityUser().getUserEmail(), readCertificateCredential.getCommunityUser().getUserEmail());
    Assert.assertEquals(certificateCredential.getCommunityUser().getUserName(), readCertificateCredential.getCommunityUser().getUserName());
    Assert.assertEquals(certificateCredential.getLifeTime(), readCertificateCredential.getLifeTime());
    Assert.assertEquals(certificateCredential.getNotAfter(), readCertificateCredential.getNotAfter());
    Assert.assertEquals(certificateCredential.getNotBefore(), readCertificateCredential.getNotBefore());
    Assert.assertEquals(certificateCredential.getPortalUserName(), readCertificateCredential.getPortalUserName());
    Assert.assertEquals(certificateCredential.getCredentialOwnerType(), readCertificateCredential.getCredentialOwnerType());
    PrivateKey newKey = readCertificateCredential.getPrivateKey();
    Assert.assertNotNull(newKey);
    Assert.assertEquals(privateKey.getClass(), newKey.getClass());
    Assert.assertEquals(privateKey.getFormat(), newKey.getFormat());
    Assert.assertEquals(privateKey.getAlgorithm(), newKey.getAlgorithm());
    Assert.assertTrue(Arrays.equals(privateKey.getEncoded(), newKey.getEncoded()));
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) PrivateKey(java.security.PrivateKey) URL(java.net.URL) Test(org.junit.Test)

Example 5 with CertificateCredential

use of org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential in project airavata by apache.

the class CredentialsDAOTest method getTestCredentialObject.

public CertificateCredential getTestCredentialObject() {
    CertificateCredential certificateCredential = new CertificateCredential();
    certificateCredential.setToken("tom");
    certificateCredential.setCertificates(x509Certificates);
    certificateCredential.setPrivateKey(privateKey);
    certificateCredential.setCommunityUser(getCommunityUser("gw1", "tom"));
    certificateCredential.setLifeTime(1000);
    certificateCredential.setPortalUserName("jerry");
    certificateCredential.setNotBefore("13 OCT 2012 5:34:23");
    certificateCredential.setNotAfter("14 OCT 2012 5:34:23");
    certificateCredential.setCredentialOwnerType(CredentialOwnerType.GATEWAY);
    return certificateCredential;
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential)

Aggregations

CertificateCredential (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential)14 Connection (java.sql.Connection)7 Test (org.junit.Test)6 CommunityUser (org.apache.airavata.credential.store.credential.CommunityUser)4 PrivateKey (java.security.PrivateKey)3 X509Certificate (java.security.cert.X509Certificate)3 Credential (org.apache.airavata.credential.store.credential.Credential)3 X509Credential (eu.emi.security.authn.x509.X509Credential)2 KeyAndCertCredential (eu.emi.security.authn.x509.impl.KeyAndCertCredential)2 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)2 AssetResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse)1 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 URL (java.net.URL)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 CertificateAuditInfo (org.apache.airavata.credential.store.credential.impl.certificate.CertificateAuditInfo)1 EmailNotificationMessage (org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage)1 CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)1 CredentialReaderImpl (org.apache.airavata.credential.store.store.impl.CredentialReaderImpl)1