Search in sources :

Example 1 with OauthAdminClient

use of org.wso2.identity.integration.common.clients.oauth.OauthAdminClient in project product-is by wso2.

the class AbstractAdaptiveAuthenticationTestCase method createServiceProvider.

protected ServiceProvider createServiceProvider(String appName, ApplicationManagementServiceClient applicationManagementServiceClient, OauthAdminClient oauthAdminClient, String script) throws Exception {
    OAuthConsumerAppDTO[] appDtos = oauthAdminClient.getAllOAuthApplicationData();
    for (OAuthConsumerAppDTO appDto : appDtos) {
        if (appDto.getApplicationName().equals(appName)) {
            consumerKey = appDto.getOauthConsumerKey();
            consumerSecret = appDto.getOauthConsumerSecret();
        }
    }
    ServiceProvider serviceProvider = new ServiceProvider();
    serviceProvider.setApplicationName(appName);
    serviceProvider.setDescription("This is a test Service Provider for conditional authentication flow test.");
    applicationManagementServiceClient.createApplication(serviceProvider);
    serviceProvider = applicationManagementServiceClient.getApplication(appName);
    InboundAuthenticationRequestConfig requestConfig = new InboundAuthenticationRequestConfig();
    requestConfig.setInboundAuthKey(consumerKey);
    requestConfig.setInboundAuthType("oauth2");
    if (StringUtils.isNotBlank(consumerSecret)) {
        Property property = new Property();
        property.setName("oauthConsumerSecret");
        property.setValue(consumerSecret);
        Property[] properties = { property };
        requestConfig.setProperties(properties);
    }
    InboundAuthenticationConfig inboundAuthenticationConfig = new InboundAuthenticationConfig();
    inboundAuthenticationConfig.setInboundAuthenticationRequestConfigs(new InboundAuthenticationRequestConfig[] { requestConfig });
    serviceProvider.setInboundAuthenticationConfig(inboundAuthenticationConfig);
    LocalAndOutboundAuthenticationConfig outboundAuthConfig = createLocalAndOutboundAuthenticationConfig();
    outboundAuthConfig.setEnableAuthorization(false);
    AuthenticationScriptConfig config = new AuthenticationScriptConfig();
    config.setContent(script);
    config.setEnabled(true);
    outboundAuthConfig.setAuthenticationScriptConfig(config);
    serviceProvider.setLocalAndOutBoundAuthenticationConfig(outboundAuthConfig);
    applicationManagementServiceClient.updateApplicationData(serviceProvider);
    return serviceProvider;
}
Also used : LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.xsd.LocalAndOutboundAuthenticationConfig) InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig) AuthenticationScriptConfig(org.wso2.carbon.identity.application.common.model.script.xsd.AuthenticationScriptConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig) Property(org.wso2.carbon.identity.application.common.model.xsd.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)

Example 2 with OauthAdminClient

use of org.wso2.identity.integration.common.clients.oauth.OauthAdminClient in project product-is by wso2.

the class AbstractAdaptiveAuthenticationTestCase method createOauthApp.

protected void createOauthApp(String callback, String appName, OauthAdminClient oAuthAdminClient) throws RemoteException, OAuthAdminServiceIdentityOAuthAdminException {
    OAuthConsumerAppDTO appDTO = new OAuthConsumerAppDTO();
    appDTO.setCallbackUrl(callback);
    appDTO.setGrantTypes("authorization_code implicit password client_credentials refresh_token " + "urn:ietf:params:oauth:grant-type:saml2-bearer iwa:ntlm");
    appDTO.setOAuthVersion(OAuth2Constant.OAUTH_VERSION_2);
    appDTO.setApplicationName(appName);
    oAuthAdminClient.registerOAuthApplicationData(appDTO);
    OAuthConsumerAppDTO[] appDtos = oAuthAdminClient.getAllOAuthApplicationData();
    for (OAuthConsumerAppDTO appDto : appDtos) {
        if (appDto.getApplicationName().equals(appName)) {
            consumerKey = appDto.getOauthConsumerKey();
            consumerSecret = appDto.getOauthConsumerSecret();
        }
    }
}
Also used : OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)

Example 3 with OauthAdminClient

use of org.wso2.identity.integration.common.clients.oauth.OauthAdminClient in project product-is by wso2.

the class RiskBasedLoginTestCase method testInit.

