use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class SSHCredentialWriter method writeCredentials.
public void writeCredentials(Credential credential) throws CredentialStoreException {
SSHCredential sshCredential = (SSHCredential) credential;
Connection connection = null;
try {
connection = dbUtil.getConnection();
// First delete existing credentials
credentialsDAO.deleteCredentials(sshCredential.getGateway(), sshCredential.getToken(), connection);
// Add the new certificate
credentialsDAO.addCredentials(sshCredential.getGateway(), credential, connection);
if (!connection.getAutoCommit()) {
connection.commit();
}
} catch (SQLException e) {
if (connection != null) {
try {
connection.rollback();
} catch (SQLException e1) {
logger.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.store.CredentialStoreException in project airavata by apache.
the class CommunityUserDAO method deleteCommunityUserByToken.
public void deleteCommunityUserByToken(CommunityUser user, String token, Connection connection) throws CredentialStoreException {
String sql = "DELETE FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND COMMUNITY_USER_NAME=? AND TOKEN_ID=?";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, user.getGatewayName());
preparedStatement.setString(2, user.getUserName());
preparedStatement.setString(3, token);
preparedStatement.executeUpdate();
connection.commit();
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error deleting community user.");
stringBuilder.append("gateway - ").append(user.getGatewayName());
stringBuilder.append("community user name - ").append(user.getUserName());
log.error(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement);
}
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CommunityUserDAO method getCommunityUser.
public CommunityUser getCommunityUser(String gatewayName, String communityUserName, Connection connection) throws CredentialStoreException {
String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND COMMUNITY_USER_NAME=?";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, gatewayName);
preparedStatement.setString(2, communityUserName);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
// 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("community user name - ").append(communityUserName);
log.error(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement);
}
return null;
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CommunityUserDAO method addCommunityUser.
public void addCommunityUser(CommunityUser user, String token, Connection connection) throws CredentialStoreException {
String sql = "INSERT INTO COMMUNITY_USER VALUES (?, ?, ?, ?)";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, user.getGatewayName());
preparedStatement.setString(2, user.getUserName());
preparedStatement.setString(3, token);
preparedStatement.setString(4, user.getUserEmail());
preparedStatement.executeUpdate();
connection.commit();
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error persisting community user.");
stringBuilder.append("gateway - ").append(user.getGatewayName());
stringBuilder.append("community user name - ").append(user.getUserName());
stringBuilder.append("community user email - ").append(user.getUserEmail());
stringBuilder.append("token id - ").append(token);
log.error(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement);
}
}
use of org.apache.airavata.credential.store.store.CredentialStoreException 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;
}
Aggregations