use of org.apache.airavata.credential.store.credential.CommunityUser in project airavata by apache.
the class CommunityUserDAOTest method testAddCommunityUser.
@Test
public void testAddCommunityUser() throws Exception {
Connection connection = getConnection();
try {
CommunityUser communityUser = new CommunityUser("gw1", "ogce", "ogce@sciencegateway.org");
communityUserDAO.addCommunityUser(communityUser, "Token1", connection);
communityUser = new CommunityUser("gw1", "ogce2", "ogce@sciencegateway.org");
communityUserDAO.addCommunityUser(communityUser, "Token2", connection);
CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce", connection);
Assert.assertNotNull(user);
Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
user = communityUserDAO.getCommunityUser("gw1", "ogce2", connection);
Assert.assertNotNull(user);
Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
user = communityUserDAO.getCommunityUserByToken("gw1", "Token1", connection);
Assert.assertNotNull(user);
Assert.assertEquals("ogce", user.getUserName());
Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
user = communityUserDAO.getCommunityUserByToken("gw1", "Token2", connection);
Assert.assertNotNull(user);
Assert.assertEquals("ogce2", user.getUserName());
Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
} finally {
connection.close();
}
}
use of org.apache.airavata.credential.store.credential.CommunityUser 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.CommunityUser in project airavata by apache.
the class CredentialStoreServerHandler method getCertificateCredential.
@Override
public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
try {
Credential credential = credentialReader.getCredential(gatewayId, tokenId);
if (credential instanceof org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) {
org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential1 = (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) credential;
CertificateCredential certificateCredential = new CertificateCredential();
org.apache.airavata.model.credential.store.CommunityUser communityUser = new org.apache.airavata.model.credential.store.CommunityUser();
communityUser.setGatewayName(credential1.getCommunityUser().getGatewayName());
communityUser.setUsername(credential1.getCommunityUser().getUserName());
communityUser.setUserEmail(credential1.getCommunityUser().getUserEmail());
certificateCredential.setCommunityUser(communityUser);
certificateCredential.setToken(credential1.getToken());
certificateCredential.setLifeTime(credential1.getLifeTime());
certificateCredential.setNotAfter(credential1.getNotAfter());
certificateCredential.setNotBefore(credential1.getNotBefore());
certificateCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
if (credential1.getPrivateKey() != null) {
certificateCredential.setPrivateKey(credential1.getPrivateKey().toString());
}
certificateCredential.setX509Cert(credential1.getCertificates()[0].toString());
return certificateCredential;
} else {
log.info("Could not find Certificate credentials for token - " + tokenId + " and " + "gateway id - " + gatewayId);
return null;
}
} catch (CredentialStoreException e) {
log.error("Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId, e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId);
}
}
use of org.apache.airavata.credential.store.credential.CommunityUser in project airavata by apache.
the class CommunityUserDAO method getCommunityUserByToken.
public CommunityUser getCommunityUserByToken(String gatewayName, String tokenId, Connection connection) throws CredentialStoreException {
String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND TOKEN_ID=?";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, gatewayName);
preparedStatement.setString(2, tokenId);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
String communityUserName = resultSet.getString("COMMUNITY_USER_NAME");
// TODO fix typo
String email = resultSet.getString("COMMUNITY_USER_EMAIL");
return new CommunityUser(gatewayName, communityUserName, email);
}
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error retrieving community user.");
stringBuilder.append("gateway - ").append(gatewayName);
stringBuilder.append("token- ").append(tokenId);
log.error(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement);
}
return null;
}
use of org.apache.airavata.credential.store.credential.CommunityUser in project airavata by apache.
the class CommunityUserDAO method getCommunityUsers.
public List<CommunityUser> getCommunityUsers(String gatewayName, Connection connection) throws CredentialStoreException {
List<CommunityUser> userList = new ArrayList<CommunityUser>();
String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=?";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, gatewayName);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String userName = resultSet.getString("COMMUNITY_USER_NAME");
// TODO fix typo
String email = resultSet.getString("COMMUNITY_USER_EMAIL");
userList.add(new CommunityUser(gatewayName, userName, email));
}
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error retrieving community users for ");
stringBuilder.append("gateway - ").append(gatewayName);
log.error(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement);
}
return userList;
}
Aggregations