Search in sources :

Example 1 with OAuthConsumerAppDTO

use of org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO in project core-util by WSO2Telco.

the class UUIDPCRService method updateServiceProviderMap.

private void updateServiceProviderMap(String appId) throws PCRException {
    if (DEBUG)
        log.debug("Updating Service Provider Map");
    try {
        OAuthConsumerAppDTO apps = authApplicationData.getApplicationData(appId);
        if (DEBUG)
            log.debug("Application List recieved");
        if (apps == null) {
            log.error("Application data not found - updateServiceProviderMap");
            throw new PCRException("Null Application list - updateServiceProviderMap");
        }
        String callbackUrl = apps.getCallbackUrl();
        String sector = SectorUtil.getSectorIdFromUrl(callbackUrl);
        KeyValueBasedPcrDAOImpl keyValueBasedPcrDAOImpl = new KeyValueBasedPcrDAOImpl();
        keyValueBasedPcrDAOImpl.createNewSPEntry(sector, appId, true);
    } catch (Exception e) {
        log.error("error in retrieving application data - updateServiceProviderMap", e);
        throw new PCRException("error in retrieving application data - updateServiceProviderMap");
    }
}
Also used : PCRException(com.wso2telco.core.pcrservice.exception.PCRException) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) KeyValueBasedPcrDAOImpl(com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl) PCRException(com.wso2telco.core.pcrservice.exception.PCRException)

Example 2 with OAuthConsumerAppDTO

use of org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO in project core-util by WSO2Telco.

the class OAuthApplicationDataTest method test.

@Test
public void test() throws Exception {
    OAuthApplicationData applicationData = new OAuthApplicationData();
    String clientid = "qwwert";
    OAuthConsumerAppDTO apps = applicationData.getApplicationData(clientid);
}
Also used : OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) Test(org.junit.Test)

Example 3 with OAuthConsumerAppDTO

use of org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO 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 4 with OAuthConsumerAppDTO

use of org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO in project core-util by WSO2Telco.

the class OAuthApplicationData method getApplicationData.

public OAuthConsumerAppDTO getApplicationData(String appId) throws PCRException {
    OAuthConsumerAppDTO apps = null;
    OAuthAdminServiceStub oAuthAdminServiceStub;
    try {
        if (DEBUG)
            log.debug("initializing the o Auth Admin Service stub");
        Object stub = this.stubs.borrowObject();
        if (stub != null) {
            oAuthAdminServiceStub = (OAuthAdminServiceStub) stub;
            if (cookie != null) {
                oAuthAdminServiceStub._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie);
            }
            apps = oAuthAdminServiceStub.getOAuthApplicationData(appId);
            // apps = oAuthAdminServiceStub.getAllOAuthApplicationData();
            ServiceContext serviceContext = oAuthAdminServiceStub._getServiceClient().getLastOperationContext().getServiceContext();
            cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
        } else {
            log.warn("Stub initialization failed.");
        }
    } catch (Exception e) {
        log.error("error initializing the stub", e);
        throw new PCRException("error initializing the stub");
    }
    return apps;
}
Also used : OAuthAdminServiceStub(org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub) ServiceContext(org.apache.axis2.context.ServiceContext) PCRException(com.wso2telco.core.pcrservice.exception.PCRException) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) PCRException(com.wso2telco.core.pcrservice.exception.PCRException)

Example 5 with OAuthConsumerAppDTO

use of org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO in project airavata by apache.

the class OAuthAppRegisteringClient method registerApplication.

public OAuthConsumerAppDTO registerApplication(String appName, String consumerId, String consumerSecret) throws AiravataSecurityException {
    try {
        OAuthConsumerAppDTO consumerAppDTO = new OAuthConsumerAppDTO();
        consumerAppDTO.setApplicationName(appName);
        // consumer key and secret is set by the application.
        consumerAppDTO.setOauthConsumerKey(consumerId);
        consumerAppDTO.setOauthConsumerSecret(consumerSecret);
        // consumerAppDTO.setUsername(adminUserName);
        // initialize trust store for SSL handshake
        TrustStoreManager trustStoreManager = new TrustStoreManager();
        trustStoreManager.initializeTrustStoreManager(Properties.TRUST_STORE_PATH, Properties.TRUST_STORE_PASSWORD);
        stub.registerOAuthApplicationData(consumerAppDTO);
        // After registration application is retrieve
        return stub.getOAuthApplicationDataByAppName(appName);
    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        throw new AiravataSecurityException("Error in registering the OAuth application.");
    } catch (RemoteException e) {
        e.printStackTrace();
        throw new AiravataSecurityException("Error in registering the OAuth application.");
    } catch (OAuthAdminServiceException e) {
        e.printStackTrace();
        throw new AiravataSecurityException("Error in registering the OAuth application.");
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) OAuthAdminServiceException(org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceException) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) TrustStoreManager(org.apache.airavata.security.util.TrustStoreManager) RemoteException(java.rmi.RemoteException) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException)

Aggregations

OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)5 PCRException (com.wso2telco.core.pcrservice.exception.PCRException)2 AiravataSecurityException (org.apache.airavata.security.AiravataSecurityException)2 KeyValueBasedPcrDAOImpl (com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Scanner (java.util.Scanner)1 Airavata (org.apache.airavata.api.Airavata)1 ApplicationModule (org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule)1 AiravataClientException (org.apache.airavata.model.error.AiravataClientException)1 InvalidRequestException (org.apache.airavata.model.error.InvalidRequestException)1 AuthzToken (org.apache.airavata.model.security.AuthzToken)1 Gateway (org.apache.airavata.model.workspace.Gateway)1 TrustStoreManager (org.apache.airavata.security.util.TrustStoreManager)1 AxisFault (org.apache.axis2.AxisFault)1 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 ServiceContext (org.apache.axis2.context.ServiceContext)1 TException (org.apache.thrift.TException)1 Test (org.junit.Test)1