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());
}
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);
}
}
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);
}
}
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);
}
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);
}
}
Aggregations