use of org.apache.airavata.credential.store.store.CredentialStoreException 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.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method getAllSSHKeysForGateway.
@Override
public Map<String, String> getAllSSHKeysForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
Map<String, String> sshKeyMap = new HashMap<>();
try {
List<Credential> allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId);
if (allCredentials != null && !allCredentials.isEmpty()) {
for (Credential credential : allCredentials) {
if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) {
org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
byte[] publicKey = sshCredential.getPublicKey();
if (publicKey != null && sshCredential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) {
sshKeyMap.put(sshCredential.getToken(), new String(publicKey));
}
}
}
}
} catch (CredentialStoreException e) {
log.error("Error occurred while retrieving credentials", e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credentials");
}
return sshKeyMap;
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method getSSHCredential.
@Override
public SSHCredential getSSHCredential(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.ssh.SSHCredential) {
org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
SSHCredential sshCredential = new SSHCredential();
sshCredential.setUsername(credential1.getPortalUserName());
sshCredential.setGatewayId(credential1.getGateway());
sshCredential.setPublicKey(new String(credential1.getPublicKey()));
sshCredential.setPrivateKey(new String(credential1.getPrivateKey()));
sshCredential.setPassphrase(credential1.getPassphrase());
sshCredential.setToken(credential1.getToken());
sshCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
sshCredential.setDescription(credential1.getDescription());
sshCredential.setCredentialOwnerType(credential1.getCredentialOwnerType().getDatamodelType());
return sshCredential;
} else {
log.info("Could not find SSH credentials for token - " + tokenId + " and " + "gateway id - " + gatewayId);
return null;
}
} catch (CredentialStoreException e) {
log.error("Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving SSH credential for token - " + tokenId + " and gateway id - " + gatewayId);
}
}
use of org.apache.airavata.credential.store.store.CredentialStoreException 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.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method getPasswordCredential.
@Override
public PasswordCredential getPasswordCredential(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.password.PasswordCredential) {
org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential1 = (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential;
PasswordCredential pwdCredential = new PasswordCredential();
pwdCredential.setGatewayId(credential1.getGateway());
pwdCredential.setPortalUserName(credential1.getPortalUserName());
pwdCredential.setLoginUserName(credential1.getUserName());
pwdCredential.setPassword(credential1.getPassword());
pwdCredential.setDescription(credential1.getDescription());
pwdCredential.setToken(credential1.getToken());
pwdCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
return pwdCredential;
} else {
log.info("Could not find PWD credentials for token - " + tokenId + " and " + "gateway id - " + gatewayId);
return null;
}
} catch (CredentialStoreException e) {
log.error("Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving PWD credential for token - " + tokenId + " and gateway id - " + gatewayId);
}
}
Aggregations