use of org.apache.airavata.credential.store.credential.Credential in project airavata by apache.
the class CredentialsDAO method getCredential.
/**
* String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" + " GATEWAY_ID VARCHAR(256) NOT NULL,\n" +
* " TOKEN_ID VARCHAR(256) NOT NULL,\n" + // Actual token used to identify the credential
* " CREDENTIAL BLOB NOT NULL,\n" + " PORTAL_USER_ID VARCHAR(256) NOT NULL,\n" +
* " TIME_PERSISTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n" + " PRIMARY KEY (GATEWAY_ID, TOKEN_ID)\n"
* + ")";
*/
public Credential getCredential(String gatewayName, String tokenId, Connection connection) throws CredentialStoreException {
String sql = "SELECT * FROM CREDENTIALS WHERE GATEWAY_ID=? AND TOKEN_ID=?";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, gatewayName);
preparedStatement.setString(2, tokenId);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
// CertificateCredential certificateCredential = new CertificateCredential();
Blob blobCredentials = resultSet.getBlob("CREDENTIAL");
byte[] certificate = blobCredentials.getBytes(1, (int) blobCredentials.length());
Credential certificateCredential = (Credential) convertByteArrayToObject(certificate);
certificateCredential.setPortalUserName(resultSet.getString("PORTAL_USER_ID"));
certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("TIME_PERSISTED"));
certificateCredential.setDescription(resultSet.getString("DESCRIPTION"));
certificateCredential.setCredentialOwnerType(CredentialOwnerType.valueOf(resultSet.getString("CREDENTIAL_OWNER_TYPE")));
return certificateCredential;
}
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for user.");
stringBuilder.append("gateway - ").append(gatewayName);
stringBuilder.append("token id - ").append(tokenId);
log.debug(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement, resultSet);
}
return null;
}
use of org.apache.airavata.credential.store.credential.Credential 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.credential.Credential 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.credential.Credential 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