Search in sources :

Example 11 with Credential

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;
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) ArrayList(java.util.ArrayList) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 12 with Credential

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();
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) Connection(java.sql.Connection)

Example 13 with Credential

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;
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) X509Credential(eu.emi.security.authn.x509.X509Credential) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) X509Certificate(java.security.cert.X509Certificate)

Example 14 with Credential

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;
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) SSHCredential(org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)

Example 15 with Credential

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;
}
Also used : CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) X509Credential(eu.emi.security.authn.x509.X509Credential) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) X509Certificate(java.security.cert.X509Certificate)

Aggregations

Credential (org.apache.airavata.credential.store.credential.Credential)19 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)14 org.apache.airavata.model.credential.store (org.apache.airavata.model.credential.store)9 CertificateCredential (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential)5 X509Credential (eu.emi.security.authn.x509.X509Credential)2 KeyAndCertCredential (eu.emi.security.authn.x509.impl.KeyAndCertCredential)2 X509Certificate (java.security.cert.X509Certificate)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 CommunityUser (org.apache.airavata.credential.store.credential.CommunityUser)2 SSHCredential (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential)2 CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)2 ParseException (java.text.ParseException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 EmailNotificationMessage (org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage)1 CredentialReaderImpl (org.apache.airavata.credential.store.store.impl.CredentialReaderImpl)1 SSHKeyAuthentication (org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication)1 Test (org.junit.Test)1