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();
}
}
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()));
}
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);
}
}
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);
}
}
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;
}
Aggregations