use of org.apache.airavata.credential.store.credential.Credential 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.credential.Credential in project airavata by apache.
the class CredentialReaderImpl method getPortalUser.
public String getPortalUser(String gatewayName, String tokenId) throws CredentialStoreException {
Connection connection = getConnection();
Credential credential;
try {
credential = this.credentialsDAO.getCredential(gatewayName, tokenId, connection);
} finally {
DBUtil.cleanup(connection);
}
return credential.getPortalUserName();
}
use of org.apache.airavata.credential.store.credential.Credential in project airavata by apache.
the class X509SecurityContext method getCredentialsFromStore.
/**
* Reads the credentials from credential store.
* @return If token is found in the credential store, will return a valid credential. Else returns null.
* @throws Exception If an error occurred while retrieving credentials.
*/
public X509Credential getCredentialsFromStore() throws Exception {
if (getCredentialReader() == null) {
return null;
}
Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(), getRequestData().getTokenId());
if (credential != null) {
if (credential instanceof CertificateCredential) {
log.info("Successfully found credentials for token id - " + getRequestData().getTokenId() + " gateway id - " + getRequestData().getGatewayId());
CertificateCredential certificateCredential = (CertificateCredential) credential;
X509Certificate[] certificates = certificateCredential.getCertificates();
KeyAndCertCredential keyAndCert = new KeyAndCertCredential(certificateCredential.getPrivateKey(), certificates);
return keyAndCert;
// return new GlobusGSSCredentialImpl(newCredential,
// GSSCredential.INITIATE_AND_ACCEPT);
} else {
log.info("Credential type is not CertificateCredential. Cannot create mapping globus credentials. " + "Credential type - " + credential.getClass().getName());
}
} else {
log.info("Could not find credentials for token - " + getRequestData().getTokenId() + " and " + "gateway id - " + getRequestData().getGatewayId());
}
return null;
}
use of org.apache.airavata.credential.store.credential.Credential in project airavata by apache.
the class TokenizedSSHAuthInfo method getCredentialsFromStore.
/**
* Reads the credentials from credential store.
*
* @return If token is found in the credential store, will return a valid credential. Else returns null.
* @throws Exception If an error occurred while retrieving credentials.
*/
public SSHCredential getCredentialsFromStore() throws Exception {
if (getCredentialReader() == null) {
credentialReader = GFacUtils.getCredentialReader();
if (credentialReader == null) {
return null;
}
}
Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(), getRequestData().getTokenId());
if (credential instanceof SSHCredential) {
SSHCredential credential1 = (SSHCredential) credential;
this.publicKeyFile = writeFileToDisk(credential1.getPublicKey());
this.privateKeyFile = writeFileToDisk(credential1.getPrivateKey());
this.passPhrase = credential1.getPassphrase();
System.out.println(this.publicKeyFile);
System.out.println(this.privateKeyFile);
System.out.println(this.passPhrase);
this.getRequestData().setRequestUser(credential1.getPortalUserName());
return credential1;
} else {
log.info("Could not find SSH credentials for token - " + getRequestData().getTokenId() + " and " + "gateway id - " + getRequestData().getGatewayId());
}
return null;
}
use of org.apache.airavata.credential.store.credential.Credential in project airavata by apache.
the class X509SecurityContext method getCredentialsFromStore.
/**
* Reads the credentials from credential store.
* @return If token is found in the credential store, will return a valid credential. Else returns null.
* @throws Exception If an error occurred while retrieving credentials.
*/
public X509Credential getCredentialsFromStore() throws Exception {
if (getCredentialReader() == null) {
return null;
}
Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(), getRequestData().getTokenId());
if (credential != null) {
if (credential instanceof CertificateCredential) {
log.info("Successfully found credentials for token id - " + getRequestData().getTokenId() + " gateway id - " + getRequestData().getGatewayId());
CertificateCredential certificateCredential = (CertificateCredential) credential;
X509Certificate[] certificates = certificateCredential.getCertificates();
KeyAndCertCredential keyAndCert = new KeyAndCertCredential(certificateCredential.getPrivateKey(), certificates);
return keyAndCert;
// return new GlobusGSSCredentialImpl(newCredential,
// GSSCredential.INITIATE_AND_ACCEPT);
} else {
log.info("Credential type is not CertificateCredential. Cannot create mapping globus credentials. " + "Credential type - " + credential.getClass().getName());
}
} else {
log.info("Could not find credentials for token - " + getRequestData().getTokenId() + " and " + "gateway id - " + getRequestData().getGatewayId());
}
return null;
}
Aggregations