use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class EmailNotifier method notifyMessage.
public void notifyMessage(NotificationMessage message) throws CredentialStoreException {
try {
Email email = new SimpleEmail();
email.setHostName(this.emailNotifierConfiguration.getEmailServer());
email.setSmtpPort(this.emailNotifierConfiguration.getEmailServerPort());
email.setAuthenticator(new DefaultAuthenticator(this.emailNotifierConfiguration.getEmailUserName(), this.emailNotifierConfiguration.getEmailPassword()));
email.setSSLOnConnect(this.emailNotifierConfiguration.isSslConnect());
email.setFrom(this.emailNotifierConfiguration.getFromAddress());
EmailNotificationMessage emailMessage = (EmailNotificationMessage) message;
email.setSubject(emailMessage.getSubject());
email.setMsg(emailMessage.getMessage());
email.addTo(emailMessage.getSenderEmail());
email.send();
} catch (EmailException e) {
log.error("[CredentialStore]Error sending email notification message.");
throw new CredentialStoreException("Error sending email notification message", e);
}
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method addCertificateCredential.
@Override
public String addCertificateCredential(CertificateCredential certificateCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
try {
org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential();
credential.setPortalUserName(certificateCredential.getCommunityUser().getUsername());
credential.setCommunityUser(new CommunityUser(certificateCredential.getCommunityUser().getGatewayName(), certificateCredential.getCommunityUser().getUsername(), certificateCredential.getCommunityUser().getUserEmail()));
String token = TokenGenerator.generateToken(certificateCredential.getCommunityUser().getGatewayName(), null);
credential.setToken(token);
Base64 encoder = new Base64(64);
byte[] decoded = encoder.decode(certificateCredential.getX509Cert().replaceAll(X509Factory.BEGIN_CERT, "").replaceAll(X509Factory.END_CERT, ""));
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(decoded));
X509Certificate[] certificates = new X509Certificate[1];
certificates[0] = certificate;
credential.setCertificates(certificates);
certificateCredentialWriter.writeCredentials(credential);
return token;
} catch (CredentialStoreException e) {
log.error("Error occurred while saving Certificate Credentials.", e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while saving Certificate Credentials.");
} catch (Exception e) {
log.error("Error occurred while converting to X509 certificate.", e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while converting to X509 certificate..");
}
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method getAllPWDCredentialsForGateway.
@Override
public Map<String, String> getAllPWDCredentialsForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
Map<String, String> pwdCredMap = 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.password.PasswordCredential) {
org.apache.airavata.credential.store.credential.impl.password.PasswordCredential pwdCredential = (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential;
pwdCredMap.put(pwdCredential.getToken(), pwdCredential.getDescription() == null ? "" : pwdCredential.getDescription());
}
}
}
} 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 pwdCredMap;
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method getAllSSHKeysForUser.
@Override
public Map<String, String> getAllSSHKeysForUser(String username) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
Map<String, String> sshKeyMap = new HashMap<>();
try {
List<Credential> allCredentials = credentialReader.getAllCredentials();
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;
String portalUserName = sshCredential.getPortalUserName();
if (portalUserName != null && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER) {
if (portalUserName.equals(username)) {
byte[] publicKey = sshCredential.getPublicKey();
if (publicKey != null) {
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 getAllCredentialSummaryForGateway.
@Override
public List<CredentialSummary> getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
if (type.equals(SummaryType.SSH)) {
Map<String, String> sshKeyMap = new HashMap<>();
List<CredentialSummary> summaryList = new ArrayList<>();
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 && credential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) {
org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
CredentialSummary sshCredentialSummary = new CredentialSummary();
sshCredentialSummary.setType(SummaryType.SSH);
sshCredentialSummary.setToken(sshCredential.getToken());
sshCredentialSummary.setUsername(sshCredential.getPortalUserName());
sshCredentialSummary.setGatewayId(sshCredential.getGateway());
sshCredentialSummary.setDescription(sshCredential.getDescription());
sshCredentialSummary.setPublicKey(new String(sshCredential.getPublicKey()));
summaryList.add(sshCredentialSummary);
}
}
}
} catch (CredentialStoreException e) {
log.error("Error occurred while retrieving credential Summary", e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credential Summary");
}
return summaryList;
} else {
log.info("Summay Type" + type.toString() + " not supported for gateway id - " + gatewayId);
return null;
}
}
Aggregations