Merge pull request #3959 from mhajas/KEYCLOAK-4141
KEYCLOAK-4141 Added saml tests
This commit is contained in:
commit
4aa996c2db
5 changed files with 177 additions and 0 deletions
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||||
|
* and other contributors as indicated by the @author tags.
|
||||||
|
*
|
||||||
|
* Licensed 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.keycloak.testsuite.adapter.page;
|
||||||
|
|
||||||
|
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
|
||||||
|
import org.jboss.arquillian.test.api.ArquillianResource;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author mhajas
|
||||||
|
*/
|
||||||
|
public class DifferentCookieNameServlet extends SAMLServlet {
|
||||||
|
public static final String DEPLOYMENT_NAME = "different-cookie-name";
|
||||||
|
|
||||||
|
@ArquillianResource
|
||||||
|
@OperateOnDeployment(DEPLOYMENT_NAME)
|
||||||
|
private URL url;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getInjectedUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,6 +60,7 @@ import org.keycloak.testsuite.adapter.AbstractServletsAdapterTest;
|
||||||
import org.keycloak.testsuite.adapter.page.BadAssertionSalesPostSig;
|
import org.keycloak.testsuite.adapter.page.BadAssertionSalesPostSig;
|
||||||
import org.keycloak.testsuite.adapter.page.BadClientSalesPostSigServlet;
|
import org.keycloak.testsuite.adapter.page.BadClientSalesPostSigServlet;
|
||||||
import org.keycloak.testsuite.adapter.page.BadRealmSalesPostSigServlet;
|
import org.keycloak.testsuite.adapter.page.BadRealmSalesPostSigServlet;
|
||||||
|
import org.keycloak.testsuite.adapter.page.DifferentCookieNameServlet;
|
||||||
import org.keycloak.testsuite.adapter.page.Employee2Servlet;
|
import org.keycloak.testsuite.adapter.page.Employee2Servlet;
|
||||||
import org.keycloak.testsuite.adapter.page.EmployeeServlet;
|
import org.keycloak.testsuite.adapter.page.EmployeeServlet;
|
||||||
import org.keycloak.testsuite.adapter.page.EmployeeSigFrontServlet;
|
import org.keycloak.testsuite.adapter.page.EmployeeSigFrontServlet;
|
||||||
|
@ -205,6 +206,9 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
|
||||||
@Page
|
@Page
|
||||||
protected EmployeeServlet employeeServletPage;
|
protected EmployeeServlet employeeServletPage;
|
||||||
|
|
||||||
|
@Page
|
||||||
|
protected DifferentCookieNameServlet differentCookieNameServletPage;
|
||||||
|
|
||||||
@Page
|
@Page
|
||||||
private InputPortal inputPortalPage;
|
private InputPortal inputPortalPage;
|
||||||
|
|
||||||
|
@ -303,6 +307,11 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
|
||||||
return samlServletDeployment(SalesPost2Servlet.DEPLOYMENT_NAME, SendUsernameServlet.class);
|
return samlServletDeployment(SalesPost2Servlet.DEPLOYMENT_NAME, SendUsernameServlet.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deployment(name = DifferentCookieNameServlet.DEPLOYMENT_NAME)
|
||||||
|
protected static WebArchive differentCokieName() {
|
||||||
|
return samlServletDeployment(DifferentCookieNameServlet.DEPLOYMENT_NAME, "different-cookie-name/WEB-INF/web.xml", SendUsernameServlet.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Deployment(name = SalesPostAssertionAndResponseSig.DEPLOYMENT_NAME)
|
@Deployment(name = SalesPostAssertionAndResponseSig.DEPLOYMENT_NAME)
|
||||||
protected static WebArchive salesPostAssertionAndResponseSig() {
|
protected static WebArchive salesPostAssertionAndResponseSig() {
|
||||||
return samlServletDeployment(SalesPostAssertionAndResponseSig.DEPLOYMENT_NAME, SendUsernameServlet.class);
|
return samlServletDeployment(SalesPostAssertionAndResponseSig.DEPLOYMENT_NAME, SendUsernameServlet.class);
|
||||||
|
@ -1069,6 +1078,18 @@ public abstract class AbstractSAMLServletsAdapterTest extends AbstractServletsAd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
// KEYCLOAK-4141
|
||||||
|
public void testDifferentCookieName() {
|
||||||
|
assertSuccessfulLogin(differentCookieNameServletPage, bburkeUser, testRealmSAMLPostLoginPage, "principal=bburke");
|
||||||
|
|
||||||
|
assertThat(driver.manage().getCookieNamed("DIFFERENT_SESSION_ID"), notNullValue());
|
||||||
|
assertThat(driver.manage().getCookieNamed("JSESSIONID"), nullValue());
|
||||||
|
|
||||||
|
salesPost2ServletPage.logout();
|
||||||
|
checkLoggedOut(differentCookieNameServletPage, testRealmSAMLPostLoginPage);
|
||||||
|
}
|
||||||
|
|
||||||
private URI getAuthServerSamlEndpoint(String realm) throws IllegalArgumentException, UriBuilderException {
|
private URI getAuthServerSamlEndpoint(String realm) throws IllegalArgumentException, UriBuilderException {
|
||||||
return RealmsResource
|
return RealmsResource
|
||||||
.protocolUrl(UriBuilder.fromUri(getAuthServerRoot()))
|
.protocolUrl(UriBuilder.fromUri(getAuthServerRoot()))
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
<!--
|
||||||
|
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||||
|
~ and other contributors as indicated by the @author tags.
|
||||||
|
~
|
||||||
|
~ Licensed 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<keycloak-saml-adapter xmlns="urn:keycloak:saml:adapter"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="urn:keycloak:saml:adapter http://www.keycloak.org/schema/keycloak_saml_adapter_1_7.xsd">
|
||||||
|
<SP entityID="http://localhost:8081/different-cookie-name/"
|
||||||
|
sslPolicy="EXTERNAL"
|
||||||
|
nameIDPolicyFormat="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
|
||||||
|
logoutPage="/logout.jsp"
|
||||||
|
forceAuthentication="false">
|
||||||
|
<PrincipalNameMapping policy="FROM_NAME_ID"/>
|
||||||
|
<RoleIdentifiers>
|
||||||
|
<Attribute name="Role"/>
|
||||||
|
</RoleIdentifiers>
|
||||||
|
<IDP entityID="idp">
|
||||||
|
<SingleSignOnService requestBinding="POST"
|
||||||
|
bindingUrl="http://localhost:8080/auth/realms/demo/protocol/saml"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SingleLogoutService
|
||||||
|
requestBinding="POST"
|
||||||
|
responseBinding="POST"
|
||||||
|
postBindingUrl="http://localhost:8080/auth/realms/demo/protocol/saml"
|
||||||
|
redirectBindingUrl="http://localhost:8080/auth/realms/demo/protocol/saml"
|
||||||
|
/>
|
||||||
|
</IDP>
|
||||||
|
</SP>
|
||||||
|
</keycloak-saml-adapter>
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||||
|
~ and other contributors as indicated by the @author tags.
|
||||||
|
~
|
||||||
|
~ Licensed 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||||
|
version="3.0">
|
||||||
|
|
||||||
|
<module-name>%CONTEXT_PATH%</module-name>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>javax.ws.rs.core.Application</servlet-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<error-page>
|
||||||
|
<location>/error.html</location>
|
||||||
|
</error-page>
|
||||||
|
|
||||||
|
<security-constraint>
|
||||||
|
<web-resource-collection>
|
||||||
|
<web-resource-name>Application</web-resource-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</web-resource-collection>
|
||||||
|
<auth-constraint>
|
||||||
|
<role-name>manager</role-name>
|
||||||
|
</auth-constraint>
|
||||||
|
</security-constraint>
|
||||||
|
|
||||||
|
<login-config>
|
||||||
|
<auth-method>KEYCLOAK-SAML</auth-method>
|
||||||
|
<realm-name>demo</realm-name>
|
||||||
|
</login-config>
|
||||||
|
|
||||||
|
<security-role>
|
||||||
|
<role-name>manager</role-name>
|
||||||
|
</security-role>
|
||||||
|
|
||||||
|
<session-config>
|
||||||
|
<cookie-config>
|
||||||
|
<name>DIFFERENT_SESSION_ID</name>
|
||||||
|
</cookie-config>
|
||||||
|
</session-config>
|
||||||
|
</web-app>
|
|
@ -162,6 +162,21 @@
|
||||||
"saml_idp_initiated_sso_relay_state": "redirectTo=/foo"
|
"saml_idp_initiated_sso_relay_state": "redirectTo=/foo"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"clientId": "http://localhost:8081/different-cookie-name/",
|
||||||
|
"enabled": true,
|
||||||
|
"fullScopeAllowed": true,
|
||||||
|
"protocol": "saml",
|
||||||
|
"baseUrl": "http://localhost:8080/different-cookie-name",
|
||||||
|
"redirectUris": [
|
||||||
|
"http://localhost:8080/different-cookie-name/*"
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"saml.authnstatement": "true",
|
||||||
|
"saml_assertion_consumer_url_post": "http://localhost:8080/different-cookie-name/saml",
|
||||||
|
"saml_single_logout_service_url_post": "http://localhost:8080/different-cookie-name/saml"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"clientId": "http://localhost:8081/sales-post/",
|
"clientId": "http://localhost:8081/sales-post/",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
|
Loading…
Reference in a new issue