use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialsDAO method getCredentials.
/**
* Gets all credentials.
* @param connection The database connection
* @return All credentials as a list
* @throws CredentialStoreException If an error occurred while rerieving credentials.
*/
public List<Credential> getCredentials(Connection connection) throws CredentialStoreException {
List<Credential> credentialList = new ArrayList<Credential>();
String sql = "SELECT * FROM CREDENTIALS";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = connection.prepareStatement(sql);
resultSet = preparedStatement.executeQuery();
Credential certificateCredential;
while (resultSet.next()) {
Blob blobCredentials = resultSet.getBlob("CREDENTIAL");
byte[] certificate = blobCredentials.getBytes(1, (int) blobCredentials.length());
certificateCredential = (Credential) convertByteArrayToObject(certificate);
certificateCredential.setToken(resultSet.getString("TOKEN_ID"));
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")));
credentialList.add(certificateCredential);
}
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error retrieving all credentials");
log.debug(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement, resultSet);
}
return credentialList;
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialsDAO method getCredentials.
/**
* 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 List<Credential> getCredentials(String gatewayName, Connection connection) throws CredentialStoreException {
List<Credential> credentialList = new ArrayList<Credential>();
String sql = "SELECT * FROM CREDENTIALS WHERE GATEWAY_ID=?";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, gatewayName);
resultSet = preparedStatement.executeQuery();
Credential certificateCredential;
while (resultSet.next()) {
Blob blobCredentials = resultSet.getBlob("CREDENTIAL");
byte[] certificate = blobCredentials.getBytes(1, (int) blobCredentials.length());
certificateCredential = (Credential) convertByteArrayToObject(certificate);
certificateCredential.setToken(resultSet.getString("TOKEN_ID"));
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")));
credentialList.add(certificateCredential);
}
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error retrieving credential list for ");
stringBuilder.append("gateway - ").append(gatewayName);
log.debug(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement, resultSet);
}
return credentialList;
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialsDAO method getGatewayID.
/**
*/
public String getGatewayID(String tokenId, Connection connection) throws CredentialStoreException {
String sql = "SELECT GATEWAY_ID FROM CREDENTIALS WHERE TOKEN_ID=?";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, tokenId);
resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
return resultSet.getString("GATEWAY_ID");
}
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials for user.");
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.store.CredentialStoreException in project airavata by apache.
the class CertificateCredentialWriter method writeCredentials.
public void writeCredentials(Credential credential) throws CredentialStoreException {
CertificateCredential certificateCredential = (CertificateCredential) credential;
Connection connection = null;
try {
connection = dbUtil.getConnection();
// Write community user
writeCommunityUser(certificateCredential.getCommunityUser(), credential.getToken(), connection);
// First delete existing credentials
credentialsDAO.deleteCredentials(certificateCredential.getCommunityUser().getGatewayName(), certificateCredential.getToken(), connection);
// Add the new certificate
credentialsDAO.addCredentials(certificateCredential.getCommunityUser().getGatewayName(), credential, connection);
if (!connection.getAutoCommit()) {
connection.commit();
}
} catch (SQLException e) {
if (connection != null) {
try {
connection.rollback();
} catch (SQLException e1) {
log.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 GfacServerHandler method submitProcess.
/**
* * After creating the experiment Data and Task Data in the orchestrator
* * Orchestrator has to invoke this operation for each Task per experiment to run
* * the actual Job related actions.
* *
* * @param experimentID
* * @param taskID
* * @param gatewayId:
* * The GatewayId is inferred from security context and passed onto gfac.
* * @return sucess/failure
* *
* *
*
* @param processId - processModel id in registry
* @param gatewayId - gateway Identification
*/
public boolean submitProcess(String processId, String gatewayId, String tokenId) throws TException {
MDC.put(MDCConstants.PROCESS_ID, processId);
MDC.put(MDCConstants.GATEWAY_ID, gatewayId);
MDC.put(MDCConstants.TOKEN_ID, tokenId);
try {
executorService.execute(MDCUtil.wrapWithMDC(new GFacWorker(processId, gatewayId, tokenId)));
} catch (GFacException e) {
log.error("Failed to submit process", e);
throw new TException("Failed to submit process", e);
} catch (CredentialStoreException e) {
log.error("Failed to submit process due to credential issue, " + "make sure you are passing a valid credentials");
throw new TException("Failed to submit process due to credential issue, " + "make sure you are passing a valid credential token", e);
} catch (Exception e) {
log.error("Error creating zookeeper nodes", e);
throw new TException("Error creating zookeeper nodes", e);
}
return true;
}
Aggregations