http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java deleted file mode 100644 index 387e2af..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * - * 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.server; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.DBUtil; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; -import org.apache.airavata.credential.store.cpi.credential_store_cpiConstants; -import org.apache.airavata.credential.store.credential.CommunityUser; -import org.apache.airavata.credential.store.credential.Credential; -import org.apache.airavata.credential.store.credential.CredentialOwnerType; -import org.apache.airavata.credential.store.datamodel.CertificateCredential; -import org.apache.airavata.credential.store.datamodel.PasswordCredential; -import org.apache.airavata.credential.store.datamodel.SSHCredential; -import org.apache.airavata.credential.store.datamodel.SSHCredentialSummary; -import org.apache.airavata.credential.store.store.CredentialStoreException; -import org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter; -import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl; -import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter; -import org.apache.airavata.credential.store.store.impl.util.CredentialStoreInitUtil; -import org.apache.airavata.credential.store.util.TokenGenerator; -import org.apache.airavata.credential.store.util.Utility; -import org.apache.commons.codec.binary.Base64; -import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sun.security.provider.X509Factory; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.sql.SQLException; -import java.util.*; - -public class CredentialStoreServerHandler implements CredentialStoreService.Iface { - protected static Logger log = LoggerFactory.getLogger(CredentialStoreServerHandler.class); - private DBUtil dbUtil; - private SSHCredentialWriter sshCredentialWriter; - private CertificateCredentialWriter certificateCredentialWriter; - private CredentialReaderImpl credentialReader; - - public CredentialStoreServerHandler() throws ApplicationSettingsException, IllegalAccessException, - ClassNotFoundException, InstantiationException, SQLException, IOException { - String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); - String userName = ServerSettings.getCredentialStoreDBUser(); - String password = ServerSettings.getCredentialStoreDBPassword(); - String driverName = ServerSettings.getCredentialStoreDBDriver(); - - log.debug("Starting credential store, connecting to database - " + jdbcUrl + " DB user - " + userName + " driver name - " + driverName); - CredentialStoreInitUtil.initializeDB(); - - dbUtil = new DBUtil(jdbcUrl, userName, password, driverName); - sshCredentialWriter = new SSHCredentialWriter(dbUtil); - certificateCredentialWriter = new CertificateCredentialWriter(dbUtil); - credentialReader = new CredentialReaderImpl(dbUtil); - } - - @Override - public String getCSServiceVersion() throws TException { - return credential_store_cpiConstants.CS_CPI_VERSION; - } - - @Override - public String addSSHCredential(SSHCredential sshCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential = new org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential(); - credential.setGateway(sshCredential.getGatewayId()); - credential.setPortalUserName(sshCredential.getUsername()); - // only username and gateway id will be sent by client. - String token = TokenGenerator.generateToken(sshCredential.getGatewayId(), null); - credential.setToken(token); - credential.setPassphrase(String.valueOf(UUID.randomUUID())); - if (sshCredential.getPrivateKey() != null) { - credential.setPrivateKey(sshCredential.getPrivateKey().getBytes()); - } - if(sshCredential.getDescription() != null){ - credential.setDescription(sshCredential.getDescription()); - } - if (sshCredential.getPublicKey() != null) { - credential.setPublicKey(sshCredential.getPublicKey().getBytes()); - } - if (sshCredential.getPublicKey() == null || sshCredential.getPrivateKey() == null) { - credential = Utility.generateKeyPair(credential); - } - credential.setCredentialOwnerType(CredentialOwnerType.findByDataModelType(sshCredential.getCredentialOwnerType())); - sshCredentialWriter.writeCredentials(credential); - return token; - } catch (CredentialStoreException e) { - log.error("Error occurred while saving SSH Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while saving SSH Credentials."); - } catch (Exception e) { - log.error("Error occurred while generating key pair.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while generating key pair.."); - } - } - - @Override - public String addCertificateCredential(CertificateCredential certificateCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential(); - credential.setPortalUserName(certificateCredential.getCommunityUser().getUsername()); - credential.setCommunityUser(new CommunityUser(certificateCredential.getCommunityUser().getGatewayName(), - certificateCredential.getCommunityUser().getUsername(), certificateCredential.getCommunityUser().getUserEmail())); - String token = TokenGenerator.generateToken(certificateCredential.getCommunityUser().getGatewayName(), null); - credential.setToken(token); - Base64 encoder = new Base64(64); - byte [] decoded = encoder.decode(certificateCredential.getX509Cert().replaceAll(X509Factory.BEGIN_CERT, "").replaceAll(X509Factory.END_CERT, "")); - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - X509Certificate certificate = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(decoded)); - X509Certificate[] certificates = new X509Certificate[1]; - certificates[0] = certificate; - credential.setCertificates(certificates); - certificateCredentialWriter.writeCredentials(credential); - return token; - } catch (CredentialStoreException e) { - log.error("Error occurred while saving Certificate Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while saving Certificate Credentials."); - } catch (Exception e) { - log.error("Error occurred while converting to X509 certificate.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while converting to X509 certificate.."); - } - } - - @Override - public String addPasswordCredential(PasswordCredential passwordCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential = new org.apache.airavata.credential.store.credential.impl.password.PasswordCredential(); - credential.setGateway(passwordCredential.getGatewayId()); - credential.setPortalUserName(passwordCredential.getPortalUserName()); - credential.setUserName(passwordCredential.getLoginUserName()); - credential.setPassword(passwordCredential.getPassword()); - credential.setDescription(passwordCredential.getDescription()); - String token = TokenGenerator.generateToken(passwordCredential.getGatewayId(), null); - credential.setToken(token); - sshCredentialWriter.writeCredentials(credential); - return token; - } catch (CredentialStoreException e) { - log.error("Error occurred while saving PWD Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while saving PWD Credentials."); - } catch (Exception e) { - log.error("Error occurred while registering PWD Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while registering PWD Credentials.."); - } - } - - @Override - public SSHCredential getSSHCredential(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.ssh.SSHCredential) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; - SSHCredential sshCredential = new SSHCredential(); - sshCredential.setUsername(credential1.getPortalUserName()); - sshCredential.setGatewayId(credential1.getGateway()); - sshCredential.setPublicKey(new String(credential1.getPublicKey())); - sshCredential.setPrivateKey(new String(credential1.getPrivateKey())); - sshCredential.setPassphrase(credential1.getPassphrase()); - sshCredential.setToken(credential1.getToken()); - sshCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime()); - sshCredential.setDescription(credential1.getDescription()); - sshCredential.setCredentialOwnerType(credential1.getCredentialOwnerType().getDatamodelType()); - return sshCredential; - } else { - log.info("Could not find SSH credentials for token - " + tokenId + " and " - + "gateway id - " + gatewayId); - return null; - } - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving SSH credential for token - " + tokenId + " and gateway id - " + gatewayId); - } - } - - @Override - public SSHCredentialSummary getSSHCredentialSummary(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.ssh.SSHCredential) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; - SSHCredentialSummary sshCredentialSummary = new SSHCredentialSummary(); - 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; - } - } 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); - } - } - - @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.credential.store.datamodel.CommunityUser communityUser = new org.apache.airavata.credential.store.datamodel.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); - } - } - - @Override - public PasswordCredential getPasswordCredential(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.password.PasswordCredential) { - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential1 = (org.apache.airavata.credential - .store.credential.impl.password.PasswordCredential) credential; - PasswordCredential pwdCredential = new PasswordCredential(); - pwdCredential.setGatewayId(credential1.getGateway()); - pwdCredential.setPortalUserName(credential1.getPortalUserName()); - pwdCredential.setLoginUserName(credential1.getUserName()); - pwdCredential.setPassword(credential1.getPassword()); - pwdCredential.setDescription(credential1.getDescription()); - pwdCredential.setToken(credential1.getToken()); - pwdCredential.setPersistedTime(credential1.getCertificateRequestedTime().getTime()); - return pwdCredential; - } else { - log.info("Could not find PWD credentials for token - " + tokenId + " and " - + "gateway id - " + gatewayId); - return null; - } - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving PWD credential for token - " + tokenId + " and gateway id - " + gatewayId); - } - } - - @Override - public Map<String, String> getAllSSHKeysForUser(String username) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - Map<String, String> sshKeyMap = new HashMap<>(); - 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(); - if (portalUserName != null && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER){ - if (portalUserName.equals(username)) { - byte[] publicKey = sshCredential.getPublicKey(); - if (publicKey != null) { - sshKeyMap.put(sshCredential.getToken(), new String(publicKey)); - } - } - } - } - } - } - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credentials", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credentials"); - } - return sshKeyMap; - } - - @Override - public Map<String, String> getAllSSHKeysForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - Map<String, String> sshKeyMap = new HashMap<>(); - try { - List<Credential> allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); - 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; - byte[] publicKey = sshCredential.getPublicKey(); - if (publicKey != null && sshCredential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) { - sshKeyMap.put(sshCredential.getToken(), new String(publicKey)); - } - } - } - } - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credentials", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credentials"); - } - return sshKeyMap; - - } - - @Override - public List<SSHCredentialSummary> getAllGatewaySSHCredentialSummary(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - Map<String, String> sshKeyMap = new HashMap<>(); - List<SSHCredentialSummary> summaryList = new ArrayList<>(); - try { - List<Credential> allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); - if (allCredentials != null && !allCredentials.isEmpty()){ - for (Credential credential : allCredentials) { - if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential - && credential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; - SSHCredentialSummary sshCredentialSummary = new SSHCredentialSummary(); - sshCredentialSummary.setToken(sshCredential.getToken()); - sshCredentialSummary.setUsername(sshCredential.getPortalUserName()); - sshCredentialSummary.setGatewayId(sshCredential.getGateway()); - sshCredentialSummary.setDescription(sshCredential.getDescription()); - sshCredentialSummary.setPublicKey(new String(sshCredential.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; - } - - @Override - public List<SSHCredentialSummary> getAllSSHCredentialSummaryForUserInGateway(String gatewayId, String userId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - Map<String, String> sshKeyMap = new HashMap<>(); - List<SSHCredentialSummary> 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 && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER){ - if (portalUserName.equals(userId) && gateway.equals(gatewayId)) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredentialKey = (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; - SSHCredentialSummary sshCredentialSummary = new SSHCredentialSummary(); - 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; - } - - @Override - public Map<String, String> getAllPWDCredentialsForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - Map<String, String> pwdCredMap = new HashMap<>(); - try { - List<Credential> allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); - if (allCredentials != null && !allCredentials.isEmpty()){ - for (Credential credential : allCredentials) { - if (credential instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) { - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential pwdCredential = (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential; - pwdCredMap.put(pwdCredential.getToken(),pwdCredential.getDescription() == null ? "" : pwdCredential.getDescription()); - } - } - } - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credentials", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while retrieving credentials"); - } - return pwdCredMap; - } - - @Override - public boolean deleteSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - credentialReader.removeCredentials(gatewayId, tokenId); - return true; - } catch (CredentialStoreException e) { - log.error("Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " + gatewayId); - } - } - - @Override - public boolean deletePWDCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - credentialReader.removeCredentials(gatewayId, tokenId); - return true; - } catch (CredentialStoreException e) { - log.error("Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException("Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " + gatewayId); - } - } - - -}
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java deleted file mode 100644 index b2e8786..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialBootstrapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * 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.servlet; - -import edu.uiuc.ncsa.myproxy.oa4mp.client.loader.ClientBootstrapper; -import edu.uiuc.ncsa.security.core.util.ConfigurationLoader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletContext; -import java.io.File; - -/** - * Bootstrapper class for credential-store. - */ -public class CredentialBootstrapper extends ClientBootstrapper { - - protected static Logger log = LoggerFactory.getLogger(CredentialBootstrapper.class); - - public ConfigurationLoader getConfigurationLoader(ServletContext servletContext) throws Exception { - - File currentDirectory = new File("."); - - log.info("Current directory is - " + currentDirectory.getAbsolutePath()); - - return super.getConfigurationLoader(servletContext); - - } - -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java deleted file mode 100644 index 72211fa..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreCallbackServlet.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * - * 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.servlet; - -import edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse; -import edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment; -import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPService; -import edu.uiuc.ncsa.myproxy.oa4mp.client.servlet.ClientServlet; -import edu.uiuc.ncsa.security.core.exceptions.GeneralException; -import edu.uiuc.ncsa.security.servlet.JSPUtil; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.AiravataUtils; -import org.apache.airavata.common.utils.ApplicationSettings; -import org.apache.airavata.common.utils.DBUtil; -import org.apache.airavata.credential.store.credential.CommunityUser; -import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential; -import org.apache.airavata.credential.store.notifier.NotifierBootstrap; -import org.apache.airavata.credential.store.notifier.impl.EmailNotifierConfiguration; -import org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter; -import org.apache.airavata.credential.store.util.ConfigurationReader; -import org.apache.airavata.credential.store.util.CredentialStoreConstants; -import org.apache.airavata.credential.store.util.PrivateKeyStore; -import org.apache.airavata.credential.store.util.Utility; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.security.PrivateKey; -import java.security.cert.X509Certificate; -import java.util.HashMap; -import java.util.Map; - -import static edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment.CALLBACK_URI_KEY; - -/** - * Callback from the portal will come here. In this class we will store incomming certificate to the database. Partly - * taken from OA4MP code base. - */ -public class CredentialStoreCallbackServlet extends ClientServlet { - - private OA4MPService oa4mpService; - - private CertificateCredentialWriter certificateCredentialWriter; - - private static ConfigurationReader configurationReader; - - private NotifierBootstrap notifierBootstrap; - - public void init() throws ServletException { - - DBUtil dbUtil; - - try { - dbUtil = DBUtil.getCredentialStoreDBUtil(); - } catch (Exception e) { - throw new ServletException("Error initializing database operations.", e); - } - - try { - configurationReader = new ConfigurationReader(); - super.init(); - certificateCredentialWriter = new CertificateCredentialWriter(dbUtil); - } catch (Exception e) { - throw new ServletException("Error initializing configuration reader.", e); - } - - - // initialize notifier - try { - boolean enabled = Boolean.parseBoolean(ApplicationSettings.getCredentialStoreNotifierEnabled()); - - if (enabled) { - EmailNotifierConfiguration notifierConfiguration - = EmailNotifierConfiguration.getEmailNotifierConfigurations(); - long duration = Long.parseLong(ApplicationSettings.getCredentialStoreNotifierDuration()); - - notifierBootstrap = new NotifierBootstrap(duration, dbUtil, notifierConfiguration); - } - - } catch (ApplicationSettingsException e) { - throw new ServletException("Error initializing notifier.", e); - } - - - info("Credential store callback initialized successfully."); - } - - @Override - public OA4MPService getOA4MPService() { - return oa4mpService; - } - - @Override - public void loadEnvironment() throws IOException { - environment = getConfigurationLoader().load(); - oa4mpService = new OA4MPService((ClientEnvironment) environment); - } - - @Override - protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable { - - String gatewayName = request.getParameter(CredentialStoreConstants.GATEWAY_NAME_QUERY_PARAMETER); - String portalUserName = request.getParameter(CredentialStoreConstants.PORTAL_USER_QUERY_PARAMETER); - String durationParameter = request.getParameter(CredentialStoreConstants.DURATION_QUERY_PARAMETER); - String contactEmail = request.getParameter(CredentialStoreConstants.PORTAL_USER_EMAIL_QUERY_PARAMETER); - String portalTokenId = request.getParameter(CredentialStoreConstants.PORTAL_TOKEN_ID_ASSIGNED); - - // TODO remove hard coded values, once passing query parameters is - // fixed in OA4MP client api - long duration = 864000; - - if (durationParameter != null) { - duration = Long.parseLong(durationParameter); - } - - if (portalTokenId == null) { - error("Token given by portal is invalid."); - GeneralException ge = new GeneralException("Error: The token presented by portal is null."); - request.setAttribute("exception", ge); - JSPUtil.fwd(request, response, configurationReader.getErrorUrl()); - return; - } - - info("Gateway name " + gatewayName); - info("Portal user name " + portalUserName); - info("Community user contact email " + contactEmail); - info("Token id presented " + portalTokenId); - - info("2.a. Getting token and verifier."); - String token = request.getParameter(CONST(ClientEnvironment.TOKEN)); - String verifier = request.getParameter(CONST(ClientEnvironment.VERIFIER)); - if (token == null || verifier == null) { - warn("2.a. The token is " + (token == null ? "null" : token) + " and the verifier is " - + (verifier == null ? "null" : verifier)); - GeneralException ge = new GeneralException( - "Error: This servlet requires parameters for the token and verifier. It cannot be called directly."); - request.setAttribute("exception", ge); - JSPUtil.fwd(request, response, configurationReader.getErrorUrl()); - return; - } - info("2.a Token and verifier found."); - X509Certificate[] certificates; - AssetResponse assetResponse = null; - - PrivateKey privateKey; - - try { - - PrivateKeyStore privateKeyStore = PrivateKeyStore.getPrivateKeyStore(); - privateKey = privateKeyStore.getKey(portalTokenId); - - if (privateKey != null) { - info("Found private key for token " + portalTokenId); - } else { - info("Could not find private key for token " + portalTokenId); - } - - info("2.a. Getting the cert(s) from the service"); - assetResponse = getOA4MPService().getCert(token, verifier); - - certificates = assetResponse.getX509Certificates(); - - } catch (Throwable t) { - warn("2.a. Exception from the server: " + t.getCause().getMessage()); - error("Exception while trying to get cert. message:" + t.getMessage()); - request.setAttribute("exception", t); - JSPUtil.fwd(request, response, configurationReader.getErrorUrl()); - return; - } - - info("2.b. Done! Displaying success page."); - - CertificateCredential certificateCredential = new CertificateCredential(); - - certificateCredential.setNotBefore(Utility.convertDateToString(certificates[0].getNotBefore())); //TODO check this is correct - certificateCredential.setNotAfter(Utility.convertDateToString(certificates[0].getNotAfter())); - certificateCredential.setCertificates(certificates); - certificateCredential.setPrivateKey(privateKey); - certificateCredential - .setCommunityUser(new CommunityUser(gatewayName, assetResponse.getUsername(), contactEmail)); - certificateCredential.setPortalUserName(portalUserName); - certificateCredential.setLifeTime(duration); - certificateCredential.setToken(portalTokenId); - - - certificateCredentialWriter.writeCredentials(certificateCredential); - - StringBuilder stringBuilder = new StringBuilder("Certificate for community user "); - stringBuilder.append(assetResponse.getUsername()).append(" successfully persisted."); - stringBuilder.append(" Certificate DN - ").append(certificates[0].getSubjectDN()); - - info(stringBuilder.toString()); - - if (isUrlInSameServer(configurationReader.getSuccessUrl())) { - - String contextPath = request.getContextPath(); - if (!contextPath.endsWith("/")) { - contextPath = contextPath + "/"; - } - request.setAttribute("action", contextPath); - request.setAttribute("tokenId", portalTokenId); - JSPUtil.fwd(request, response, configurationReader.getSuccessUrl()); - } else { - - String urlToRedirect = decorateUrlWithToken(configurationReader.getSuccessUrl(), portalTokenId); - - info("Redirecting to url - " + urlToRedirect); - - response.sendRedirect(urlToRedirect); - } - - info("2.a. Completely finished with delegation."); - - } - - private boolean isUrlInSameServer(String url) { - - return !(url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")); - - } - - private String decorateUrlWithToken(String url, String tokenId) { - - StringBuilder stringBuilder = new StringBuilder(url); - stringBuilder.append("?tokenId=").append(tokenId); - return stringBuilder.toString(); - } - - private Map<String, String> createQueryParameters(String gatewayName, String portalUserName, String portalEmail, - String tokenId) { - - String callbackUriKey = getEnvironment().getConstants().get(CALLBACK_URI_KEY); - ClientEnvironment clientEnvironment = (ClientEnvironment) getEnvironment(); - - String callbackUri = clientEnvironment.getCallback().toString(); - - StringBuilder stringBuilder = new StringBuilder(callbackUri); - - stringBuilder.append("?").append(CredentialStoreConstants.GATEWAY_NAME_QUERY_PARAMETER).append("=").append(gatewayName).append("&") - .append(CredentialStoreConstants.PORTAL_USER_QUERY_PARAMETER).append("=").append(portalUserName).append("&") - .append(CredentialStoreConstants.PORTAL_USER_EMAIL_QUERY_PARAMETER).append("=").append(portalEmail).append("&") - .append(CredentialStoreConstants.PORTAL_TOKEN_ID_ASSIGNED).append("=").append(tokenId); - - info("Callback URI is set to - " + stringBuilder.toString()); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put(callbackUriKey, stringBuilder.toString()); - - return parameters; - - } -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java deleted file mode 100644 index 3b70242..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/servlet/CredentialStoreStartServlet.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * - * 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.servlet; - -import edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment; -import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPResponse; -import edu.uiuc.ncsa.myproxy.oa4mp.client.OA4MPService; -import edu.uiuc.ncsa.myproxy.oa4mp.client.servlet.ClientServlet; -import edu.uiuc.ncsa.security.servlet.JSPUtil; -import org.apache.airavata.credential.store.store.CredentialStoreException; -import org.apache.airavata.credential.store.util.ConfigurationReader; -import org.apache.airavata.credential.store.util.CredentialStoreConstants; -import org.apache.airavata.credential.store.util.PrivateKeyStore; -import org.apache.airavata.credential.store.util.TokenGenerator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.URI; -import java.util.HashMap; -import java.util.Map; - -import static edu.uiuc.ncsa.myproxy.oa4mp.client.ClientEnvironment.CALLBACK_URI_KEY; - -/** - * When portal initiate a request to get credentials it will hit this servlet. - */ -public class CredentialStoreStartServlet extends ClientServlet { - - private static ConfigurationReader configurationReader = null; - - private static Logger log = LoggerFactory.getLogger(CredentialStoreStartServlet.class); - private OA4MPService oa4mpService; - - protected String decorateURI(URI inputURI, Map<String, String> parameters) { - - if (parameters.isEmpty()) { - return inputURI.toString(); - } - - String stringUri = inputURI.toString(); - StringBuilder stringBuilder = new StringBuilder(stringUri); - - boolean isFirst = true; - - for (Map.Entry<String, String> entry : parameters.entrySet()) { - if (isFirst) { - stringBuilder.append("?"); - isFirst = false; - } else { - stringBuilder.append("&"); - } - - stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()); - } - - return stringBuilder.toString(); - - } - - public void init() throws ServletException { - - super.init(); - - try { - if (configurationReader == null) { - configurationReader = new ConfigurationReader(); - } - } catch (CredentialStoreException e) { - throw new ServletException(e); - } - - } - - @Override - public OA4MPService getOA4MPService() { - return oa4mpService; - } - - @Override - public void loadEnvironment() throws IOException { - environment = getConfigurationLoader().load(); - oa4mpService = new OA4MPService((ClientEnvironment) environment); - } - - @Override - protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable { - - String gatewayName - = request.getParameter(CredentialStoreConstants.GATEWAY_NAME_QUERY_PARAMETER); - String portalUserName - = request.getParameter(CredentialStoreConstants.PORTAL_USER_QUERY_PARAMETER); - String contactEmail - = request.getParameter(CredentialStoreConstants.PORTAL_USER_EMAIL_QUERY_PARAMETER); - String associatedToken = TokenGenerator.generateToken(gatewayName, portalUserName); - - if (gatewayName == null) { - JSPUtil.handleException(new RuntimeException("Please specify a gateway name."), request, response, - configurationReader.getErrorUrl()); - return; - } - - if (portalUserName == null) { - JSPUtil.handleException(new RuntimeException("Please specify a portal user name."), request, response, - configurationReader.getErrorUrl()); - return; - } - - if (contactEmail == null) { - JSPUtil.handleException(new RuntimeException("Please specify a contact email address for community" - + " user account."), request, response, configurationReader.getErrorUrl()); - return; - } - - log.info("1.a. Starting transaction"); - OA4MPResponse gtwResp; - - Map<String, String> queryParameters = new HashMap<String, String>(); - queryParameters.put(CredentialStoreConstants.GATEWAY_NAME_QUERY_PARAMETER, gatewayName); - queryParameters.put(CredentialStoreConstants.PORTAL_USER_QUERY_PARAMETER, portalUserName); - queryParameters.put(CredentialStoreConstants.PORTAL_USER_EMAIL_QUERY_PARAMETER, contactEmail); - queryParameters.put(CredentialStoreConstants.PORTAL_TOKEN_ID_ASSIGNED, associatedToken); - - Map<String, String> additionalParameters = new HashMap<String, String>(); - - if (getOA4MPService() == null) { - loadEnvironment(); - } - - String modifiedCallbackUri = decorateURI(getOA4MPService().getEnvironment().getCallback(), queryParameters); - - info("The modified callback URI - " + modifiedCallbackUri); - - additionalParameters.put(getEnvironment().getConstants().get(CALLBACK_URI_KEY), modifiedCallbackUri); - - try { - gtwResp = getOA4MPService().requestCert(additionalParameters); - - // Private key in store - PrivateKeyStore privateKeyStore = PrivateKeyStore.getPrivateKeyStore(); - privateKeyStore.addKey(associatedToken, gtwResp.getPrivateKey()); - - } catch (Throwable t) { - JSPUtil.handleException(t, request, response, configurationReader.getErrorUrl()); - return; - } - log.info("1.b. Got response. Creating page with redirect for " + gtwResp.getRedirect().getHost()); - // Normally, we'd just do a redirect, but we will put up a page and show the redirect to the user. - // The client response contains the generated private key as well - // In a real application, the private key would be stored. This, however, exceeds the scope of this - // sample application -- all we need to do to complete the process is send along the redirect url. - - request.setAttribute(REDIR, REDIR); - request.setAttribute("redirectUrl", gtwResp.getRedirect().toString()); - request.setAttribute(ACTION_KEY, ACTION_KEY); - request.setAttribute("action", ACTION_REDIRECT_VALUE); - log.info("1.b. Showing redirect page."); - JSPUtil.fwd(request, response, configurationReader.getPortalRedirectUrl()); - - } -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java deleted file mode 100644 index ab96be4..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * - * 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; - -import org.apache.airavata.credential.store.credential.AuditInfo; -import org.apache.airavata.credential.store.credential.Credential; - -import java.util.List; - -/** - * This interface provides an API for Credential Store. Provides methods to manipulate credential store data. - */ -public interface CredentialReader { - - /** - * Retrieves the credential from the credential store. - * - * @param gatewayId - * The gateway id - * @param tokenId - * The token id associated with the credential - * @return The Credential object associated with the token. - * @throws CredentialStoreException - * If an error occurred while retrieving a credential. - */ - Credential getCredential(String gatewayId, String tokenId) throws CredentialStoreException; - - /** - * Gets the admin portal user name who retrieved given community user for given portal user name. - * - * @param gatewayName - * The gateway name - * @param tokenId - * The issued token id. - * @return The portal user name who requested given community user credentials. - */ - String getPortalUser(String gatewayName, String tokenId) throws CredentialStoreException; - - /** - * Gets audit information related to given gateway name and community user name. - * - * @param gatewayName - * The gateway name. - * @param tokenId - * The community user name. - * @return CertificateAuditInfo object. - */ - AuditInfo getAuditInfo(String gatewayName, String tokenId) throws CredentialStoreException; - - /** - * Gets all the credential records. - * @return All credential records as a list - * @throws CredentialStoreException If an error occurred while retrieving credentials. - */ - public List<Credential> getAllCredentials() throws CredentialStoreException; - - public List<Credential> getAllCredentialsPerGateway(String gatewayId) throws CredentialStoreException; - - public List<Credential> getAllCredentialsPerUser(String userName) throws CredentialStoreException; - /** - * Updates the community user contact email address. - * - * @param gatewayName - * The gateway name. - * @param communityUser - * The community user name. - * @param email - * The new email address. - */ - void updateCommunityUserEmail(String gatewayName, String communityUser, String email) - throws CredentialStoreException; - - /** - * Will remove credentials for the given gateway id and community user. - * - * @param gatewayName - * The gateway Id - * @param tokenId - * The issued token id. - * @throws CredentialStoreException - * If an error occurred while retrieving data. - */ - void removeCredentials(String gatewayName, String tokenId) throws CredentialStoreException; - - /** - * Retrieves gatewayID from the credential store. - * - * @param tokenId - * The token id associated with the credential - * @return The Credential object associated with the token. - * @throws CredentialStoreException - * If an error occurred while retrieving a credential. - */ - String getGatewayID(String tokenId) throws CredentialStoreException; - -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReaderFactory.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReaderFactory.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReaderFactory.java deleted file mode 100644 index f4b5e21..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialReaderFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * 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; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.DBUtil; -import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl; - -/** - * Factory class to create credential store readers. - */ -public class CredentialReaderFactory { - - /** - * Creates a credential reader using supplied database configurations. - * @param dbUti The database configurations. - * @return CredentialReader object. - */ - public static CredentialReader createCredentialStoreReader(DBUtil dbUti) throws ApplicationSettingsException { - return new CredentialReaderImpl(dbUti); - } - - /** - * Creates credential reader using default configurations for credential store database. - * @return The credential reader. - * @throws ClassNotFoundException If an error occurred while instantiating jdbc driver - * @throws ApplicationSettingsException If an error occurred while reading database configurations. - * @throws InstantiationException If an error occurred while instantiating jdbc driver - * @throws IllegalAccessException A security exception accessing jdbc driver. - */ - public static CredentialReader createCredentialStoreReader() throws ClassNotFoundException, - ApplicationSettingsException, InstantiationException, IllegalAccessException { - return new CredentialReaderImpl(DBUtil.getCredentialStoreDBUtil()); - } -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialStoreException.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialStoreException.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialStoreException.java deleted file mode 100644 index 07bed10..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialStoreException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * 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; - -/** - * An exception class for credential store. - */ -public class CredentialStoreException extends Exception { - - public CredentialStoreException() { - super(); - } - - public CredentialStoreException(String s) { - super(s); - } - - public CredentialStoreException(String s, Throwable throwable) { - super(s, throwable); - } -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialWriter.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialWriter.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialWriter.java deleted file mode 100644 index 05ae9fe..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/CredentialWriter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * 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; - -import org.apache.airavata.credential.store.credential.Credential; - -/** - * The entity who's writing credentials to DB will use this interface. - */ -public interface CredentialWriter { - - /** - * Writes given credentials to a persistent storage. - * - * @param credential - * The credentials implementation. - */ - void writeCredentials(Credential credential) throws CredentialStoreException; - -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CertificateCredentialWriter.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CertificateCredentialWriter.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CertificateCredentialWriter.java deleted file mode 100644 index 8b96187..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CertificateCredentialWriter.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * - * 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.CommunityUser; -import org.apache.airavata.credential.store.credential.Credential; -import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential; -import org.apache.airavata.credential.store.store.impl.db.CommunityUserDAO; -import org.apache.airavata.credential.store.store.impl.db.CredentialsDAO; -import org.apache.airavata.credential.store.store.CredentialStoreException; -import org.apache.airavata.credential.store.store.CredentialWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.sql.Connection; -import java.sql.SQLException; - -/** - * Writes certificate credentials to database. - */ -public class CertificateCredentialWriter implements CredentialWriter { - - private CredentialsDAO credentialsDAO; - private CommunityUserDAO communityUserDAO; - - protected static Logger log = LoggerFactory.getLogger(CertificateCredentialWriter.class); - - private DBUtil dbUtil; - - public CertificateCredentialWriter(DBUtil dbUtil) throws ApplicationSettingsException { - - this.dbUtil = dbUtil; - - this.credentialsDAO = new CredentialsDAO(ApplicationSettings.getCredentialStoreKeyStorePath(), - ApplicationSettings.getCredentialStoreKeyAlias(), new DefaultKeyStorePasswordCallback()); - - communityUserDAO = new CommunityUserDAO(); - } - - public void writeCredentials(Credential credential) throws CredentialStoreException { - - CertificateCredential certificateCredential = (CertificateCredential) credential; - - Connection connection = null; - - try { - - connection = dbUtil.getConnection(); - // Write community user - writeCommunityUser(certificateCredential.getCommunityUser(), credential.getToken(), connection); - // First delete existing credentials - credentialsDAO.deleteCredentials(certificateCredential.getCommunityUser().getGatewayName(), - certificateCredential.getToken(), connection); - // Add the new certificate - credentialsDAO.addCredentials(certificateCredential.getCommunityUser().getGatewayName(), credential, - connection); - - if (!connection.getAutoCommit()) { - connection.commit(); - } - - } catch (SQLException e) { - if (connection != null) { - try { - connection.rollback(); - } catch (SQLException e1) { - log.error("Unable to rollback transaction", e1); - } - } - throw new CredentialStoreException("Unable to retrieve database connection.", e); - } finally { - DBUtil.cleanup(connection); - } - - } - - public void writeCommunityUser(CommunityUser communityUser, String token, Connection connection) - throws CredentialStoreException { - - // First delete existing community user - communityUserDAO.deleteCommunityUserByToken(communityUser, token, connection); - - // Persist new community user - communityUserDAO.addCommunityUser(communityUser, token, connection); - - } - - /* - * TODO Remove later - If we dont need to expose this in the interface public void writeCommunityUser(CommunityUser - * communityUser, String token) throws CredentialStoreException { - * - * Connection connection = null; try { connection = dbUtil.getConnection(); writeCommunityUser(communityUser, token, - * connection); - * - * } catch (SQLException e) { throw new CredentialStoreException("Unable to retrieve database connection.", e); } - * finally { DBUtil.cleanup(connection); } } - */ -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java deleted file mode 100644 index a7dded3..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * - * 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.CommunityUser; -import org.apache.airavata.credential.store.credential.Credential; -import org.apache.airavata.credential.store.credential.impl.certificate.CertificateAuditInfo; -import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential; -import org.apache.airavata.credential.store.store.CredentialReader; -import org.apache.airavata.credential.store.store.impl.db.CredentialsDAO; -import org.apache.airavata.credential.store.store.CredentialStoreException; - -import java.io.Serializable; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.List; - -/** - * Credential store API implementation. - */ -public class CredentialReaderImpl implements CredentialReader, Serializable { - - private CredentialsDAO credentialsDAO; - - private DBUtil dbUtil; - - public CredentialReaderImpl(DBUtil dbUtil) throws ApplicationSettingsException { - - this.credentialsDAO = new CredentialsDAO(ApplicationSettings.getCredentialStoreKeyStorePath(), - ApplicationSettings.getCredentialStoreKeyAlias(), new DefaultKeyStorePasswordCallback()); - - this.dbUtil = dbUtil; - } - - private Connection getConnection() throws CredentialStoreException { - try { - return this.dbUtil.getConnection(); - } catch (SQLException e) { - throw new CredentialStoreException("Unable to retrieve database connection.", e); - } - } - - @Override - public Credential getCredential(String gatewayId, String tokenId) throws CredentialStoreException { - - Connection connection = getConnection(); - - try { - return this.credentialsDAO.getCredential(gatewayId, tokenId, connection); - } finally { - DBUtil.cleanup(connection); - } - } - - public List<Credential> getAllCredentials() throws CredentialStoreException { - - Connection connection = getConnection(); - - try { - return this.credentialsDAO.getCredentials(connection); - } finally { - DBUtil.cleanup(connection); - } - - } - - @Override - public List<Credential> getAllCredentialsPerGateway(String gatewayId) throws CredentialStoreException { - Connection connection = getConnection(); - - try { - return this.credentialsDAO.getCredentials(gatewayId, connection); - } finally { - DBUtil.cleanup(connection); - } - } - - @Override - public List<Credential> getAllCredentialsPerUser(String userName) throws CredentialStoreException { - return null; - } - - 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(); - } - - public CertificateAuditInfo getAuditInfo(String gatewayName, String tokenId) throws CredentialStoreException { - - Connection connection = getConnection(); - - CertificateAuditInfo certificateAuditInfo; - - try { - - CertificateCredential certificateCredential = (CertificateCredential) this.credentialsDAO.getCredential( - gatewayName, tokenId, connection); - - certificateAuditInfo = new CertificateAuditInfo(); - - CommunityUser retrievedUser = certificateCredential.getCommunityUser(); - certificateAuditInfo.setCommunityUserName(retrievedUser.getUserName()); - certificateAuditInfo.setCredentialLifeTime(certificateCredential.getLifeTime()); - certificateAuditInfo.setCredentialsRequestedTime(certificateCredential.getCertificateRequestedTime()); - certificateAuditInfo.setGatewayName(gatewayName); - certificateAuditInfo.setNotAfter(certificateCredential.getNotAfter()); - certificateAuditInfo.setNotBefore(certificateCredential.getNotBefore()); - certificateAuditInfo.setPortalUserName(certificateCredential.getPortalUserName()); - - } finally { - DBUtil.cleanup(connection); - } - - return certificateAuditInfo; - } - - public void updateCommunityUserEmail(String gatewayName, String communityUser, String email) - throws CredentialStoreException { - // TODO - } - - public void removeCredentials(String gatewayName, String tokenId) throws CredentialStoreException { - - Connection connection = getConnection(); - - try { - credentialsDAO.deleteCredentials(gatewayName, tokenId, connection); - } finally { - DBUtil.cleanup(connection); - } - - } - - @Override - public String getGatewayID(String tokenId) throws CredentialStoreException { - Connection connection = getConnection(); - try { - return this.credentialsDAO.getGatewayID(tokenId, connection); - } finally { - DBUtil.cleanup(connection); - } - } - -} http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/488b772f/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java ---------------------------------------------------------------------- diff --git a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java deleted file mode 100644 index ad4f6b3..0000000 --- a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/SSHCredentialWriter.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * 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 java.sql.Connection; -import java.sql.SQLException; - -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.ssh.SSHCredential; -import org.apache.airavata.credential.store.store.CredentialStoreException; -import org.apache.airavata.credential.store.store.CredentialWriter; -import org.apache.airavata.credential.store.store.impl.db.CredentialsDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Writes SSH credentials to database. - */ -public class SSHCredentialWriter implements CredentialWriter { - - private CredentialsDAO credentialsDAO; - private DBUtil dbUtil; - - protected static Logger logger = LoggerFactory.getLogger(SSHCredentialWriter.class); - - public SSHCredentialWriter(DBUtil dbUtil) throws ApplicationSettingsException { - this.dbUtil = dbUtil; - this.credentialsDAO = new CredentialsDAO(ApplicationSettings.getCredentialStoreKeyStorePath(), - ApplicationSettings.getCredentialStoreKeyAlias(), new DefaultKeyStorePasswordCallback()); - - } - - public void writeCredentials(Credential credential) throws CredentialStoreException { - - SSHCredential sshCredential = (SSHCredential) credential; - Connection connection = null; - - try { - connection = dbUtil.getConnection(); - // First delete existing credentials - credentialsDAO.deleteCredentials(sshCredential.getGateway(), sshCredential.getToken(), connection); - // Add the new certificate - credentialsDAO.addCredentials(sshCredential.getGateway(), credential, connection); - - if (!connection.getAutoCommit()) { - connection.commit(); - } - - } 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); - } - - } - -}
