use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method getAllCredentialSummaryForUserInGateway.
@Override
public List<CredentialSummary> getAllCredentialSummaryForUserInGateway(SummaryType type, String gatewayId, String userId) 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.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();
String gateway = sshCredential.getGateway();
if (portalUserName != null && gateway != null) {
if (portalUserName.equals(userId) && gateway.equals(gatewayId) && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER) {
org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredentialKey = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
CredentialSummary sshCredentialSummary = new CredentialSummary();
sshCredentialSummary.setType(SummaryType.SSH);
sshCredentialSummary.setToken(sshCredentialKey.getToken());
sshCredentialSummary.setUsername(sshCredentialKey.getPortalUserName());
sshCredentialSummary.setGatewayId(sshCredentialKey.getGateway());
sshCredentialSummary.setDescription(sshCredentialKey.getDescription());
sshCredentialSummary.setPublicKey(new String(sshCredentialKey.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 user Id - " + userId + " and " + "gateway id - " + gatewayId);
return null;
}
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CredentialStoreServerHandler method getCredentialSummary.
@Override
public CredentialSummary getCredentialSummary(SummaryType type, String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
try {
if (type.equals(SummaryType.SSH)) {
Credential credential = credentialReader.getCredential(gatewayId, tokenId);
if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) {
org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential;
CredentialSummary sshCredentialSummary = new CredentialSummary();
sshCredentialSummary.setType(SummaryType.SSH);
sshCredentialSummary.setUsername(credential1.getPortalUserName());
sshCredentialSummary.setGatewayId(credential1.getGateway());
sshCredentialSummary.setPublicKey(new String(credential1.getPublicKey()));
sshCredentialSummary.setToken(credential1.getToken());
sshCredentialSummary.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
sshCredentialSummary.setDescription(credential1.getDescription());
return sshCredentialSummary;
} else {
log.info("Could not find SSH credential for token - " + tokenId + " and " + "gateway id - " + gatewayId);
return null;
}
} else {
log.info("Summay Type" + type.toString() + " not supported for - " + tokenId + " and " + "gateway id - " + gatewayId);
return null;
}
} catch (CredentialStoreException e) {
log.error("Error occurred while retrieving SSH credential Summary for token - " + tokenId + " and gateway id - " + gatewayId, e);
throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving SSH credential Summary for token - " + tokenId + " and gateway id - " + gatewayId);
}
}
use of org.apache.airavata.credential.store.store.CredentialStoreException in project airavata by apache.
the class CommunityUserDAO method deleteCommunityUser.
public void deleteCommunityUser(CommunityUser user, Connection connection) throws CredentialStoreException {
String sql = "DELETE FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND COMMUNITY_USER_NAME=?";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, user.getGatewayName());
preparedStatement.setString(2, user.getUserName());
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 getCommunityUserByToken.
public CommunityUser getCommunityUserByToken(String gatewayName, String tokenId, Connection connection) throws CredentialStoreException {
String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=? AND TOKEN_ID=?";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, gatewayName);
preparedStatement.setString(2, tokenId);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next()) {
String communityUserName = resultSet.getString("COMMUNITY_USER_NAME");
// 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("token- ").append(tokenId);
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 getCommunityUsers.
public List<CommunityUser> getCommunityUsers(String gatewayName, Connection connection) throws CredentialStoreException {
List<CommunityUser> userList = new ArrayList<CommunityUser>();
String sql = "SELECT * FROM COMMUNITY_USER WHERE GATEWAY_ID=?";
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, gatewayName);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
String userName = resultSet.getString("COMMUNITY_USER_NAME");
// TODO fix typo
String email = resultSet.getString("COMMUNITY_USER_EMAIL");
userList.add(new CommunityUser(gatewayName, userName, email));
}
} catch (SQLException e) {
StringBuilder stringBuilder = new StringBuilder("Error retrieving community users for ");
stringBuilder.append("gateway - ").append(gatewayName);
log.error(stringBuilder.toString(), e);
throw new CredentialStoreException(stringBuilder.toString(), e);
} finally {
DBUtil.cleanup(preparedStatement);
}
return userList;
}
Aggregations