adding the user-profile migration module to develop branch
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/49afd997 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/49afd997 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/49afd997 Branch: refs/heads/develop Commit: 49afd997f2f30ccabb83a30059f0e4483553a640 Parents: d9a69ae Author: Anuj Bhandar <[email protected]> Authored: Mon Dec 12 15:51:57 2016 -0500 Committer: Anuj Bhandar <[email protected]> Committed: Mon Dec 12 15:51:57 2016 -0500 ---------------------------------------------------------------------- modules/user-profile-migration/pom.xml | 102 ++++++++++++++ .../apache/airavata/ISLoginCredentialsDAO.java | 59 ++++++++ .../apache/airavata/IdentityServerClient.java | 118 ++++++++++++++++ .../org/apache/airavata/MigrationManager.java | 141 +++++++++++++++++++ .../UserProfileAiravataThriftClient.java | 45 ++++++ .../org/apache/airavata/UserProfileDAO.java | 120 ++++++++++++++++ pom.xml | 1 + 7 files changed, 586 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/49afd997/modules/user-profile-migration/pom.xml ---------------------------------------------------------------------- diff --git a/modules/user-profile-migration/pom.xml b/modules/user-profile-migration/pom.xml new file mode 100644 index 0000000..faf0121 --- /dev/null +++ b/modules/user-profile-migration/pom.xml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--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. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>airavata</artifactId> + <groupId>org.apache.airavata</groupId> + <version>0.17-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>user-profile-migration</artifactId> + + <repositories> + <repository> + <id>wso2-maven2-repository</id> + <url>http://dist.wso2.org/maven2</url> + </repository> + <repository> + <id>apache-maven2-repo</id> + <name>Apache Maven2 Repository</name> + <url>http://repo1.maven.org/maven2/</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.axis2.wso2</groupId> + <artifactId>axis2</artifactId> + <version>1.6.1.wso2v1</version> + </dependency> + <dependency> + <groupId>org.wso2.securevault</groupId> + <artifactId>org.wso2.securevault</artifactId> + <version>1.0.0</version> + </dependency> + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.0.1</version> + </dependency> + <dependency> + <groupId>org.wso2.carbon</groupId> + <artifactId>org.wso2.carbon.um.ws.api.stub</artifactId> + <version>4.0.2</version> + </dependency> + <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.6</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>user-profile-stubs</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-commons</artifactId> + <version>0.17-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.airavata</groupId> + <artifactId>airavata-data-models</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + + <build> + <sourceDirectory>src/main/java</sourceDirectory> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <version>2.0</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + </plugins> + </build> + + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/49afd997/modules/user-profile-migration/src/main/java/org/apache/airavata/ISLoginCredentialsDAO.java ---------------------------------------------------------------------- diff --git a/modules/user-profile-migration/src/main/java/org/apache/airavata/ISLoginCredentialsDAO.java b/modules/user-profile-migration/src/main/java/org/apache/airavata/ISLoginCredentialsDAO.java new file mode 100644 index 0000000..871f823 --- /dev/null +++ b/modules/user-profile-migration/src/main/java/org/apache/airavata/ISLoginCredentialsDAO.java @@ -0,0 +1,59 @@ + +/* + * + * 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; + +public class ISLoginCredentialsDAO { + public String getGateway() { + return Gateway; + } + + public void setGateway(String gateway) { + Gateway = gateway; + } + + public String getLoginUserName() { + return loginUserName; + } + + public void setLoginUserName(String loginUserName) { + this.loginUserName = loginUserName; + } + + public String getLoginPassword() { + return loginPassword; + } + + public void setLoginPassword(String loginPassword) { + this.loginPassword = loginPassword; + } + + private String Gateway; + private String loginUserName; + private String loginPassword; + + public ISLoginCredentialsDAO(String gateway, String loginUserName, String loginPassword) { + Gateway = gateway; + this.loginUserName = loginUserName; + this.loginPassword = loginPassword; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/49afd997/modules/user-profile-migration/src/main/java/org/apache/airavata/IdentityServerClient.java ---------------------------------------------------------------------- diff --git a/modules/user-profile-migration/src/main/java/org/apache/airavata/IdentityServerClient.java b/modules/user-profile-migration/src/main/java/org/apache/airavata/IdentityServerClient.java new file mode 100644 index 0000000..c8cd0a0 --- /dev/null +++ b/modules/user-profile-migration/src/main/java/org/apache/airavata/IdentityServerClient.java @@ -0,0 +1,118 @@ +package org.apache.airavata; + +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.transport.http.HttpTransportProperties; +import org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceStub; + +import java.io.File; + +/* + * + * 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. + * + */ + + +public class IdentityServerClient { + /** + * Server url of the WSO2 Carbon Server + */ + private static String SEVER_URL = "URL for Identity server"; + + + public static RemoteUserStoreManagerServiceStub getAdminServiceClient(String adminUserName, String adminPassword, String adminService){ + + /** + * trust store path. this must contains server's certificate or Server's CA chain + */ + + /* The below code snippet is intentionally commented for the build to pass, + * because the private key and certificate file are not committed to GitHub, + * which are needed to run the client */ + +// String trustStore = System.getProperty("user.dir") + File.separator + +// "modules" + File.separator + "user-profile-migration" + File.separator + +// "src" + File.separator + "main" + File.separator + +// "resources" + File.separator + "wso2carbon.jks"; +// System.out.println("file path : " + trustStore); +// +// /** +// * Call to https://localhost:9443/services/ uses HTTPS protocol. +// * Therefore we to validate the server certificate or CA chain. The server certificate is looked up in the +// * trust store. +// * Following code sets what trust-store to look for and its JKs password. +// */ +// +// System.setProperty("javax.net.ssl.trustStore", trustStore ); +// +// System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); + + /** + * Axis2 configuration context + */ + ConfigurationContext configContext; + RemoteUserStoreManagerServiceStub adminStub; + + try { + + /** + * Create a configuration context. A configuration context contains information for + * axis2 environment. This is needed to create an axis2 service client + */ + configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); + + /** + * end point url with service name + */ +// String serviceEndPoint = SEVER_URL + "RemoteUserStoreManagerService"; + String serviceEndPoint = SEVER_URL + adminService; + + /** + * create stub and service client + */ + adminStub = new RemoteUserStoreManagerServiceStub(configContext, serviceEndPoint); + ServiceClient client = adminStub._getServiceClient(); + Options option = client.getOptions(); + + /** + * Setting a authenticated cookie that is received from Carbon server. + * If you have authenticated with Carbon server earlier, you can use that cookie, if + * it has not been expired + */ + option.setProperty(HTTPConstants.COOKIE_STRING, null); + + /** + * Setting basic auth headers for authentication for carbon server + */ + HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); + auth.setUsername(adminUserName); + auth.setPassword(adminPassword); + auth.setPreemptiveAuthentication(true); + option.setProperty(HTTPConstants.AUTHENTICATE, auth); + option.setManageSession(true); + return adminStub; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/49afd997/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java ---------------------------------------------------------------------- diff --git a/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java b/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java new file mode 100644 index 0000000..a5161cd --- /dev/null +++ b/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java @@ -0,0 +1,141 @@ +/* + * + * 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; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; +import org.apache.thrift.TException; +import org.wso2.carbon.um.ws.api.stub.ClaimValue; +import org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceStub; +import org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceUserStoreExceptionException; + +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.List; + +public class MigrationManager { + + private ArrayList<ISLoginCredentialsDAO> adminCredentials = new ArrayList<ISLoginCredentialsDAO>(); + + /*Add the credentials for all the tenants from which the profile should be migrated to Airavata DB*/ + + public void setISLoginCredentials(){ + adminCredentials.add(new ISLoginCredentialsDAO("prod.seagrid","UserName","Password")); + // new credential records here... + } + + /* Method used to fetch all the user profiles from the registered tenants */ + + public List<UserProfileDAO> getUserProfilesFromIS(){ + ArrayList<UserProfileDAO> userProfileList = new ArrayList<UserProfileDAO>(); + for(ISLoginCredentialsDAO creds:adminCredentials){ + RemoteUserStoreManagerServiceStub isClient = IdentityServerClient.getAdminServiceClient(creds.getLoginUserName(),creds.getLoginPassword(),"RemoteUserStoreManagerService"); + String[] userList; + System.out.println("Fetching User Profiles for " + creds.getGateway() + " tenant ..."); + try { + userList = isClient.getUserList("http://wso2.org/claims/givenname", "*", "default"); + System.out.println("FirstName\tLastName\tEmail\t\t\tuserName\tCountry\tOrganization\tphone"); + String[] claims = {"http://wso2.org/claims/givenname", + "http://wso2.org/claims/lastname", + "http://wso2.org/claims/emailaddress", + "http://wso2.org/claims/country", + "http://wso2.org/claims/organization", + "http://wso2.org/claims/mobile", + "http://wso2.org/claims/telephone", + "http://wso2.org/claims/streetaddress"}; + for (String user : userList) { + UserProfileDAO userProfile = new UserProfileDAO(); + ClaimValue[] retrievedClaimValues = isClient.getUserClaimValuesForClaims(user, claims, null); + List<String> phones = new ArrayList<String>(); + for(ClaimValue claim:retrievedClaimValues){ + if(claim.getClaimURI().equals(claims[0])){ + userProfile.setFirstName(claim.getValue()); + }else if(claim.getClaimURI().equals(claims[1])){ + userProfile.setLastName(claim.getValue()); + }else if(claim.getClaimURI().equals(claims[2])){ + userProfile.setEmail(claim.getValue()); + }else if(claim.getClaimURI().equals(claims[3])){ + userProfile.setCountry(claim.getValue()); + }else if(claim.getClaimURI().equals(claims[4])){ + userProfile.setOrganization(claim.getValue()); + }else if(claim.getClaimURI().equals(claims[5]) || claim.getClaimURI().equals(claims[6])){ + phones.add(claim.getValue()); + } else if(claim.getClaimURI().equals(claims[7])){ + userProfile.setAddress(claim.getValue()); + } + } + userProfile.setUserName(user); + userProfile.setGatewayID(creds.getGateway()); + userProfile.setPhones(phones); + System.out.println(userProfile.getFirstName()+"\t"+userProfile.getLastName()+"\t"+userProfile.getUserName()+"\t"+userProfile.getEmail()+"\t"+userProfile.getCountry()+"\t"+userProfile.getOrganization() + userProfile.getAddress()); + userProfileList.add(userProfile); + } + } catch (RemoteException e) { + System.out.println(e.getMessage()); + System.out.println(e.getCause()); + e.printStackTrace(); + } catch (RemoteUserStoreManagerServiceUserStoreExceptionException e) { + System.out.println(e.getMessage()); + System.out.println(e.getCause()); + e.printStackTrace(); + } + } + System.out.println("User profiles from all the tenant are retrieved ..."); + return userProfileList; + } + + /* Method used to migrate User profiles to Airavata DB by making a call to User profile thrift Service */ + private boolean migrateUserProfilesToAiravata(List<UserProfileDAO> ISProfileList) throws TException, ApplicationSettingsException { + System.out.println("Initiating migration to Airavata internal DB ..."); + UserProfileAiravataThriftClient objFactory = new UserProfileAiravataThriftClient(); + UserProfileCrudeService.Client client = objFactory.getRegistryServiceClient(); + UserProfile airavataUserProfile = new UserProfile(); + // Here are the data associations... + for(UserProfileDAO ISProfile : ISProfileList){ + airavataUserProfile.setUserName(ISProfile.getFirstName()+" "+ISProfile.getLastName()); + airavataUserProfile.setUserId(ISProfile.getUserName()); + airavataUserProfile.setGatewayId(ISProfile.getGatewayID()); + List<String> emails = new ArrayList<String>(); + emails.add(ISProfile.getEmail()); + airavataUserProfile.setEmails(emails); + airavataUserProfile.setHomeOrganization(ISProfile.getOrganization()); + airavataUserProfile.setPhones(ISProfile.getPhones()); + airavataUserProfile.setCountry(ISProfile.getCountry()); + client.addUserProfile(airavataUserProfile); + } + return false; + } + + public static void main(String[] args) { + MigrationManager migrationManager = new MigrationManager(); + migrationManager.setISLoginCredentials(); + List<UserProfileDAO> userProfileList = migrationManager.getUserProfilesFromIS(); + try { + migrationManager.migrateUserProfilesToAiravata(userProfileList); + } catch (TException e) { + e.printStackTrace(); + } catch (ApplicationSettingsException e) { + e.printStackTrace(); + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/49afd997/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java ---------------------------------------------------------------------- diff --git a/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java b/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java new file mode 100644 index 0000000..9e5568f --- /dev/null +++ b/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java @@ -0,0 +1,45 @@ +/* + * + * 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; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.registry.api.exception.RegistryServiceException; +import org.apache.airavata.userprofile.crude.cpi.UserProfileCrudeService; +import org.apache.airavata.userprofile.crude.cpi.client.UserProfileServiceClientFactory; +import org.apache.thrift.TException; + +import java.util.ArrayList; +import java.util.List; + +public class UserProfileAiravataThriftClient { + + public UserProfileCrudeService.Client getRegistryServiceClient() throws TException, ApplicationSettingsException { + final int serverPort = Integer.parseInt(ServerSettings.getRegistryServerPort()); + final String serverHost = ServerSettings.getRegistryServerHost(); + try { + return UserProfileServiceClientFactory.createRegistryClient(serverHost, serverPort); + } catch (RegistryServiceException e) { + throw new TException("Unable to create registry client...", e); + } + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/49afd997/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileDAO.java ---------------------------------------------------------------------- diff --git a/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileDAO.java b/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileDAO.java new file mode 100644 index 0000000..1edb7cf --- /dev/null +++ b/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileDAO.java @@ -0,0 +1,120 @@ +/* + * + * 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; + +import java.util.List; + +public class UserProfileDAO { + private String firstName; + private String lastName; + private String middleInitials; + private String userName; + private String email; + private String country; + private String organization; + private List<String> Phones; + private String gatewayID; + private String address; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + + public List<String> getPhones() { + return Phones; + } + + public void setPhones(List<String> phones) { + Phones = phones; + } + + public String getGatewayID() { + return gatewayID; + } + + public void setGatewayID(String gatewayID) { + this.gatewayID = gatewayID; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getOrganization() { + return organization; + } + + public void setOrganization(String organization) { + this.organization = organization; + } + + + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getMiddleInitials() { + return middleInitials; + } + + public void setMiddleInitials(String middleInitials) { + this.middleInitials = middleInitials; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/49afd997/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index f00aa4b..c019dce 100644 --- a/pom.xml +++ b/pom.xml @@ -636,6 +636,7 @@ <module>modules/sharing-registry</module> <module>modules/cluster-monitoring</module> <module>modules/registry-refactoring</module> + <module>modules/user-profile-migration</module> <!-- Deprecated Modules--> <!--<module>modules/integration-tests</module>--> <!--<module>modules/workflow-model</module>-->
