Search in sources :

Example 11 with AuthzToken

use of org.apache.airavata.model.security.AuthzToken in project airavata by apache.

the class SecureClient method main.

public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(System.in);
    // register client or use existing client
    System.out.println("");
    System.out.println("Please select from the following options:");
    System.out.println("1. Register the client as an OAuth application.");
    System.out.println("2. Client is already registered. Use the existing credentials.");
    String opInput = scanner.next();
    int option = Integer.valueOf(opInput.trim());
    String consumerId = null;
    String consumerSecret = null;
    if (option == 1) {
        // register OAuth application - this happens once during initialization of the gateway.
        /**
         **********************Start obtaining input from user****************************
         */
        System.out.println("");
        System.out.println("Registering an OAuth application representing the client....");
        System.out.println("Please enter following information as you prefer, or use defaults.");
        System.out.println("OAuth application name: (default:" + Properties.appName + ", press 'd' to use default value.)");
        String appNameInput = scanner.next();
        String appName = null;
        if (appNameInput.trim().equals("d")) {
            appName = Properties.appName;
        } else {
            appName = appNameInput.trim();
        }
        System.out.println("Consumer Id: (default:" + Properties.consumerID + ", press 'd' to use default value.)");
        String consumerIdInput = scanner.next();
        if (consumerIdInput.trim().equals("d")) {
            consumerId = Properties.consumerID;
        } else {
            consumerId = consumerIdInput.trim();
        }
        System.out.println("Consumer Secret: (default:" + Properties.consumerSecret + ", press 'd' to use default value.)");
        String consumerSecInput = scanner.next();
        if (consumerSecInput.trim().equals("d")) {
            consumerSecret = Properties.consumerSecret;
        } else {
            consumerSecret = consumerSecInput.trim();
        }
        /**
         ********************* Perform registration of the client as an OAuth app**************************
         */
        try {
            ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
            OAuthAppRegisteringClient authAppRegisteringClient = new OAuthAppRegisteringClient(Properties.oauthAuthzServerURL, Properties.adminUserName, Properties.adminPassword, configContext);
            OAuthConsumerAppDTO appDTO = authAppRegisteringClient.registerApplication(appName, consumerId, consumerSecret);
            /**
             ******************* Complete registering the client **********************************************
             */
            System.out.println("");
            System.out.println("Registered OAuth app successfully. Following is app's details:");
            System.out.println("App Name: " + appDTO.getApplicationName());
            System.out.println("Consumer ID: " + appDTO.getOauthConsumerKey());
            System.out.println("Consumer Secret: " + appDTO.getOauthConsumerSecret());
            System.out.println("");
        } catch (AiravataSecurityException e) {
            e.printStackTrace();
            throw e;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    } else if (option == 2) {
        System.out.println("");
        System.out.println("Enter Consumer Id: ");
        consumerId = scanner.next().trim();
        System.out.println("Enter Consumer Secret: ");
        consumerSecret = scanner.next().trim();
    }
    // obtain OAuth access token
    /**
     **********************Start obtaining input from user****************************
     */
    System.out.println("");
    System.out.println("Please select the preferred grant type: (or press d to use the default option" + Properties.grantType + ")");
    System.out.println("1. Resource Owner Password Credential.");
    System.out.println("2. Client Credential.");
    String grantTypeInput = scanner.next().trim();
    int grantType = 0;
    if (grantTypeInput.equals("d")) {
        grantType = Properties.grantType;
    } else {
        grantType = Integer.valueOf(grantTypeInput);
    }
    String userName = null;
    String password = null;
    if (grantType == 1) {
        System.out.println("Obtaining OAuth access token via 'Resource Owner Password' grant type....");
        System.out.println("Please enter following information as you prefer, or use defaults.");
        System.out.println("End user's name: (default:" + Properties.userName + ", press 'd' to use default value.)");
        String userNameInput = scanner.next();
        if (userNameInput.trim().equals("d")) {
            userName = Properties.userName;
        } else {
            userName = userNameInput.trim();
        }
        System.out.println("End user's password: (default:" + Properties.password + ", press 'd' to use default value.)");
        String passwordInput = scanner.next();
        if (passwordInput.trim().equals("d")) {
            password = Properties.password;
        } else {
            password = passwordInput.trim();
        }
    } else if (grantType == 2) {
        System.out.println("");
        System.out.println("Please enter the user name to be passed: ");
        String userNameInput = scanner.next();
        userName = userNameInput.trim();
        System.out.println("");
        System.out.println("Obtaining OAuth access token via 'Client Credential' grant type...' grant type....");
    }
    /**
     *************************** Finish obtaining input from user******************************************
     */
    try {
        // obtain the OAuth token for the specified end user.
        String accessToken = new OAuthTokenRetrievalClient().retrieveAccessToken(consumerId, consumerSecret, userName, password, grantType);
        System.out.println("");
        System.out.println("OAuth access token is: " + accessToken);
        // invoke Airavata API by the SecureClient, on behalf of the user.
        System.out.println("");
        System.out.println("Invoking Airavata API...");
        System.out.println("Enter the access token to be used: (default:" + accessToken + ", press 'd' to use default value.)");
        String accessTokenInput = scanner.next();
        String acTk = null;
        if (accessTokenInput.trim().equals("d")) {
            acTk = accessToken;
        } else {
            acTk = accessTokenInput.trim();
        }
        // obtain as input, the method to be invoked
        System.out.println("");
        System.out.println("Enter the number corresponding to the method to be invoked: ");
        System.out.println("1. getAPIVersion");
        System.out.println("2. getAllAppModules");
        System.out.println("3. addGateway");
        String methodNumberString = scanner.next();
        int methodNumber = Integer.valueOf(methodNumberString.trim());
        Airavata.Client client = createAiravataClient(Properties.SERVER_HOST, Properties.SERVER_PORT);
        AuthzToken authzToken = new AuthzToken();
        authzToken.setAccessToken(acTk);
        Map<String, String> claimsMap = new HashMap<>();
        claimsMap.put("userName", userName);
        claimsMap.put("email", "hasini@gmail.com");
        authzToken.setClaimsMap(claimsMap);
        if (methodNumber == 1) {
            String version = client.getAPIVersion(authzToken);
            System.out.println("");
            System.out.println("Airavata API version: " + version);
            System.out.println("");
        } else if (methodNumber == 2) {
            System.out.println("");
            System.out.println("Enter the gateway id: ");
            String gatewayId = scanner.next().trim();
            List<ApplicationModule> appModules = client.getAllAppModules(authzToken, gatewayId);
            System.out.println("Output of getAllAppModuels: ");
            for (ApplicationModule appModule : appModules) {
                System.out.println(appModule.getAppModuleName());
            }
            System.out.println("");
            System.out.println("");
        } else if (methodNumber == 3) {
            System.out.println("");
            System.out.println("Enter the gateway id: ");
            String gatewayId = scanner.next().trim();
            Gateway gateway = new Gateway(gatewayId, GatewayApprovalStatus.REQUESTED);
            gateway.setDomain("airavata.org");
            gateway.setEmailAddress("airavata@apache.org");
            gateway.setGatewayName("airavataGW");
            String output = client.addGateway(authzToken, gateway);
            System.out.println("");
            System.out.println("Output of addGateway: " + output);
            System.out.println("");
        }
    } catch (InvalidRequestException e) {
        e.printStackTrace();
    } catch (TException e) {
        e.printStackTrace();
    } catch (AiravataSecurityException e) {
        e.printStackTrace();
    }
}
Also used : TException(org.apache.thrift.TException) Scanner(java.util.Scanner) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) HashMap(java.util.HashMap) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) TException(org.apache.thrift.TException) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException) ApplicationModule(org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule) Gateway(org.apache.airavata.model.workspace.Gateway) AuthzToken(org.apache.airavata.model.security.AuthzToken) List(java.util.List) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException) Airavata(org.apache.airavata.api.Airavata)

