Search in sources :

Example 6 with CertificateCredential

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

the class CredentialsDAOTest method testGetCredentials.

@Test
public void testGetCredentials() throws Exception {
    addTestCredentials();
    Connection connection = getConnection();
    try {
        CertificateCredential certificateCredential = (CertificateCredential) credentialsDAO.getCredential("gw1", "tom", connection);
        Assert.assertEquals("CN=Airavata Project, OU=IU, O=Indiana University, L=Bloomington, ST=IN, C=US", certificateCredential.getCertificates()[0].getIssuerDN().toString());
    // Assert.assertNotNull(certificateCredential.getPrivateKey());
    } finally {
        connection.close();
    }
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Connection(java.sql.Connection) Test(org.junit.Test)

Example 7 with CertificateCredential

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

the class CredentialsDAOTest method testSerialization.

@Test
public void testSerialization() throws CredentialStoreException {
    CertificateCredential certificateCredential = getTestCredentialObject();
    CredentialsDAO credentialsDAO1 = new CredentialsDAO();
    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) Test(org.junit.Test)

Example 8 with CertificateCredential

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

the class NotifierBootstrap method run.

@Override
public void run() {
    if (!enabled)
        return;
    // retrieve OA4MP credentials
    try {
        CredentialReader credentialReader = new CredentialReaderImpl(this.dbUtil);
        List<Credential> credentials = credentialReader.getAllCredentials();
        for (Credential credential : credentials) {
            if (credential instanceof CertificateCredential) {
                CertificateCredential certificateCredential = (CertificateCredential) credential;
                Date date = Utility.convertStringToDate(certificateCredential.getNotAfter());
                // gap is 1 days
                date.setDate(date.getDate() + 1);
                Date currentDate = new Date();
                if (currentDate.after(date)) {
                    // Send an email
                    CommunityUser communityUser = certificateCredential.getCommunityUser();
                    String body = String.format(MESSAGE, communityUser.getUserName(), certificateCredential.getNotAfter());
                    String subject = String.format(SUBJECT, communityUser.getUserName());
                    NotificationMessage notificationMessage = new EmailNotificationMessage(subject, communityUser.getUserEmail(), body);
                    this.credentialStoreNotifier.notifyMessage(notificationMessage);
                }
            }
        }
    } catch (ApplicationSettingsException e) {
        log.error("Error configuring email senders.", e);
    } catch (CredentialStoreException e) {
        log.error("Error sending emails about credential expiring.", e);
    } catch (ParseException e) {
        log.error("Error parsing date time when sending emails", e);
    }
}
Also used : EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CredentialReaderImpl(org.apache.airavata.credential.store.store.impl.CredentialReaderImpl) EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ParseException(java.text.ParseException)

Example 9 with CertificateCredential

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

the class CertificateCredentialWriter method writeCredentials.

public void writeCredentials(Credential credential) throws CredentialStoreException {
    CertificateCredential certificateCredential = (CertificateCredential) credential;
    Connection connection = null;
    try {
        connection = dbUtil.getConnection();
        // Write community user
        writeCommunityUser(certificateCredential.getCommunityUser(), credential.getToken(), connection);
        // First delete existing credentials
        credentialsDAO.deleteCredentials(certificateCredential.getCommunityUser().getGatewayName(), certificateCredential.getToken(), connection);
        // Add the new certificate
        credentialsDAO.addCredentials(certificateCredential.getCommunityUser().getGatewayName(), credential, connection);
        if (!connection.getAutoCommit()) {
            connection.commit();
        }
    } catch (SQLException e) {
        if (connection != null) {
            try {
                connection.rollback();
            } catch (SQLException e1) {
                log.error("Unable to rollback transaction", e1);
            }
        }
        throw new CredentialStoreException("Unable to retrieve database connection.", e);
    } finally {
        DBUtil.cleanup(connection);
    }
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 10 with CertificateCredential

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

the class X509SecurityContext method getCredentialsFromStore.

/**
 * Reads the credentials from credential store.
 * @return If token is found in the credential store, will return a valid credential. Else returns null.
 * @throws Exception If an error occurred while retrieving credentials.
 */
public X509Credential getCredentialsFromStore() throws Exception {
    if (getCredentialReader() == null) {
        return null;
    }
    Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(), getRequestData().getTokenId());
    if (credential != null) {
        if (credential instanceof CertificateCredential) {
            log.info("Successfully found credentials for token id - " + getRequestData().getTokenId() + " gateway id - " + getRequestData().getGatewayId());
            CertificateCredential certificateCredential = (CertificateCredential) credential;
            X509Certificate[] certificates = certificateCredential.getCertificates();
            KeyAndCertCredential keyAndCert = new KeyAndCertCredential(certificateCredential.getPrivateKey(), certificates);
            return keyAndCert;
        // return new GlobusGSSCredentialImpl(newCredential,
        // GSSCredential.INITIATE_AND_ACCEPT);
        } else {
            log.info("Credential type is not CertificateCredential. Cannot create mapping globus credentials. " + "Credential type - " + credential.getClass().getName());
        }
    } else {
        log.info("Could not find credentials for token - " + getRequestData().getTokenId() + " and " + "gateway id - " + getRequestData().getGatewayId());
    }
    return null;
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) X509Credential(eu.emi.security.authn.x509.X509Credential) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) X509Certificate(java.security.cert.X509Certificate)

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