@BeforeClass(alwaysRun = true)
public void testInit() throws Exception {
    super.init();
    InputStream webappUrl = getClass().getResourceAsStream(ISIntegrationTest.URL_SEPARATOR + "samples" + ISIntegrationTest.URL_SEPARATOR + "authenticators" + ISIntegrationTest.URL_SEPARATOR + "sample-auth.war");
    InputStream jarUrl = getClass().getResourceAsStream(ISIntegrationTest.URL_SEPARATOR + "samples" + ISIntegrationTest.URL_SEPARATOR + "authenticators" + ISIntegrationTest.URL_SEPARATOR + "org.wso2.carbon.identity.sample.extension.authenticators.jar");
    String authenticatorPathString = Utils.getResidentCarbonHome() + File.separator + "repository" + File.separator + "components" + File.separator + "dropins" + File.separator + "org.wso2.carbon.identity.sample.extension.authenticators.jar";
    File jarDestFile = new File(authenticatorPathString);
    FileOutputStream jarDest = new FileOutputStream(jarDestFile);
    copyFileUsingStream(jarUrl, jarDest);
    log.info("Copied the demo authenticator jar file to " + authenticatorPathString);
    Assert.assertTrue(Files.exists(Paths.get(authenticatorPathString)), "Demo Authenticator is not copied " + "successfully. File path: " + authenticatorPathString);
    String authenticatorWarPathString = Utils.getResidentCarbonHome() + File.separator + "repository" + File.separator + "deployment" + File.separator + "server" + File.separator + "webapps" + File.separator + "sample-auth.war";
    File warDestFile = new File(authenticatorWarPathString);
    FileOutputStream warDest = new FileOutputStream(warDestFile);
    copyFileUsingStream(webappUrl, warDest);
    // Waiting for the war file to deploy.
    String authenticatorWebappPathString = Utils.getResidentCarbonHome() + File.separator + "repository" + File.separator + "deployment" + File.separator + "server" + File.separator + "webapps" + File.separator + "sample-auth";
    waitForWebappToDeploy(authenticatorWebappPathString, 120000L);
    log.info("Copied the demo authenticator war file to " + authenticatorWarPathString);
    Assert.assertTrue(Files.exists(Paths.get(authenticatorWarPathString)), "Demo Authenticator war is not copied " + "successfully. File path: " + authenticatorWarPathString);
    log.info("Restarting the server at: " + isServer.getContextUrls().getBackEndUrl());
    serverConfigurationManager = new ServerConfigurationManager(isServer);
    changeISConfiguration();
    log.info("Restarting the server at: " + isServer.getContextUrls().getBackEndUrl() + " is successful");
    super.init();
    logManger = new AuthenticatorClient(backendURL);
    String cookie = this.logManger.login(isServer.getSuperTenant().getTenantAdmin().getUserName(), isServer.getSuperTenant().getTenantAdmin().getPassword(), isServer.getInstance().getHosts().get("default"));
    oauthAdminClient = new OauthAdminClient(backendURL, cookie);
    ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    applicationManagementServiceClient = new ApplicationManagementServiceClient(sessionCookie, backendURL, configContext);
    webAppAdminClient = new WebAppAdminClient(backendURL, sessionCookie);
    client = HttpClientBuilder.create().disableRedirectHandling().setDefaultCookieStore(cookieStore).build();
    String script = getConditionalAuthScript("RiskBasedLoginScript.js");
    createOauthApp(CALLBACK_URL, PRIMARY_IS_APPLICATION_NAME, oauthAdminClient);
    // Create service provider in primary IS with conditional authentication script enabled.
    createServiceProvider(PRIMARY_IS_APPLICATION_NAME, applicationManagementServiceClient, oauthAdminClient, script);
    microserviceServer = MicroserviceUtil.initMicroserviceServer();
    MicroserviceUtil.deployService(microserviceServer, this);
    superTenantResidentIDP = superTenantIDPMgtClient.getResidentIdP();
    updateResidentIDPProperty(superTenantResidentIDP, "adaptive_authentication.analytics.receiver", "http://localhost:" + microserviceServer.getPort());
    userRiskScores.put(userInfo.getUserName(), 0);
}
Also used : OauthAdminClient(org.wso2.identity.integration.common.clients.oauth.OauthAdminClient) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AuthenticatorClient(org.wso2.carbon.integration.common.admin.client.AuthenticatorClient) InputStream(java.io.InputStream) ServerConfigurationManager(org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager) FileOutputStream(java.io.FileOutputStream) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient) WebAppAdminClient(org.wso2.identity.integration.common.clients.webappmgt.WebAppAdminClient) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with OauthAdminClient

use of org.wso2.identity.integration.common.clients.oauth.OauthAdminClient in project product-is by wso2.

