From 204b995dd6ade319ca9a5a600b29acd478ec1148 Mon Sep 17 00:00:00 2001 From: thanujalk Date: Wed, 13 May 2015 11:28:23 +0530 Subject: [PATCH 1/4] Modified SAMLSSOTestCase to have different subject claim uri --- .../test/saml/SAMLSSOTestCase.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java index 8376f93fdd..adfa430ee1 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java @@ -115,13 +115,19 @@ private enum ClaimType{ LOCAL, CUSTOM, NONE } + private enum SubjectClaimUri { + EMAIL, NONE + } + private static class SAMLConfig{ private HttpBinding httpBinding; private ClaimType claimType; + private SubjectClaimUri subjectClaimUri; - private SAMLConfig(HttpBinding httpBinding, ClaimType claimType) { + private SAMLConfig(HttpBinding httpBinding, ClaimType claimType, SubjectClaimUri subjectClaimUri) { this.httpBinding = httpBinding; this.claimType = claimType; + this.subjectClaimUri = subjectClaimUri; } public ClaimType getClaimType() { @@ -132,12 +138,16 @@ public HttpBinding getHttpBinding() { return httpBinding; } + public SubjectClaimUri getSubjectClaimUri() { + return subjectClaimUri; + } + @Override public String toString() { return "SAMLConfig[" + "httpBinding=" + httpBinding + ", claimType=" + claimType + - ']'; + "subjectClaimUri=" + subjectClaimUri + "]"; } } @@ -239,8 +249,13 @@ public void testSAMLSSOLogin() { response = sendSAMLMessage(ACS_URL, "SAMLResponse", samlResponse); resultPage = extractDataFromResponse(response); - Assert.assertTrue(resultPage.contains("You are logged in as " + USERNAME), - "SAML SSO Login failed for " + config); + if(SubjectClaimUri.EMAIL.equals(config.getSubjectClaimUri())) { + Assert.assertTrue(resultPage.contains("You are logged in as " + EMAIL), + "SAML SSO Login failed for " + config); + } else { + Assert.assertTrue(resultPage.contains("You are logged in as " + USERNAME), + "SAML SSO Login failed for " + config); + } } catch (Exception e) { Assert.fail("SAML SSO Login test failed for " + config, e); } @@ -291,10 +306,11 @@ public void testSAMLSSOLogout() throws Exception { @DataProvider(name = "samlConfigProvider") public static SAMLConfig[][] samlConfigProvider(){ return new SAMLConfig[][]{ - {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.NONE)}, - {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.LOCAL)}, - {new SAMLConfig(HttpBinding.HTTP_POST, ClaimType.NONE)}, - {new SAMLConfig(HttpBinding.HTTP_POST, ClaimType.LOCAL)}, + {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.NONE, SubjectClaimUri.NONE)}, + {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.LOCAL, SubjectClaimUri.NONE)}, + {new SAMLConfig(HttpBinding.HTTP_POST, ClaimType.NONE, SubjectClaimUri.NONE)}, + {new SAMLConfig(HttpBinding.HTTP_POST, ClaimType.LOCAL, SubjectClaimUri.NONE)}, + {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.NONE, SubjectClaimUri.EMAIL)} }; } @@ -446,6 +462,9 @@ private void createApplication() throws Exception{ serviceProvider = applicationManagementServiceClient.getApplication(APPLICATION_NAME); serviceProvider.getClaimConfig().setClaimMappings(getClaimMappings()); + if(SubjectClaimUri.EMAIL.equals(config.getSubjectClaimUri())) { + serviceProvider.getLocalAndOutBoundAuthenticationConfig().setSubjectClaimUri(emailClaimURI); + } InboundAuthenticationRequestConfig requestConfig = new InboundAuthenticationRequestConfig(); requestConfig.setInboundAuthType(INBOUND_AUTH_TYPE); @@ -495,6 +514,7 @@ private SAMLSSOServiceProviderDTO createSsoServiceProviderDTO() { samlssoServiceProviderDTO.setIssuer(ISSUER_NAME); samlssoServiceProviderDTO.setAssertionConsumerUrl(ACS_URL); samlssoServiceProviderDTO.setAttributeConsumingServiceIndex(ATTRIBUTE_CS_INDEX_VALUE); + samlssoServiceProviderDTO.setUseFullyQualifiedUsername(true); samlssoServiceProviderDTO.setNameIDFormat(NAMEID_FORMAT); samlssoServiceProviderDTO.setDoSignAssertions(true); samlssoServiceProviderDTO.setDoSignResponse(true); From ca7c2384ce75a63c52b237d3f20f1cf49f8220f5 Mon Sep 17 00:00:00 2001 From: thanujalk Date: Mon, 18 May 2015 18:29:38 +0530 Subject: [PATCH 2/4] Merge wso2 master --- .../test/saml/SAMLSSOTestCase.java | 276 +++++++++++------- 1 file changed, 178 insertions(+), 98 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java index adfa430ee1..2ff05bf8c8 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/saml/SAMLSSOTestCase.java @@ -1,20 +1,20 @@ /* -*Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -*WSO2 Inc. licenses this file to you under the Apache License, -*Version 2.0 (the "License"); you may not use this file except -*in compliance with the License. -*You may obtain a copy of the License at -* -*http://www.apache.org/licenses/LICENSE-2.0 -* -*Unless required by applicable law or agreed to in writing, -*software distributed under the License is distributed on an -*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -*KIND, either express or implied. See the License for the -*specific language governing permissions and limitations -*under the License. -*/ + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.wso2.identity.integration.test.saml; @@ -36,6 +36,7 @@ import org.apache.http.util.EntityUtils; import org.testng.Assert; import org.testng.annotations.*; +import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO; import org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient; import org.wso2.identity.integration.common.clients.sso.saml.SAMLSSOConfigServiceClient; @@ -60,25 +61,19 @@ public class SAMLSSOTestCase extends ISIntegrationTest { // SAML Application attributes private static final String USER_AGENT = "Apache-HttpClient/4.2.5 (java 1.5)"; - private static final String ISSUER_NAME = "travelocity.com"; private static final String APPLICATION_NAME = "SAML-SSO-TestApplication"; private static final String INBOUND_AUTH_TYPE = "samlsso"; private static final String ATTRIBUTE_CS_INDEX_VALUE = "1239245949"; private static final String ATTRIBUTE_CS_INDEX_NAME = "attrConsumServiceIndex"; - - // User Attributes - private static final String USERNAME = "testUser"; - private static final String PASSWORD = "testUser"; - private static final String EMAIL = "testUser@wso2.com"; - private static final String NICKNAME = "testUserNick"; + public static final String TENANT_DOMAIN_PARAM = "tenantDomain"; private static final String SAML_SSO_URL = "https://localhost:9443/samlsso"; - private static final String ACS_URL = "http://localhost:8090/travelocity.com/home.jsp"; + private static final String ACS_URL = "http://localhost:8090/%s/home.jsp"; private static final String COMMON_AUTH_URL = "https://localhost:9443/commonauth"; private static final String SAML_SSO_LOGIN_URL = - "http://localhost:8090/travelocity.com/samlsso?SAML2.HTTPBinding=%s"; + "http://localhost:8090/%s/samlsso?SAML2.HTTPBinding=%s"; private static final String SAML_SSO_LOGOUT_URL = - "http://localhost:8090/travelocity.com/logout?SAML2.HTTPBinding=%s"; + "http://localhost:8090/%s/logout?SAML2.HTTPBinding=%s"; private static final String NAMEID_FORMAT = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"; @@ -115,19 +110,98 @@ private enum ClaimType{ LOCAL, CUSTOM, NONE } - private enum SubjectClaimUri { - EMAIL, NONE + private enum User { + SUPER_TENANT_USER("samluser1", "samluser1", "carbon.super", "samluser1", "samluser1@abc.com", "samlnickuser1"), + TENANT_USER("samluser2@wso2.com", "samluser2", "wso2.com", "samluser2", "samluser2@abc.com", "samlnickuser2"); + + private String username; + private String password; + private String tenantDomain; + private String tenantAwareUsername; + private String email; + private String nickname; + + User(String username, String password, String tenantDomain, String tenantAwareUsername, String email, + String nickname) { + this.username = username; + this.password = password; + this.tenantDomain = tenantDomain; + this.tenantAwareUsername = tenantAwareUsername; + this.email = email; + this.nickname = nickname; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public String getTenantAwareUsername() { + return tenantAwareUsername; + } + + public String getEmail() { + return email; + } + + public String getNickname() { + return nickname; + } + }; + + private enum App{ + SUPER_TENANT_APP_WITH_SIGNING("travelocity.com", true), + TENANT_APP_WITHOUT_SIGNING("travelocity.com-saml-tenantwithoutsigning", false); + + private String artifact; + private boolean signingEnabled; + + App(String artifact, boolean signingEnabled) { + this.artifact = artifact; + this.signingEnabled = signingEnabled; + } + + public String getArtifact() { + return artifact; + } + + public boolean isSigningEnabled() { + return signingEnabled; + } } private static class SAMLConfig{ + private TestUserMode userMode; + private User user; private HttpBinding httpBinding; private ClaimType claimType; - private SubjectClaimUri subjectClaimUri; + private App app; - private SAMLConfig(HttpBinding httpBinding, ClaimType claimType, SubjectClaimUri subjectClaimUri) { + private SAMLConfig(TestUserMode userMode, User user, HttpBinding httpBinding, ClaimType claimType, App app) { + this.userMode = userMode; + this.user = user; this.httpBinding = httpBinding; this.claimType = claimType; - this.subjectClaimUri = subjectClaimUri; + this.app = app; + } + + public TestUserMode getUserMode() { + return userMode; + } + + public App getApp() { + return app; + } + + public User getUser() { + return user; } public ClaimType getClaimType() { @@ -138,16 +212,15 @@ public HttpBinding getHttpBinding() { return httpBinding; } - public SubjectClaimUri getSubjectClaimUri() { - return subjectClaimUri; - } - @Override public String toString() { return "SAMLConfig[" + - "httpBinding=" + httpBinding + - ", claimType=" + claimType + - "subjectClaimUri=" + subjectClaimUri + "]"; + ", userMode=" + userMode.name() + + ", user=" + user.getUsername() + + ", httpBinding=" + httpBinding + + ", claimType=" + claimType + + ", app=" + app.getArtifact() + + ']'; } } @@ -161,7 +234,7 @@ public SAMLSSOTestCase(SAMLConfig config) { @BeforeClass(alwaysRun = true) public void testInit() throws Exception { - super.init(); + super.init(config.getUserMode()); ConfigurationContext configContext = ConfigurationContextFactory .createConfigurationContextFromFileSystem(null @@ -181,11 +254,9 @@ public void testInit() throws Exception { log.info("Starting Tomcat"); tomcatServer = getTomcat(); - //TODO: Uncomment below once the tomcat dependency issue is resolved -// URL resourceUrl = getClass() -// .getResource(File.separator + "samples" + File.separator + "org.wso2.sample.is .sso.agent.war"); - URL resourceUrl = getClass().getResource(File.separator + "samples" + File.separator + "travelocity.com.war"); - startTomcat(tomcatServer, "/travelocity.com", resourceUrl.getPath()); + URL resourceUrl = getClass() + .getResource(File.separator + "samples" + File.separator + config.getApp().getArtifact() + ".war"); + startTomcat(tomcatServer, "/" + config.getApp().getArtifact(), resourceUrl.getPath()); } @@ -212,24 +283,25 @@ public void testAddSP() throws Exception { SAMLSSOServiceProviderDTO[] samlssoServiceProviderDTOs = ssoConfigServiceClient .getServiceProviders().getServiceProviders(); - Assert.assertEquals(samlssoServiceProviderDTOs[0].getIssuer(), ISSUER_NAME, - "Adding a service provider has failed for " + config); + Assert.assertEquals(samlssoServiceProviderDTOs[0].getIssuer(), config.getApp().getArtifact(), + "Adding a service provider has failed for " + config); } @Test(description = "Remove service provider", groups = "wso2.is", dependsOnMethods = { "testSAMLSSOLogout" }) public void testRemoveSP() throws Exception { - Boolean isAddSuccess = ssoConfigServiceClient.removeServiceProvider(ISSUER_NAME); + Boolean isAddSuccess = ssoConfigServiceClient.removeServiceProvider(config.getApp().getArtifact()); Assert.assertTrue(isAddSuccess, "Removing a service provider has failed for " + config); } @Test(alwaysRun = true, description = "Testing SAML SSO login", groups = "wso2.is", - dependsOnMethods = { "testAddSP" }) + dependsOnMethods = { "testAddSP" }) public void testSAMLSSOLogin() { try { HttpResponse response; - response = sendGetRequest(String.format(SAML_SSO_LOGIN_URL, config.getHttpBinding().binding)); + response = sendGetRequest( + String.format(SAML_SSO_LOGIN_URL, config.getApp().getArtifact(), config.getHttpBinding().binding)); if (config.getHttpBinding() == HttpBinding.HTTP_POST){ String samlRequest = extractDataFromResponse(response, "SAMLRequest", 5); @@ -246,23 +318,19 @@ public void testSAMLSSOLogin() { response = sendRedirectRequest(response); String samlResponse = extractDataFromResponse(response, "SAMLResponse", 5); - response = sendSAMLMessage(ACS_URL, "SAMLResponse", samlResponse); + response = sendSAMLMessage(String.format(ACS_URL, config.getApp().getArtifact()), "SAMLResponse", + samlResponse); resultPage = extractDataFromResponse(response); - if(SubjectClaimUri.EMAIL.equals(config.getSubjectClaimUri())) { - Assert.assertTrue(resultPage.contains("You are logged in as " + EMAIL), - "SAML SSO Login failed for " + config); - } else { - Assert.assertTrue(resultPage.contains("You are logged in as " + USERNAME), - "SAML SSO Login failed for " + config); - } + Assert.assertTrue(resultPage.contains("You are logged in as " + config.getUser().getTenantAwareUsername()), + "SAML SSO Login failed for " + config); } catch (Exception e) { Assert.fail("SAML SSO Login test failed for " + config, e); } } @Test(alwaysRun = true, description = "Testing SAML SSO Claims", groups = "wso2.is", - dependsOnMethods = { "testSAMLSSOLogin" }) + dependsOnMethods = { "testSAMLSSOLogin" }) public void testClaims(){ String claimString = resultPage.substring(resultPage.lastIndexOf("")); @@ -277,12 +345,13 @@ public void testClaims(){ } @Test(alwaysRun = true, description = "Testing SAML SSO logout", groups = "wso2.is", - dependsOnMethods = { "testSAMLSSOLogin" }) + dependsOnMethods = { "testSAMLSSOLogin" }) public void testSAMLSSOLogout() throws Exception { try { HttpResponse response; - response = sendGetRequest(String.format(SAML_SSO_LOGOUT_URL, config.getHttpBinding().binding)); + response = sendGetRequest( + String.format(SAML_SSO_LOGOUT_URL, config.getApp().getArtifact(), config.getHttpBinding().binding)); if (config.getHttpBinding() == HttpBinding.HTTP_POST){ String samlRequest = extractDataFromResponse(response, "SAMLRequest", 5); @@ -293,11 +362,12 @@ public void testSAMLSSOLogout() throws Exception { } String samlResponse = extractDataFromResponse(response, "SAMLResponse", 5); - response = sendSAMLMessage(ACS_URL, "SAMLResponse", samlResponse); + response = sendSAMLMessage(String.format(ACS_URL, config.getApp().getArtifact()), "SAMLResponse", + samlResponse); String resultPage = extractDataFromResponse(response); Assert.assertTrue(resultPage.contains("index.jsp") && !resultPage.contains("error"), - "SAML SSO Logout failed for " + config); + "SAML SSO Logout failed for " + config); } catch (Exception e) { Assert.fail("SAML SSO Logout test failed for " + config, e); } @@ -306,25 +376,36 @@ public void testSAMLSSOLogout() throws Exception { @DataProvider(name = "samlConfigProvider") public static SAMLConfig[][] samlConfigProvider(){ return new SAMLConfig[][]{ - {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.NONE, SubjectClaimUri.NONE)}, - {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.LOCAL, SubjectClaimUri.NONE)}, - {new SAMLConfig(HttpBinding.HTTP_POST, ClaimType.NONE, SubjectClaimUri.NONE)}, - {new SAMLConfig(HttpBinding.HTTP_POST, ClaimType.LOCAL, SubjectClaimUri.NONE)}, - {new SAMLConfig(HttpBinding.HTTP_REDIRECT, ClaimType.NONE, SubjectClaimUri.EMAIL)} + {new SAMLConfig(TestUserMode.SUPER_TENANT_ADMIN, User.SUPER_TENANT_USER, HttpBinding.HTTP_REDIRECT, + ClaimType.NONE, App.SUPER_TENANT_APP_WITH_SIGNING)}, + {new SAMLConfig(TestUserMode.SUPER_TENANT_ADMIN, User.SUPER_TENANT_USER, HttpBinding.HTTP_REDIRECT, + ClaimType.LOCAL, App.SUPER_TENANT_APP_WITH_SIGNING)}, + {new SAMLConfig(TestUserMode.SUPER_TENANT_ADMIN, User.SUPER_TENANT_USER, HttpBinding.HTTP_POST, + ClaimType.NONE, App.SUPER_TENANT_APP_WITH_SIGNING)}, + {new SAMLConfig(TestUserMode.SUPER_TENANT_ADMIN, User.SUPER_TENANT_USER, HttpBinding.HTTP_POST, + ClaimType.LOCAL, App.SUPER_TENANT_APP_WITH_SIGNING)}, + {new SAMLConfig(TestUserMode.TENANT_ADMIN, User.TENANT_USER, HttpBinding.HTTP_REDIRECT, + ClaimType.NONE, App.TENANT_APP_WITHOUT_SIGNING)}, + {new SAMLConfig(TestUserMode.TENANT_ADMIN, User.TENANT_USER, HttpBinding.HTTP_REDIRECT, + ClaimType.LOCAL, App.TENANT_APP_WITHOUT_SIGNING)}, + {new SAMLConfig(TestUserMode.TENANT_ADMIN, User.TENANT_USER, HttpBinding.HTTP_POST, + ClaimType.NONE, App.TENANT_APP_WITHOUT_SIGNING)}, + {new SAMLConfig(TestUserMode.TENANT_ADMIN, User.TENANT_USER, HttpBinding.HTTP_POST, + ClaimType.LOCAL, App.TENANT_APP_WITHOUT_SIGNING)}, }; } private void assertLocalClaims(String claims){ Map attributeMap = extractClaims(claims); Assert.assertTrue(attributeMap.containsKey(firstNameClaimURI), "Claim nickname is expected"); - Assert.assertEquals(attributeMap.get(firstNameClaimURI), NICKNAME, - "Expected claim value for nickname is " + NICKNAME); + Assert.assertEquals(attributeMap.get(firstNameClaimURI), config.getUser().getNickname(), + "Expected claim value for nickname is " + config.getUser().getNickname()); Assert.assertTrue(attributeMap.containsKey(lastNameClaimURI), "Claim lastname is expected"); - Assert.assertEquals(attributeMap.get(lastNameClaimURI), USERNAME, - "Expected claim value for lastname is " + USERNAME); + Assert.assertEquals(attributeMap.get(lastNameClaimURI), config.getUser().getUsername(), + "Expected claim value for lastname is " + config.getUser().getUsername()); Assert.assertTrue(attributeMap.containsKey(emailClaimURI), "Claim email is expected"); - Assert.assertEquals(attributeMap.get(emailClaimURI), EMAIL, - "Expected claim value for email is " + EMAIL); + Assert.assertEquals(attributeMap.get(emailClaimURI), config.getUser().getEmail(), + "Expected claim value for email is " + config.getUser().getEmail()); } private void assertNoneClaims(String claims){ @@ -358,10 +439,10 @@ private Tomcat getTomcat() { private void setSystemProperties() { URL resourceUrl = getClass().getResource(File.separator + "keystores" + File.separator - + "products" + File.separator + "wso2carbon.jks"); + + "products" + File.separator + "wso2carbon.jks"); System.setProperty("javax.net.ssl.trustStore", resourceUrl.getPath()); System.setProperty("javax.net.ssl.trustStorePassword", - "wso2carbon"); + "wso2carbon"); System.setProperty("javax.net.ssl.trustStoreType", "JKS"); } @@ -385,10 +466,10 @@ private String extractDataFromResponse(HttpResponse response, String key, int to private HttpResponse sendPOSTMessage(String sessionKey) throws Exception { HttpPost post = new HttpPost(COMMON_AUTH_URL); post.setHeader("User-Agent", USER_AGENT); - post.addHeader("Referer", ACS_URL); + post.addHeader("Referer", String.format(ACS_URL, config.getApp().getArtifact())); List urlParameters = new ArrayList(); - urlParameters.add(new BasicNameValuePair("username", USERNAME)); - urlParameters.add(new BasicNameValuePair("password", PASSWORD)); + urlParameters.add(new BasicNameValuePair("username", config.getUser().getUsername())); + urlParameters.add(new BasicNameValuePair("password", config.getUser().getPassword())); urlParameters.add(new BasicNameValuePair("sessionDataKey", sessionKey)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); return httpClient.execute(post); @@ -405,6 +486,9 @@ private HttpResponse sendSAMLMessage(String url, String samlMsgKey, String samlM HttpPost post = new HttpPost(url); post.setHeader("User-Agent", USER_AGENT); urlParameters.add(new BasicNameValuePair(samlMsgKey, samlMsgValue)); + if (config.getUserMode() == TestUserMode.TENANT_ADMIN || config.getUserMode() == TestUserMode.TENANT_USER){ + urlParameters.add(new BasicNameValuePair(TENANT_DOMAIN_PARAM, config.getUser().getTenantDomain())); + } post.setEntity(new UrlEncodedFormEntity(urlParameters)); return httpClient.execute(post); } @@ -420,7 +504,7 @@ private HttpResponse sendRedirectRequest(HttpResponse response) throws IOExcepti HttpGet request = new HttpGet(url); request.addHeader("User-Agent", USER_AGENT); - request.addHeader("Referer", ACS_URL); + request.addHeader("Referer", String.format(ACS_URL, config.getApp().getArtifact())); return httpClient.execute(request); } @@ -462,13 +546,10 @@ private void createApplication() throws Exception{ serviceProvider = applicationManagementServiceClient.getApplication(APPLICATION_NAME); serviceProvider.getClaimConfig().setClaimMappings(getClaimMappings()); - if(SubjectClaimUri.EMAIL.equals(config.getSubjectClaimUri())) { - serviceProvider.getLocalAndOutBoundAuthenticationConfig().setSubjectClaimUri(emailClaimURI); - } InboundAuthenticationRequestConfig requestConfig = new InboundAuthenticationRequestConfig(); requestConfig.setInboundAuthType(INBOUND_AUTH_TYPE); - requestConfig.setInboundAuthKey(ISSUER_NAME); + requestConfig.setInboundAuthKey(config.getApp().getArtifact()); Property attributeConsumerServiceIndexProp = new Property(); attributeConsumerServiceIndexProp.setName(ATTRIBUTE_CS_INDEX_NAME); @@ -488,12 +569,12 @@ private void deleteApplication() throws Exception{ } private void createUser(){ - log.info("Creating User " + USERNAME); + log.info("Creating User " + config.getUser().getUsername()); try { // creating the user - remoteUSMServiceClient.addUser(USERNAME, PASSWORD, - null, getUserClaims(), - profileName, true); + remoteUSMServiceClient.addUser(config.getUser().getTenantAwareUsername(), config.getUser().getPassword(), + null, getUserClaims(), + profileName, true); } catch (Exception e) { Assert.fail("Error while creating the user", e); } @@ -501,9 +582,9 @@ null, getUserClaims(), } private void deleteUser(){ - log.info("Deleting User " + USERNAME); + log.info("Deleting User " + config.getUser().getUsername()); try { - remoteUSMServiceClient.deleteUser(USERNAME); + remoteUSMServiceClient.deleteUser(config.getUser().getTenantAwareUsername()); } catch (Exception e) { Assert.fail("Error while deleting the user", e); } @@ -511,13 +592,12 @@ private void deleteUser(){ private SAMLSSOServiceProviderDTO createSsoServiceProviderDTO() { SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = new SAMLSSOServiceProviderDTO(); - samlssoServiceProviderDTO.setIssuer(ISSUER_NAME); - samlssoServiceProviderDTO.setAssertionConsumerUrl(ACS_URL); + samlssoServiceProviderDTO.setIssuer(config.getApp().getArtifact()); + samlssoServiceProviderDTO.setAssertionConsumerUrl(String.format(ACS_URL, config.getApp().getArtifact())); samlssoServiceProviderDTO.setAttributeConsumingServiceIndex(ATTRIBUTE_CS_INDEX_VALUE); - samlssoServiceProviderDTO.setUseFullyQualifiedUsername(true); samlssoServiceProviderDTO.setNameIDFormat(NAMEID_FORMAT); - samlssoServiceProviderDTO.setDoSignAssertions(true); - samlssoServiceProviderDTO.setDoSignResponse(true); + samlssoServiceProviderDTO.setDoSignAssertions(config.getApp().isSigningEnabled()); + samlssoServiceProviderDTO.setDoSignResponse(config.getApp().isSigningEnabled()); samlssoServiceProviderDTO.setDoSingleLogout(true); samlssoServiceProviderDTO.setLoginPageURL(LOGIN_URL); if (config.getClaimType() != ClaimType.NONE){ @@ -563,20 +643,20 @@ private ClaimValue[] getUserClaims(){ ClaimValue firstName = new ClaimValue(); firstName.setClaimURI(firstNameClaimURI); - firstName.setValue(NICKNAME); + firstName.setValue(config.getUser().getNickname()); claimValues[0] = firstName; ClaimValue lastName = new ClaimValue(); lastName.setClaimURI(lastNameClaimURI); - lastName.setValue(USERNAME); + lastName.setValue(config.getUser().getUsername()); claimValues[1] = lastName; ClaimValue email = new ClaimValue(); email.setClaimURI(emailClaimURI); - email.setValue(EMAIL); + email.setValue(config.getUser().getEmail()); claimValues[2] = email; return claimValues; } -} +} \ No newline at end of file From 01d60e077e127d066caa3052ad5142f319d23bef Mon Sep 17 00:00:00 2001 From: hasinthaindrajee Date: Wed, 15 Jul 2015 19:54:31 +0530 Subject: [PATCH 3/4] fixes to show error message on user registration failure. adding new user registration feature to the product --- .../controllers/user-registration/add.jag | 93 ++++++++++--------- .../userRegistrationServiceClient.jag | 27 ++++++ .../user-dashboard/dashboard/landing.jag | 8 ++ modules/p2-profile-gen/pom.xml | 5 +- 4 files changed, 87 insertions(+), 46 deletions(-) create mode 100644 modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/userRegistrationServiceClient.jag diff --git a/modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/add.jag b/modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/add.jag index b91fb6d429..369075358a 100644 --- a/modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/add.jag +++ b/modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/add.jag @@ -2,12 +2,16 @@ var log = new Log(); var selfReg = require('/controllers/user-registration/userRegistrationClient.jag'); +var userRegClient = require('/controllers/user-registration/userRegistrationServiceClient.jag'); +var userDTO = Packages.org.wso2.carbon.identity.user.registration.stub.dto.UserDTO; +var userFieldDTO = Packages.org.wso2.carbon.identity.user.registration.stub.dto.UserFieldDTO; var constants = require("../../util/constants.jag"); var util = require("../../util/utility.jag"); var i18n = util.initI18N(); function edit(){ + var user = new userDTO(); var messages = i18n.localize("messages"); try{ var claim = constants.DEFAULT_CLAIM_URL; @@ -15,16 +19,6 @@ function edit(){ claim = constants.OPENID_REG_CLAIM_URL; } - - var req = - - - - - ; - - var userName = ; - var domain = request.getParameter("domain"); var userNameVal = request.getParameter("userName"); var pwd = request.getParameter("pwd"); @@ -54,15 +48,17 @@ function edit(){ return; } - req.*::user.*::openID.setChildren(session.get("openIdURL")); - req.*::user.*::password.setChildren(pwd); - userName.setChildren(domain + "/" + userNameVal); - + user.setUserName(domain + "/" + userNameVal); + user.setPassword(pwd); + user.setOpenID(session.get("openIdURL")) ; var fieldValues = selfReg.readUserFieldsForUserRegistration(claim, true); fieldValues = fieldValues.*::['return']; + var userFields = []; + var i =0; + log.debug(fieldValues); for each (var f in fieldValues){ @@ -77,43 +73,45 @@ function edit(){ return; } - var fieldValue = - - - - - - - - - - - ; - - fieldValue.*::claimUri.setChildren(f.*::['claimUri'].text()); - fieldValue.*::defaultValue.setChildren(f.*::['defaultValue'].text()); - fieldValue.*::displayOrder.setChildren(f.*::['displayOrder'].text()); - fieldValue.*::fieldName.setChildren(f.*::['fieldName'].text()); - - fieldValue.*::inputValues.setChildren(f.*::['inputValues'].text()); - fieldValue.*::maxLength.setChildren(f.*::['maxLength'].text()); - fieldValue.*::minLength.setChildren(f.*::['minLength'].text()); - fieldValue.*::regEx.setChildren(f.*::['regEx'].text()); - fieldValue.*::required.setChildren(f.*::['required'].text()); + var fieldDTO = new userFieldDTO(); + var inputValues = f.*::['inputValues']; + var inputValArray = []; + var j = 0; + + for each (var inVal in inputValues){ + inputValArray[j]= inVal.text(); + } + + + + fieldDTO.setClaimUri(f.*::['claimUri'].text()); + fieldDTO.setDefaultValue(f.*::['defaultValue'].text()); + fieldDTO.setDisplayOrder(f.*::['displayOrder'].text()); + fieldDTO.setFieldName(f.*::['fieldName'].text()); + + fieldDTO.setInputValues(inputValArray); + fieldDTO.setMaxLength(f.*::['maxLength'].text()); + fieldDTO.setMinLength(f.*::['minLength'].text()); + fieldDTO.setRegEx(f.*::['regEx'].text()); + fieldDTO.setRequired(Boolean(f.*::['required'].text())); if(value != null && value.length > 0){ - fieldValue.*::fieldValue.setChildren(value); - } + fieldDTO.setFieldValue(value); + } else{ + fieldDTO.setFieldValue(""); + } + - req.*::['user'].appendChild(fieldValue); + userFields[i] = fieldDTO; + i++; } - req.*::['user'].appendChild(userName); - selfReg.addUser(req); + user.setUserFields(userFields); + userRegClient.addUser(user); response.sendRedirect("../../login.jag?"); }catch(e){ log.error(e); - response.sendRedirect("index.jag?e=1&error=service_invok_error"); + response.sendRedirect("../../landing.jag?e=1&error=" + getErrorMessage(e.message)); } } @@ -138,4 +136,13 @@ function validate(value, f){ edit(); +function getErrorMessage(message) { + var msg = message.split(':'); + if (msg.length > 0) { + return msg[2].toString().replaceAll('\'',' '); + } + return 'Error while adding user'; +} + + %> diff --git a/modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/userRegistrationServiceClient.jag b/modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/userRegistrationServiceClient.jag new file mode 100644 index 0000000000..15bad7188d --- /dev/null +++ b/modules/jaggery-apps/user-dashboard/dashboard/controllers/user-registration/userRegistrationServiceClient.jag @@ -0,0 +1,27 @@ +<% + +var log = new Log(); + +var util = require("../../util/utility.jag"); +var serverUrl = util.getServerUrl() + "/UserRegistrationAdminService"; +var connectorStub = Packages.org.wso2.carbon.identity.user.registration.stub.UserRegistrationAdminServiceStub; +var userDTO = Packages.org.wso2.carbon.identity.user.registration.stub.dto.UserDTO; +var HTTPConstants = Packages.org.apache.axis2.transport.http.HTTPConstants; + +function addUser(user) { + try { + var serviceStub = new connectorStub(serverUrl); + var serviceClient = serviceStub._getServiceClient(); + var option = serviceClient.getOptions(); + option.setManageSession(true); + var cookie = session.get("auth-cookie"); + option.setProperty(HTTPConstants.COOKIE_STRING, cookie); + + serviceStub.addUser(user); + } catch (e) { + throw e; + } +} + + +%> \ No newline at end of file diff --git a/modules/jaggery-apps/user-dashboard/dashboard/landing.jag b/modules/jaggery-apps/user-dashboard/dashboard/landing.jag index 596aa18582..6618f34e06 100644 --- a/modules/jaggery-apps/user-dashboard/dashboard/landing.jag +++ b/modules/jaggery-apps/user-dashboard/dashboard/landing.jag @@ -30,6 +30,14 @@ + <%if(request.getParameter("error") != null && request.getParameter("error").length > 0) {%> + + <%}%> diff --git a/modules/p2-profile-gen/pom.xml b/modules/p2-profile-gen/pom.xml index f5bfc45b3c..6fc23ecd05 100644 --- a/modules/p2-profile-gen/pom.xml +++ b/modules/p2-profile-gen/pom.xml @@ -134,7 +134,7 @@ org.wso2.carbon.identity:org.wso2.carbon.idp.mgt.feature:${carbon.identity.version} org.wso2.carbon.identity:org.wso2.carbon.identity.relying.party.server.feature:${carbon.identity.version} org.wso2.carbon.identity:org.wso2.carbon.identity.mgt.feature:${carbon.identity.version} - org.wso2.carbon.identity:org.wso2.carbon.identity.self.registration.server.feature:${carbon.identity.version} + org.wso2.carbon.identity:org.wso2.carbon.identity.self.registration.feature:${carbon.identity.version} org.wso2.carbon.identity:org.wso2.carbon.identity.user.profile.feature:${carbon.identity.version} org.wso2.carbon.identity:org.wso2.carbon.identity.xacml.feature:${carbon.identity.version} org.wso2.carbon.identity:org.wso2.carbon.claim.mgt.feature:${carbon.identity.version} @@ -349,14 +349,13 @@ ${carbon.identity.version} - org.wso2.carbon.identity.self.registration.server.feature.group + org.wso2.carbon.identity.self.registration.feature.group ${carbon.identity.version} org.wso2.carbon.identity.user.profile.feature.group ${carbon.identity.version} - org.wso2.carbon.identity.xacml.feature.group ${carbon.identity.version} From 2357b96849594bfd0688b64b87d2e2c0c117a87e Mon Sep 17 00:00:00 2001 From: thanujalk Date: Fri, 17 Jul 2015 14:42:30 +0530 Subject: [PATCH 4/4] Commenting some test cases until they are properly fixed --- .../tests-backend/src/test/resources/testng.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index 657e212d89..9ef8822938 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -25,7 +25,7 @@ - + @@ -34,7 +34,7 @@ - + @@ -47,15 +47,15 @@ - + - + - +