Search in sources :

Example 1 with CommunityUser

use of org.apache.airavata.credential.store.credential.CommunityUser in project airavata by apache.

the class CommunityUserDAOTest method testAddCommunityUser.

@Test
public void testAddCommunityUser() throws Exception {
    Connection connection = getConnection();
    try {
        CommunityUser communityUser = new CommunityUser("gw1", "ogce", "ogce@sciencegateway.org");
        communityUserDAO.addCommunityUser(communityUser, "Token1", connection);
        communityUser = new CommunityUser("gw1", "ogce2", "ogce@sciencegateway.org");
        communityUserDAO.addCommunityUser(communityUser, "Token2", connection);
        CommunityUser user = communityUserDAO.getCommunityUser("gw1", "ogce", connection);
        Assert.assertNotNull(user);
        Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
        user = communityUserDAO.getCommunityUser("gw1", "ogce2", connection);
        Assert.assertNotNull(user);
        Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
        user = communityUserDAO.getCommunityUserByToken("gw1", "Token1", connection);
        Assert.assertNotNull(user);
        Assert.assertEquals("ogce", user.getUserName());
        Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
        user = communityUserDAO.getCommunityUserByToken("gw1", "Token2", connection);
        Assert.assertNotNull(user);
        Assert.assertEquals("ogce2", user.getUserName());
        Assert.assertEquals("ogce@sciencegateway.org", user.getUserEmail());
    } finally {
        connection.close();
    }
}
Also used : CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) Connection(java.sql.Connection)

Example 2 with CommunityUser

use of org.apache.airavata.credential.store.credential.CommunityUser in project airavata by apache.

the class NotifierBootstrap method run.

@Override
public void run() {
    if (!enabled)
        return;
    // retrieve OA4MP credentials
    try {
        CredentialReader credentialReader = new CredentialReaderImpl(this.dbUtil);
        List<Credential> credentials = credentialReader.getAllCredentials();
        for (Credential credential : credentials) {
            if (credential instanceof CertificateCredential) {
                CertificateCredential certificateCredential = (CertificateCredential) credential;
                Date date = Utility.convertStringToDate(certificateCredential.getNotAfter());
                // gap is 1 days
                date.setDate(date.getDate() + 1);
                Date currentDate = new Date();
                if (currentDate.after(date)) {
                    // Send an email
                    CommunityUser communityUser = certificateCredential.getCommunityUser();
                    String body = String.format(MESSAGE, communityUser.getUserName(), certificateCredential.getNotAfter());
                    String subject = String.format(SUBJECT, communityUser.getUserName());
                    NotificationMessage notificationMessage = new EmailNotificationMessage(subject, communityUser.getUserEmail(), body);
                    this.credentialStoreNotifier.notifyMessage(notificationMessage);
                }
            }
        }
    } catch (ApplicationSettingsException e) {
        log.error("Error configuring email senders.", e);
    } catch (CredentialStoreException e) {
        log.error("Error sending emails about credential expiring.", e);
    } catch (ParseException e) {
        log.error("Error parsing date time when sending emails", e);
    }
}
Also used : EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) Credential(org.apache.airavata.credential.store.credential.Credential) CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) CertificateCredential(org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) CredentialReaderImpl(org.apache.airavata.credential.store.store.impl.CredentialReaderImpl) EmailNotificationMessage(org.apache.airavata.credential.store.notifier.impl.EmailNotificationMessage) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) ParseException(java.text.ParseException)

Example 3 with CommunityUser

use of org.apache.airavata.credential.store.credential.CommunityUser in project airavata by apache.

the class CredentialStoreServerHandler method getCertificateCredential.

@Override
public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException {
    try {
        Credential credential = credentialReader.getCredential(gatewayId, tokenId);
        if (credential instanceof org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) {
            org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential1 = (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) credential;
            CertificateCredential certificateCredential = new CertificateCredential();
            org.apache.airavata.model.credential.store.CommunityUser communityUser = new org.apache.airavata.model.credential.store.CommunityUser();
            communityUser.setGatewayName(credential1.getCommunityUser().getGatewayName());
            communityUser.setUsername(credential1.getCommunityUser().getUserName());
            communityUser.setUserEmail(credential1.getCommunityUser().getUserEmail());
            certificateCredential.setCommunityUser(communityUser);
            certificateCredential.setToken(credential1.getToken());
            certificateCredential.setLifeTime(credential1.getLifeTime());
            certificateCredential.setNotAfter(credential1.getNotAfter());
            certificateCredential.setNotBefore(credential1.getNotBefore());
            certificateCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime());
            if (credential1.getPrivateKey() != null) {
                certificateCredential.setPrivateKey(credential1.getPrivateKey().toString());
            }
            certificateCredential.setX509Cert(credential1.getCertificates()[0].toString());
            return certificateCredential;
        } else {
            log.info("Could not find Certificate credentials for token - " + tokenId + " and " + "gateway id - " + gatewayId);
            return null;
        }
    } catch (CredentialStoreException e) {
        log.error("Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId, e);
        throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId);
    }
}
Also used : Credential(org.apache.airavata.credential.store.credential.Credential) CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) org.apache.airavata.model.credential.store(org.apache.airavata.model.credential.store) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 4 with CommunityUser

use of org.apache.airavata.credential.store.credential.CommunityUser 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;
}
Also used : CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Example 5 with CommunityUser

use of org.apache.airavata.credential.store.credential.CommunityUser 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;
}
Also used : CommunityUser(org.apache.airavata.credential.store.credential.CommunityUser) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException)

Aggregations

CommunityUser (org.apache.airavata.credential.store.credential.CommunityUser)14 Connection (java.sql.Connection)7 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)6 SQLException (java.sql.SQLException)4 CertificateCredential (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 X509Certificate (java.security.cert.X509Certificate)2 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)2 Credential (org.apache.airavata.credential.store.credential.Credential)2 org.apache.airavata.model.credential.store (org.apache.airavata.model.credential.store)2 AssetResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse)1 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 PrivateKey (java.security.PrivateKey)1 CertificateFactory (java.security.cert.CertificateFactory)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 CertificateAuditInfo (org.apache.airavata.credential.store.credential.impl.certificate.CertificateAuditInfo)1