the class AbstractIdentityFederationTestCase method createServiceClients.

public void createServiceClients(int portOffset, String sessionCookie, IdentityConstants.ServiceClientType[] adminClients) throws Exception {
    if (adminClients == null) {
        return;
    }
    String serviceUrl = getSecureServiceUrl(portOffset, automationContextMap.get(portOffset).getContextUrls().getSecureServiceUrl());
    if (sessionCookie == null) {
        AuthenticatorClient authenticatorClient = new AuthenticatorClient(serviceUrl);
        sessionCookie = authenticatorClient.login(automationContextMap.get(portOffset).getSuperTenant().getTenantAdmin().getUserName(), automationContextMap.get(portOffset).getSuperTenant().getTenantAdmin().getPassword(), automationContextMap.get(portOffset).getDefaultInstance().getHosts().get("default"));
    }
    if (sessionCookie != null) {
        ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
        for (IdentityConstants.ServiceClientType clientType : adminClients) {
            if (IdentityConstants.ServiceClientType.APPLICATION_MANAGEMENT.equals(clientType)) {
                applicationManagementServiceClients.put(portOffset, new ApplicationManagementServiceClient(sessionCookie, serviceUrl, configContext));
            } else if (IdentityConstants.ServiceClientType.IDENTITY_PROVIDER_MGT.equals(clientType)) {
                identityProviderMgtServiceClients.put(portOffset, new IdentityProviderMgtServiceClient(sessionCookie, serviceUrl));
            } else if (IdentityConstants.ServiceClientType.SAML_SSO_CONFIG.equals(clientType)) {
                samlSSOConfigServiceClients.put(portOffset, new SAMLSSOConfigServiceClient(serviceUrl, sessionCookie));
            } else if (IdentityConstants.ServiceClientType.OAUTH_ADMIN.equals(clientType)) {
                oauthAdminClients.put(portOffset, new OauthAdminClient(serviceUrl, sessionCookie));
            }
        }
    }
}
Also used : OauthAdminClient(org.wso2.identity.integration.common.clients.oauth.OauthAdminClient) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) IdentityConstants(org.wso2.identity.integration.test.utils.IdentityConstants) AuthenticatorClient(org.wso2.carbon.integration.common.admin.client.AuthenticatorClient) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient) SAMLSSOConfigServiceClient(org.wso2.identity.integration.common.clients.sso.saml.SAMLSSOConfigServiceClient) IdentityProviderMgtServiceClient(org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient)

Example 5 with OauthAdminClient

use of org.wso2.identity.integration.common.clients.oauth.OauthAdminClient in project product-is by wso2.

the class CrossProtocolLogoutTestCase method init.

protected void init() throws Exception {
    super.init();
    adminClient = new OauthAdminClient(backendURL, sessionCookie);
    ssoConfigServiceClient = new SAMLSSOConfigServiceClient(backendURL, sessionCookie);
    applicationManagementServiceClient = new ApplicationManagementServiceClient(sessionCookie, backendURL, null);
}
Also used : OauthAdminClient(org.wso2.identity.integration.common.clients.oauth.OauthAdminClient) SAMLSSOConfigServiceClient(org.wso2.identity.integration.common.clients.sso.saml.SAMLSSOConfigServiceClient) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient)

Aggregations

OauthAdminClient (org.wso2.identity.integration.common.clients.oauth.OauthAdminClient)20 BeforeClass (org.testng.annotations.BeforeClass)18 ApplicationManagementServiceClient (org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient)15 AuthenticatorClient (org.wso2.carbon.integration.common.admin.client.AuthenticatorClient)14 RemoteUserStoreManagerServiceClient (org.wso2.identity.integration.common.clients.usermgt.remote.RemoteUserStoreManagerServiceClient)8 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)6 LoginLogoutClient (org.wso2.carbon.integration.common.utils.LoginLogoutClient)6 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)5 IdentityProviderMgtServiceClient (org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient)4 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)3 IdentityConstants (org.wso2.identity.integration.test.utils.IdentityConstants)3 HTTPCommonClient (org.wso2.identity.scenarios.commons.HTTPCommonClient)3 OAuth2CommonClient (org.wso2.identity.scenarios.commons.OAuth2CommonClient)3 SSOCommonClient (org.wso2.identity.scenarios.commons.SSOCommonClient)3 OauthAdminClient (org.wso2.identity.scenarios.commons.clients.oauth.OauthAdminClient)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)2 SAMLSSOConfigServiceClient (org.wso2.identity.integration.common.clients.sso.saml.SAMLSSOConfigServiceClient)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1