Updated performance tests. Added app-profile-jee test application (from qs) to the testsuite.

This commit is contained in:
Tomas Kyjovsky 2016-11-09 03:58:02 +01:00
parent 8ee2134e05
commit 5ac4a852e1
15 changed files with 485 additions and 3602 deletions

View file

@ -0,0 +1,10 @@
You need to create a client in Keycloak. The configuration options when creating the client should be:
* Client ID: You choose
* Access Type: confidential
* Root URL: Root URL for where you're hosting the application (for example http://localhost:8080)
* Valie Redirect URIs: /app-profile-jee/*
* Base URL: /app-profile-jee/
* Admin URL: /app-profile-jee/
Then, build the WAR with Maven and install as per the Adapter configuration for your server as described in the Keycloak documentation.

View file

@ -0,0 +1,56 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-test-apps</artifactId>
<version>2.4.0.CR1-SNAPSHOT</version>
</parent>
<artifactId>keycloak-test-app-profile-jee</artifactId>
<name>Keycloak Test App Profile JEE</name>
<description/>
<packaging>war</packaging>
<properties>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-adapter-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-adapter-spi</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>app-profile-jee</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,77 @@
/*
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
*
* 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.quickstart.profilejee;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.keycloak.KeycloakSecurityContext;
import org.keycloak.adapters.AdapterDeploymentContext;
import org.keycloak.adapters.KeycloakDeployment;
import org.keycloak.common.util.KeycloakUriBuilder;
import org.keycloak.constants.ServiceUrlConstants;
import org.keycloak.representations.IDToken;
import org.keycloak.util.JsonSerialization;
/**
* Controller simplifies access to the server environment from the JSP.
*
* @author Stan Silvert ssilvert@redhat.com (C) 2015 Red Hat Inc.
*/
public class Controller {
public void handleLogout(HttpServletRequest req) throws ServletException {
if (req.getParameter("logout") != null) {
req.logout();
}
}
public boolean isLoggedIn(HttpServletRequest req) {
return getSession(req) != null;
}
public boolean showToken(HttpServletRequest req) {
return req.getParameter("showToken") != null;
}
public IDToken getIDToken(HttpServletRequest req) {
return getSession(req).getIdToken();
}
public String getAccountUri(HttpServletRequest req) {
KeycloakSecurityContext session = getSession(req);
String baseUrl = getAuthServerBaseUrl(req);
String realm = session.getRealm();
return KeycloakUriBuilder.fromUri(baseUrl).path(ServiceUrlConstants.ACCOUNT_SERVICE_PATH)
.queryParam("referrer", "app-profile-jee").build(realm).toString();
}
private String getAuthServerBaseUrl(HttpServletRequest req) {
AdapterDeploymentContext deploymentContext = (AdapterDeploymentContext) req.getServletContext().getAttribute(AdapterDeploymentContext.class.getName());
KeycloakDeployment deployment = deploymentContext.resolveDeployment(null);
return deployment.getAuthServerBaseUrl();
}
public String getTokenString(HttpServletRequest req) throws IOException {
return JsonSerialization.writeValueAsPrettyString(getIDToken(req));
}
private KeycloakSecurityContext getSession(HttpServletRequest req) {
return (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
}
}

View file

@ -0,0 +1,10 @@
{
"realm": "Test",
"realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
"auth-server-url": "/auth",
"ssl-required": "external",
"resource": "app-profile-jee",
"credentials": {
"secret": "4f36f31a-be9d-4f92-b982-425301bac5df"
}
}

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
*
* 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>app-profile-jee</module-name>
<security-constraint>
<web-resource-collection>
<url-pattern>/profile.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>KEYCLOAK</auth-method>
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>
</web-app>

View file

@ -0,0 +1,47 @@
<%--
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
*
* 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.
--%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Keycloak Example App</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
<jsp:useBean id="controller" class="org.keycloak.quickstart.profilejee.Controller" scope="request"/>
<% controller.handleLogout(request); %>
<c:set var="isLoggedIn" value="<%=controller.isLoggedIn(request)%>"/>
<c:if test="${isLoggedIn}">
<c:redirect url="profile.jsp"/>
</c:if>
<div class="wrapper" id="welcome">
<div class="menu">
<button onclick="location.href = 'profile.jsp'" type="button">Login</button>
</div>
<div class="content">
<div class="message">Please login</div>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,79 @@
<%--
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
*
* 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.
--%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Keycloak Example App</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
<jsp:useBean id="controller" class="org.keycloak.quickstart.profilejee.Controller" scope="request"/>
<c:set var="idToken" value="<%=controller.getIDToken(request)%>"/>
<c:set var="tokenString" value="<%=controller.getTokenString(request)%>"/>
<c:set var="accountUri" value="<%=controller.getAccountUri(request)%>"/>
<c:set var="showToken" value="<%=controller.showToken(request)%>"/>
<div class="wrapper" id="profile">
<div class="menu">
<c:if test="${!showToken}">
<button onclick="location.href = 'profile.jsp?showToken=true'">Token</button>
</c:if>
<c:if test="${showToken}">
<button onclick="location.href = 'profile.jsp'">Profile</button>
</c:if>
<button onclick="location.href = 'index.jsp?logout=true'" type="button">Logout</button>
<button onclick="location.href = '${accountUri}'" type="button">Account</button>
</div>
<c:if test="${showToken}">
<div class="content">
<div id="token-content" class="message">${tokenString}</div>
<!-- <script>document.write(JSON.stringify(JSON.parse('${tokenString}'), null, ' '));</script>-->
</div>
</c:if>
<c:if test="${!showToken}">
<div class="content">
<div id="profile-content" class="message">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="label">First name</td>
<td><span id="firstName">${idToken.givenName}</span></td>
</tr>
<tr class="even">
<td class="label">Last name</td>
<td><span id="lastName">${idToken.familyName}</span></td>
</tr>
<tr>
<td class="label">Username</td>
<td><span id="username">${idToken.preferredUsername}</span></td>
</tr>
<tr class="even">
<td class="label">Email</td>
<td><span id="email">${idToken.email}</span></td>
</tr>
</table>
</div>
</div>
</c:if>
</div>
</body>
</html>

View file

@ -0,0 +1,101 @@
body {
background-color: #333;
font-family: sans-serif;
font-size: 30px;
}
button {
font-family: sans-serif;
font-size: 30px;
width: 200px;
background-color: #0085cf;
background-image: linear-gradient(to bottom, #00a8e1 0%, #0085cf 100%);
background-repeat: repeat-x;
border: 2px solid #ccc;
color: #fff;
-webkit-border-radius: 30px;
text-transform: uppercase;
-webkit-box-shadow: 2px 2px 10px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 2px 2px 10px 0px rgba(0,0,0,0.5);
box-shadow: 2px 2px 10px 0px rgba(0,0,0,0.5);
}
button:hover {
background-color: #006ba6;
background-image: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
hr {
border: none;
background-color: #eee;
height: 10px;
}
.menu {
padding: 10px;
margin-bottom: 10px;
}
.content {
background-color: #eee;
border: 1px solid #ccc;
padding: 10px;
-webkit-border-radius: 10px;
-webkit-box-shadow: 2px 2px 10px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 2px 2px 10px 0px rgba(0,0,0,0.5);
box-shadow: 2px 2px 10px 0px rgba(0,0,0,0.5);
}
.content .message {
padding: 10px;
background-color: #fff;
border: 1px solid #ccc;
font-size: 40px;
-webkit-border-radius: 10px;
}
#token .content .message {
font-size: 20px;
overflow: scroll;
padding: 5px;
white-space: pre;
text-transform: none;
}
.wrapper {
position: absolute;
left: 10px;
top: 10px;
bottom: 10px;
right: 10px;
}
.error {
color: #a21e22;
}
table {
width: 100%;
}
tr.even {
background-color: #eee;
}
td {
padding: 5px;
}
td.label {
font-weight: bold;
width: 250px;
}

View file

@ -22,6 +22,7 @@
<module>hello-world-authz-service</module>
<module>servlet-authz</module>
<module>servlets</module>
<module>app-profile-jee</module>
</modules>
<build>
@ -35,4 +36,4 @@
</plugin>
</plugins>
</build>
</project>
</project>

View file

@ -24,7 +24,7 @@
<parent>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>integration-arquillian-tests-adapters-jboss</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.4.0.CR1-SNAPSHOT</version>
</parent>
<artifactId>integration-arquillian-tests-adapters-remote</artifactId>
@ -70,9 +70,9 @@
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.keycloak.quickstart</groupId>
<artifactId>keycloak-quickstart-app-profile-jee</artifactId>
<version>0.5-SNAPSHOT</version>
<groupId>org.keycloak.testsuite</groupId>
<artifactId>keycloak-test-app-profile-jee</artifactId>
<version>${project.version}</version>
<type>war</type>
</artifactItem>
</artifactItems>

View file

@ -53,7 +53,7 @@ public class HttpClientLoginLogoutPerfTest extends HttpClientPerformanceTest {
private static final Logger LOG = Logger.getLogger(HttpClientLoginLogoutPerfTest.class);
private static final String EXAMPLES = "Examples";
private static final String TEST_REALM = "Test";
private String securedUrl;
private String logoutUrl;
@ -72,18 +72,18 @@ public class HttpClientLoginLogoutPerfTest extends HttpClientPerformanceTest {
@Deployment(name = AppProfileJEE.DEPLOYMENT_NAME)
private static WebArchive appProfileJEE() throws IOException {
return warDeployment("keycloak-quickstart-app-profile-jee-0.5-SNAPSHOT");
return exampleDeployment("keycloak-test-app-profile-jee");
}
@Override
public void setDefaultPageUriParameters() {
super.setDefaultPageUriParameters();
testRealmPage.setAuthRealm(EXAMPLES);
testRealmPage.setAuthRealm(TEST_REALM);
}
@Override
public void addAdapterTestRealms(List<RealmRepresentation> testRealms) {
RealmRepresentation examplesRealm = loadRealm("/examples-realm.json");
RealmRepresentation examplesRealm = loadRealm("/test-realm.json");
examplesRealm.setPasswordPolicy("hashIterations(" + PASSWORD_HASH_ITERATIONS + ")");
testRealms.add(examplesRealm);
}

View file

@ -0,0 +1,52 @@
{
"id": "Test",
"realm": "Test",
"enabled": true,
"accessTokenLifespan": 600,
"accessCodeLifespan": 10,
"accessCodeLifespanUserAction": 6000,
"sslRequired": "external",
"registrationAllowed": false,
"privateKey": "MIICXAIBAAKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQABAoGAfmO8gVhyBxdqlxmIuglbz8bcjQbhXJLR2EoS8ngTXmN1bo2L90M0mUKSdc7qF10LgETBzqL8jYlQIbt+e6TH8fcEpKCjUlyq0Mf/vVbfZSNaVycY13nTzo27iPyWQHK5NLuJzn1xvxxrUeXI6A2WFpGEBLbHjwpx5WQG9A+2scECQQDvdn9NE75HPTVPxBqsEd2z10TKkl9CZxu10Qby3iQQmWLEJ9LNmy3acvKrE3gMiYNWb6xHPKiIqOR1as7L24aTAkEAtyvQOlCvr5kAjVqrEKXalj0Tzewjweuxc0pskvArTI2Oo070h65GpoIKLc9jf+UA69cRtquwP93aZKtW06U8dQJAF2Y44ks/mK5+eyDqik3koCI08qaC8HYq2wVl7G2QkJ6sbAaILtcvD92ToOvyGyeE0flvmDZxMYlvaZnaQ0lcSQJBAKZU6umJi3/xeEbkJqMfeLclD27XGEFoPeNrmdx0q10Azp4NfJAY+Z8KRyQCR2BEG+oNitBOZ+YXF9KCpH3cdmECQHEigJhYg+ykOvr1aiZUMFT72HU0jnmQe2FVekuG+LJUt2Tm7GtMjTFoGpf0JwrVuZN39fOYAlo+nTixgeW7X8Y=",
"publicKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB",
"requiredCredentials": ["password"],
"users": [{
"username": "admin-user",
"enabled": true,
"firstName": "Admin",
"lastName": "User",
"email": "admin@user.com",
"credentials": [{
"type": "password",
"value": "password"
}],
"realmRoles": ["offline_access", "user", "admin"],
"clientRoles": {
"account": ["view-profile", "manage-account"]
}
}, {
"username": "secure-user",
"enabled": true,
"firstName": "Secure",
"lastName": "User",
"email": "secure@user.com",
"credentials": [{
"type": "password",
"value": "password"
}],
"realmRoles": ["offline_access", "user"],
"clientRoles": {
"account": ["view-profile", "manage-account"]
}
}],
"clients": [
{
"clientId": "app-profile-jee",
"enabled": true,
"adminUrl": "/app-profile-jee/",
"baseUrl": "/app-profile-jee/",
"redirectUris": ["/app-profile-jee/*"],
"secret": "4f36f31a-be9d-4f92-b982-425301bac5df"
}
]
}

View file

@ -209,7 +209,7 @@
</properties>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
</dependency>
</dependencies>