Search in sources :

Example 46 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class RequestPathBasicAuthenticationSSOTest method testLoginSuccessRequestPath.

@Test(alwaysRun = true, description = "Request path authenticator login success")
public void testLoginSuccessRequestPath() throws Exception {
    HttpPost request = new HttpPost(String.format(SAMPLE_APP_URL, ISSUER_TRAVELOCITY_COM) + "/samlsso" + "?SAML2.HTTPBinding=HTTP-POST");
    List<NameValuePair> urlParameters = new ArrayList<>();
    urlParameters.add(new BasicNameValuePair("username", adminUsername));
    urlParameters.add(new BasicNameValuePair("password", adminPassword));
    request.setEntity(new UrlEncodedFormEntity(urlParameters));
    HttpResponse response = client.execute(request);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line;
    String samlRequest = "";
    String secToken = "";
    while ((line = rd.readLine()) != null) {
        if (line.contains("name='SAMLRequest'")) {
            String[] tokens = line.split("'");
            samlRequest = tokens[5];
        }
        if (line.contains("name='sectoken'")) {
            String[] tokens = line.split("'");
            secToken = tokens[5];
        }
    }
    EntityUtils.consume(response.getEntity());
    request = new HttpPost(isURL + "samlsso");
    urlParameters = new ArrayList<>();
    urlParameters.add(new BasicNameValuePair("sectoken", secToken));
    urlParameters.add(new BasicNameValuePair("SAMLRequest", samlRequest));
    request.setEntity(new UrlEncodedFormEntity(urlParameters));
    response = client.execute(request);
    if (Utils.requestMissingClaims(response)) {
        String pastrCookie = Utils.getPastreCookie(response);
        Assert.assertNotNull(pastrCookie, "pastr cookie not found in response.");
        EntityUtils.consume(response.getEntity());
        response = Utils.sendPOSTConsentMessage(response, isURL + "commonauth", USER_AGENT, String.format(ACS_URL, ISSUER_TRAVELOCITY_COM), client, pastrCookie);
        EntityUtils.consume(response.getEntity());
    }
    int responseCode = response.getStatusLine().getStatusCode();
    Assert.assertEquals(responseCode, 200, "Successful login response returned code " + responseCode);
    String samlResponse = "";
    rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    while ((line = rd.readLine()) != null) {
        if (line.contains("name='SAMLResponse'")) {
            String[] tokens = line.split("'");
            samlResponse = tokens[5];
        }
    }
    Base64 base64Decoder = new Base64();
    samlResponse = new String(base64Decoder.decode(samlResponse));
    Assert.assertTrue(samlResponse.contains(SAML_SUCCESS_TAG), "SAML response did not contained success state");
    EntityUtils.consume(response.getEntity());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) Base64(org.apache.commons.codec.binary.Base64) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) BufferedReader(java.io.BufferedReader) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 47 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class ChallengeQuestionPostAuthnHandlerTestCase method testLoginWithDisabledSetting.