Example 12 with AuthzToken

use of org.apache.airavata.model.security.AuthzToken in project airavata by apache.

the class RegisterOGCEUS3Application method registerApplicationDeployment.

public static void registerApplicationDeployment() {
    try {
        System.out.println("#### Registering Application Deployments on Stampede #### \n");
        // Register Stampede
        String ultascanStamplede = airavataClient.registerApplicationDeployment(new AuthzToken(""), DEFAULT_GATEWAY, RegisterSampleApplicationsUtils.createApplicationDeployment(ultrascanModuleId, stampedeResourceId, "/home1/01437/ogce/xsede_apps/ultrascan/bin/us_mpi_analysis", ApplicationParallelismType.MPI, "ultrascan OGCE application", null, null, null));
        System.out.println("Ultrascan on stampede deployment Id " + ultascanStamplede);
        String ultascanTrestles = airavataClient.registerApplicationDeployment(new AuthzToken(""), DEFAULT_GATEWAY, RegisterSampleApplicationsUtils.createApplicationDeployment(ultrascanModuleId, trestlesResourceId, "/home/ogce/xsede_app/ultrascan/bin/us_mpi_analysis", ApplicationParallelismType.MPI, "ultrascan OGCE application", null, null, null));
        System.out.println("Ultrascan on trestles deployment Id " + ultascanTrestles);
    // String ultascanLonestar = airavataClient.registerApplicationDeployment(RegisterSampleApplicationsUtils.createApplicationDeployment(ultrascanModuleId,
    // lonestarResourceId, "/home1/01623/us3/bin/us_mpi_analysis", ApplicationParallelismType.MPI, "ultrascan application"));
    // System.out.println("Ultrascan on lonestar deployment Id " + ultascanLonestar);
    // String ultascanAlamo = airavataClient.registerApplicationDeployment(RegisterSampleApplicationsUtils.createApplicationDeployment(ultrascanModuleId,
    // alamoResourceId, "/home/us3/bin/us_mpi_analysis.sh", ApplicationParallelismType.MPI, "ultrascan application"));
    // System.out.println("Ultrascan on alamo deployment Id " + ultascanAlamo);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AuthzToken(org.apache.airavata.model.security.AuthzToken) TException(org.apache.thrift.TException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException)

Example 13 with AuthzToken

use of org.apache.airavata.model.security.AuthzToken in project airavata by apache.

the class RegisterOGCEUS3Application method registerComputeHost.

public static String registerComputeHost(String hostName, String hostDesc, ResourceJobManagerType resourceJobManagerType, String monitoringEndPoint, String jobMangerBinPath, SecurityProtocol securityProtocol, int portNumber, String jobManagerCommand) throws TException {
    ComputeResourceDescription computeResourceDescription = RegisterSampleApplicationsUtils.createComputeResourceDescription(hostName, hostDesc, null, null);
    String computeResourceId = airavataClient.registerComputeResource(new AuthzToken(""), computeResourceDescription);
    if (computeResourceId.isEmpty())
        throw new AiravataClientException();
    ResourceJobManager resourceJobManager = RegisterSampleApplicationsUtils.createResourceJobManager(resourceJobManagerType, monitoringEndPoint, jobMangerBinPath, null);
    if (jobManagerCommand != null) {
        Map<JobManagerCommand, String> jobManagerCommandStringMap = new HashMap<JobManagerCommand, String>();
        jobManagerCommandStringMap.put(JobManagerCommand.SUBMISSION, jobManagerCommand);
        resourceJobManager.setJobManagerCommands(jobManagerCommandStringMap);
    }
    SSHJobSubmission sshJobSubmission = new SSHJobSubmission();
    sshJobSubmission.setResourceJobManager(resourceJobManager);
    sshJobSubmission.setSecurityProtocol(securityProtocol);
    sshJobSubmission.setSshPort(portNumber);
    airavataClient.addSSHJobSubmissionDetails(new AuthzToken(""), computeResourceId, 1, sshJobSubmission);
    SCPDataMovement scpDataMovement = new SCPDataMovement();
    scpDataMovement.setSecurityProtocol(securityProtocol);
    scpDataMovement.setSshPort(portNumber);
    airavataClient.addSCPDataMovementDetails(new AuthzToken(""), computeResourceId, DMType.COMPUTE_RESOURCE, 1, scpDataMovement);
    return computeResourceId;
}
Also used : SCPDataMovement(org.apache.airavata.model.data.movement.SCPDataMovement) HashMap(java.util.HashMap) AuthzToken(org.apache.airavata.model.security.AuthzToken) AiravataClientException(org.apache.airavata.model.error.AiravataClientException)

Example 14 with AuthzToken

use of org.apache.airavata.model.security.AuthzToken in project airavata by apache.

the class RegisterSampleApplications method registerLocalHost.

public static void registerLocalHost() {
    try {
        System.out.println("\n #### Registering Localhost Computational Resource #### \n");
        ComputeResourceDescription computeResourceDescription = RegisterSampleApplicationsUtils.createComputeResourceDescription("localhost", "LocalHost", null, null);
        List<String> hostAliases = new ArrayList<String>();
        hostAliases.add("alias1");
        hostAliases.add("alias2");
        computeResourceDescription.setHostAliases(hostAliases);
        localhostId = airavataClient.registerComputeResource(new AuthzToken(""), computeResourceDescription);
        ResourceJobManager resourceJobManager = RegisterSampleApplicationsUtils.createResourceJobManager(ResourceJobManagerType.FORK, null, null, null);
        LOCALSubmission submission = new LOCALSubmission();
        submission.setResourceJobManager(resourceJobManager);
        airavataClient.addLocalSubmissionDetails(new AuthzToken(""), localhostId, 1, submission);
        System.out.println("LocalHost Resource Id is " + localhostId);
    } catch (TException e) {
        e.printStackTrace();
    }
}
Also used : TException(org.apache.thrift.TException) AuthzToken(org.apache.airavata.model.security.AuthzToken)

Example 15 with AuthzToken

use of org.apache.airavata.model.security.AuthzToken in project airavata by apache.

the class RegisterSampleApplications method registerGromacsInterface.

public void registerGromacsInterface() {
    try {
        System.out.println("#### Registering Gromacs Interface #### \n");
        List<String> appModules = new ArrayList<String>();
        appModules.add(gromacsModuleId);
        InputDataObjectType input1 = RegisterSampleApplicationsUtils.createAppInput("Portable_Input_Binary_File", null, DataType.URI, null, 1, true, true, false, "Coordinates velocities, molecular topology and simulation parameters - pdb1y6l-EM-vacuum.tpr", null);
        InputDataObjectType input2 = RegisterSampleApplicationsUtils.createAppInput("GROMOS_Coordinate_File", null, DataType.URI, null, 2, true, true, false, "Trajectory Coordinates Molecular Structure in Gromos87 format - pdb1y6l-EM-vacuum.gro", null);
        List<InputDataObjectType> applicationInputs = new ArrayList<InputDataObjectType>();
        applicationInputs.add(input1);
        applicationInputs.add(input2);
        OutputDataObjectType output1 = RegisterSampleApplicationsUtils.createAppOutput("GROMACS_Execution_Log", null, DataType.URI, true, true, null);
        OutputDataObjectType output2 = RegisterSampleApplicationsUtils.createAppOutput("Full_Precision_Trajectory_file", null, DataType.URI, true, true, null);
        OutputDataObjectType output3 = RegisterSampleApplicationsUtils.createAppOutput("Portable_Energy_file", null, DataType.URI, true, true, null);
        OutputDataObjectType output4 = RegisterSampleApplicationsUtils.createAppOutput("STDOUT", null, DataType.STDOUT, true, true, null);
        OutputDataObjectType output5 = RegisterSampleApplicationsUtils.createAppOutput("STDERR", null, DataType.STDERR, true, true, null);
        List<OutputDataObjectType> applicationOutputs = new ArrayList<OutputDataObjectType>();
        applicationOutputs.add(output1);
        applicationOutputs.add(output2);
        applicationOutputs.add(output3);
        applicationOutputs.add(output4);
        applicationOutputs.add(output5);
        gromacsInterfaceId = airavataClient.registerApplicationInterface(new AuthzToken(""), DEFAULT_GATEWAY, RegisterSampleApplicationsUtils.createApplicationInterfaceDescription(gromacsName, gromacsDescription, appModules, applicationInputs, applicationOutputs));
        System.out.println("Gromacs Application Interface Id " + gromacsInterfaceId);
    } catch (TException e) {
        e.printStackTrace();
    }
}
Also used : TException(org.apache.thrift.TException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) AuthzToken(org.apache.airavata.model.security.AuthzToken)

Aggregations

AuthzToken (org.apache.airavata.model.security.AuthzToken)92 TException (org.apache.thrift.TException)71 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)46 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)44 ExperimentModel (org.apache.airavata.model.experiment.ExperimentModel)33 UserConfigurationDataModel (org.apache.airavata.model.experiment.UserConfigurationDataModel)28 ComputationalResourceSchedulingModel (org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)28 AiravataClientException (org.apache.airavata.model.error.AiravataClientException)15 Project (org.apache.airavata.model.workspace.Project)13 ArrayList (java.util.ArrayList)12 InvalidRequestException (org.apache.airavata.model.error.InvalidRequestException)8 HashMap (java.util.HashMap)7 AiravataSystemException (org.apache.airavata.model.error.AiravataSystemException)7 Gateway (org.apache.airavata.model.workspace.Gateway)6 CommandObject (org.apache.airavata.model.appcatalog.appdeployment.CommandObject)5 SCPDataMovement (org.apache.airavata.model.data.movement.SCPDataMovement)5 ComputeResourcePreference (org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)4 GatewayResourceProfile (org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile)4 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)2 JobSubmissionInterface (org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface)2