Hi all I have added Ec2Credential.java and Ec2CredentialWriter.java to credentialStore. the patch file for the changes to airavata [1]. and change for gfac-jclouds [2]
[1] - add_ec2_credentials_to_credential_store.patch [2] - https://github.com/nipun123/gfac-jclouds/blob/master/src/main/java/org/apache/airavata/gfac/jclouds/security/JCloudsSecurityContext.java regards Nipun Udara
Index: modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/Ec2CredentialWriter.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/Ec2CredentialWriter.java (revision ) +++ modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/Ec2CredentialWriter.java (revision ) @@ -0,0 +1,79 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.credential.store.store.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ApplicationSettings; +import org.apache.airavata.common.utils.DBUtil; +import org.apache.airavata.common.utils.DefaultKeyStorePasswordCallback; +import org.apache.airavata.credential.store.credential.Credential; +import org.apache.airavata.credential.store.credential.impl.ec2.Ec2Credential; +import org.apache.airavata.credential.store.store.CredentialStoreException; +import org.apache.airavata.credential.store.store.impl.db.CredentialsDAO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.SQLException; + +public class Ec2CredentialWriter { + private CredentialsDAO credentialsDAO; + private DBUtil dbUtil; + + protected static Logger logger = LoggerFactory.getLogger(Ec2CredentialWriter.class); + + public Ec2CredentialWriter(DBUtil dbUtil) throws ApplicationSettingsException { + this.dbUtil = dbUtil; + this.credentialsDAO = new CredentialsDAO(ApplicationSettings.getCredentialStoreKeyStorePath(), + ApplicationSettings.getCredentialStoreKeyAlias(), new DefaultKeyStorePasswordCallback()); + + } + + public void writeCredentials(Credential credential) throws CredentialStoreException{ + Ec2Credential ec2Credential=(Ec2Credential)credential; + Connection connection=null; + + try{ + connection=dbUtil.getConnection(); + // First delete existing credentials + credentialsDAO.deleteCredentials(ec2Credential.getGateway(), ec2Credential.getToken(), connection); + // Add the new certificate + credentialsDAO.addCredentials(ec2Credential.getGateway(), credential, connection); + + }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); + + } + + } + +} + Index: modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ec2/Ec2Credential.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ec2/Ec2Credential.java (revision ) +++ modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/credential/impl/ec2/Ec2Credential.java (revision ) @@ -0,0 +1,83 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.credential.store.credential.impl.ec2; + +import org.apache.airavata.credential.store.credential.Credential; +import java.io.Serializable; + +public class Ec2Credential extends Credential implements Serializable{ + + private String accessKey; + private String secretKey; + private byte[] publickey; + private String gateway; + private String username; + + public Ec2Credential(String accessKey,String secretKey,byte[] publickey,String gateway,String username){ + this.accessKey=accessKey; + this.secretKey=secretKey; + this.publickey=publickey; + this.gateway=gateway; + this.username=username; + } + + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getGateway() { + return gateway; + } + + public void setGateway(String gateway) { + this.gateway = gateway; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public byte[] getPublickey() { + return publickey; + } + + public void setPublickey(byte[] publickey) { + this.publickey = publickey; + } +}