@Test(alwaysRun = true, description = "Testing login when the Force Challenge Questions setting is disabled", groups = "wso2.is", dependsOnMethods = { "testAddSP" })
public void testLoginWithDisabledSetting() {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        HttpResponse response;
        // Update resident IDP property for forcing challenge questions
        updateResidentIDPProperty(superTenantResidentIDP, FORCE_ADD_PW_RECOVERY_QUESTION, "false", true);
        response = Utils.sendGetRequest(String.format(SAML_SSO_LOGIN_URL, config.getApp().getArtifact(), config.getHttpBinding().binding), USER_AGENT, httpClient);
        if (config.getHttpBinding() == HttpBinding.HTTP_POST) {
            String samlRequest = Utils.extractDataFromResponse(response, CommonConstants.SAML_REQUEST_PARAM, 5);
            response = sendSAMLMessage(SAML_SSO_URL, CommonConstants.SAML_REQUEST_PARAM, samlRequest, httpClient);
            EntityUtils.consume(response.getEntity());
            response = Utils.sendRedirectRequest(response, USER_AGENT, ACS_URL, config.getApp().getArtifact(), httpClient);
        }
        String sessionKey = Utils.extractDataFromResponse(response, CommonConstants.SESSION_DATA_KEY, 1);
        response = Utils.sendPOSTMessage(sessionKey, SAML_SSO_URL, USER_AGENT, ACS_URL, config.getApp().getArtifact(), config.getUser().getUsername(), config.getUser().getPassword(), httpClient);
        // Assert for not invoking missing challenge question post authentication handler
        Assert.assertFalse(isChallengeQuestionsRequested(response), "Missing challenge questions post " + "authentication handler invoked when default setting is false");
        // Check for the missing claim handler post authenticator
        if (requestMissingClaims(response)) {
            String pastrCookie = Utils.getPastreCookie(response);
            EntityUtils.consume(response.getEntity());
            response = Utils.sendPOSTConsentMessage(response, COMMON_AUTH_URL, USER_AGENT, String.format(ACS_URL, config.getApp().getArtifact()), httpClient, pastrCookie);
            EntityUtils.consume(response.getEntity());
        }
        String redirectUrl = Utils.getRedirectUrl(response);
        if (StringUtils.isNotBlank(redirectUrl)) {
            EntityUtils.consume(response.getEntity());
            response = Utils.sendRedirectRequest(response, USER_AGENT, ACS_URL, config.getApp().getArtifact(), httpClient);
        }
        String samlResponse = Utils.extractDataFromResponse(response, CommonConstants.SAML_RESPONSE_PARAM, 5);
        EntityUtils.consume(response.getEntity());
        response = sendSAMLMessage(String.format(ACS_URL, config.getApp().getArtifact()), CommonConstants.SAML_RESPONSE_PARAM, samlResponse, httpClient);
        resultPage = extractDataFromResponse(response);
        Assert.assertTrue(resultPage.contains("You are logged in as " + userId), "SAML SSO Login failed for " + config);
        EntityUtils.consume(response.getEntity());
    } catch (Exception e) {
        Assert.fail("Missing Challenge Question post authentication handler failed for " + config, e);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 48 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class ChallengeQuestionPostAuthnHandlerTestCase method testLoginWithChallengeQuestions.

@Test(alwaysRun = true, description = "Testing login when the user already has given challenge questions", groups = "wso2.is", dependsOnMethods = { "testAddSP", "testLoginWithEnabledSetting" })
public void testLoginWithChallengeQuestions() {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        HttpResponse response;
        // Update resident IDP property for forcing challenge questions
        updateResidentIDPProperty(superTenantResidentIDP, FORCE_ADD_PW_RECOVERY_QUESTION, "true", true);
        response = Utils.sendGetRequest(String.format(SAML_SSO_LOGIN_URL, config.getApp().getArtifact(), config.getHttpBinding().binding), USER_AGENT, httpClient);
        if (config.getHttpBinding() == HttpBinding.HTTP_POST) {
            String samlRequest = Utils.extractDataFromResponse(response, CommonConstants.SAML_REQUEST_PARAM, 5);
            response = sendSAMLMessage(SAML_SSO_URL, CommonConstants.SAML_REQUEST_PARAM, samlRequest, httpClient);
            EntityUtils.consume(response.getEntity());
            response = Utils.sendRedirectRequest(response, USER_AGENT, ACS_URL, config.getApp().getArtifact(), httpClient);
        }
        String sessionKey = Utils.extractDataFromResponse(response, CommonConstants.SESSION_DATA_KEY, 1);
        response = Utils.sendPOSTMessage(sessionKey, SAML_SSO_URL, USER_AGENT, ACS_URL, config.getApp().getArtifact(), config.getUser().getUsername(), config.getUser().getPassword(), httpClient);
        // Assert for not invoking missing challenge question post authentication handler
        Assert.assertFalse(isChallengeQuestionsRequested(response), "Challenge questions were not added for" + "the user " + config.getUser().toString() + "from the previous test case " + "[testLoginWithEnabledSetting]");
        // Check for the missing claim handler post authenticator
        if (requestMissingClaims(response)) {
            String pastrCookie = Utils.getPastreCookie(response);
            EntityUtils.consume(response.getEntity());
            response = Utils.sendPOSTConsentMessage(response, COMMON_AUTH_URL, USER_AGENT, String.format(ACS_URL, config.getApp().getArtifact()), httpClient, pastrCookie);
            EntityUtils.consume(response.getEntity());
        }
        String redirectUrl = Utils.getRedirectUrl(response);
        if (StringUtils.isNotBlank(redirectUrl)) {
            EntityUtils.consume(response.getEntity());
            response = Utils.sendRedirectRequest(response, USER_AGENT, ACS_URL, config.getApp().getArtifact(), httpClient);
        }
        String samlResponse = Utils.extractDataFromResponse(response, CommonConstants.SAML_RESPONSE_PARAM, 5);
        EntityUtils.consume(response.getEntity());
        response = sendSAMLMessage(String.format(ACS_URL, config.getApp().getArtifact()), CommonConstants.SAML_RESPONSE_PARAM, samlResponse, httpClient);
        resultPage = extractDataFromResponse(response);
        Assert.assertTrue(resultPage.contains("You are logged in as " + userId), "Missing Challenge Question post authentication handler failed for " + config);
        EntityUtils.consume(response.getEntity());
    } catch (Exception e) {
        Assert.fail("Missing Challenge Question post authentication handler failed for " + config, e);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Example 49 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class SAMLFederationDynamicQueryParametersTestCase method testIdpWithDynamicQueryParams.

@Test(groups = "wso2.is", description = "Test federated IDP creation with SAML Federated Authenticator")
public void testIdpWithDynamicQueryParams() throws Exception {
    IdentityProvider identityProvider = new IdentityProvider();
    identityProvider.setIdentityProviderName(IDENTITY_PROVIDER_NAME);
    FederatedAuthenticatorConfig saml2SSOAuthnConfig = new FederatedAuthenticatorConfig();
    saml2SSOAuthnConfig.setName("SAMLSSOAuthenticator");
    saml2SSOAuthnConfig.setDisplayName("samlsso");
    saml2SSOAuthnConfig.setEnabled(true);
    saml2SSOAuthnConfig.setProperties(getSAML2SSOAuthnConfigProperties());
    identityProvider.setDefaultAuthenticatorConfig(saml2SSOAuthnConfig);
    identityProvider.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { saml2SSOAuthnConfig });
    idpMgtClient.addIdP(identityProvider);
    IdentityProvider idPByName = idpMgtClient.getIdPByName(IDENTITY_PROVIDER_NAME);
    Assert.assertNotNull(idPByName);
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) Test(org.testng.annotations.Test)

Example 50 with Authenticator

use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project product-is by wso2.

the class ApplicationManagementTestCase method testUpdateRequestPathAuthenticators.

@Test(alwaysRun = true, description = "2.1.2.8")
public void testUpdateRequestPathAuthenticators() {
    String applicationName = "TestServiceProvider";
    try {
        ServiceProvider serviceProvider = applicationManagementServiceClient.getApplication(applicationName);
        List<RequestPathAuthenticatorConfig> reqAuthList = new ArrayList<RequestPathAuthenticatorConfig>();
        RequestPathAuthenticatorConfig reqAuth = new RequestPathAuthenticatorConfig();
        reqAuth.setName(BASIC_AUTH_REQUEST_PATH_AUTHENTICATOR);
        reqAuth.setDisplayName(BASIC_AUTH_REQUEST_AUTHENTICATOR_DISPLAYNAME);
        reqAuthList.add(reqAuth);
        serviceProvider.setRequestPathAuthenticatorConfigs(reqAuthList.toArray(new RequestPathAuthenticatorConfig[reqAuthList.size()]));
        applicationManagementServiceClient.updateApplicationData(serviceProvider);
        ServiceProvider updatedServiceProvider = applicationManagementServiceClient.getApplication(applicationName);
        Assert.assertEquals(updatedServiceProvider.getRequestPathAuthenticatorConfigs()[0].getName(), BASIC_AUTH_REQUEST_PATH_AUTHENTICATOR, "Failed update Request path authenticator name");
    } catch (Exception e) {
        Assert.fail("Error while trying to update Request Path Authenticators", e);
    }
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) ArrayList(java.util.ArrayList) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.xsd.RequestPathAuthenticatorConfig) Test(org.testng.annotations.Test)

Aggregations

FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)27 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)25 Test (org.testng.annotations.Test)23 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)22 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)22 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)19 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)19 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)16 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)15 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)15 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)15 IOException (java.io.IOException)12 Map (java.util.Map)12 FederatedApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator)12 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)11 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)11 Property (org.wso2.carbon.identity.application.common.model.Property)10 HttpResponse (org.apache.http.HttpResponse)8