Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final issue 109 #113

Merged
merged 12 commits into from
Oct 27, 2023
4 changes: 2 additions & 2 deletions finish/src/main/liberty/config/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<!-- tag::simple-config[] -->
<cors domain="/configurations/simple"
allowedOrigins="openliberty.io"
allowedOrigins="http://openliberty.io"
allowedMethods="GET"
allowCredentials="true"
exposeHeaders="MyHeader"/>
Expand All @@ -29,4 +29,4 @@
allowedHeaders="MyOwnHeader1, MyOwnHeader2"
maxAge="10"/>
<!-- end::preflight-config[] -->
</server>
</server>
94 changes: 61 additions & 33 deletions finish/src/test/java/it/io/openliberty/guides/cors/TestData.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,83 @@
// tag::comment[]
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017 IBM Corporation and others.
* Copyright (c) 2017, 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* http://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* IBM Corporation - Initial implementation
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
// end::comment[]
// end::copyright[]
package it.io.openliberty.guides.cors;

import java.util.HashMap;
import java.util.Map;

public class TestData {

public static String REQUEST_HEADER_ORIGIN = "Origin";
public static String REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method";
public static String REQUEST_HEADER_ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
public static String requestHeaderOrigin;
public static String requestHeaderAccessControlRequestMethod;
public static String requestHeaderAccessControlRequestHeaders;
public static String responseHeaderAccessControlAllowOrigin;
public static String responseHeaderAccessControlAllowCredentials;
public static String responseHeaderAccessControlExposeHeaders;
public static String responseHeaderAccessControlMaxAge;
public static String responseHeaderAccessControlAllowMethods;
public static String responseHeaderAccessControlAllowHeaders;
public static Map<String, String> simpleRequestHeaders;
public static Map<String, String> simpleResponseHeaders;
public static Map<String, String> preflightRequestHeaders;
public static Map<String, String> preflightResponseHeaders;

public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
public static String RESPONSE_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
public static String RESPONSE_HEADER_ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age";
public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
public static String prefix;

public static Map<String, String> simpleRequestHeaders = new HashMap<String, String>();
public static Map<String, String> simpleResponseHeaders = new HashMap<String, String>();
static {

public static Map<String, String> preflightRequestHeaders = new HashMap<String, String>();
public static Map<String, String> preflightResponseHeaders = new HashMap<String, String>();
prefix = "Access-Control-";

static {
simpleRequestHeaders.put(REQUEST_HEADER_ORIGIN, "openliberty.io");
requestHeaderOrigin = "Origin";
requestHeaderAccessControlRequestMethod = prefix + "Request-Method";
requestHeaderAccessControlRequestHeaders = prefix + "Request-Headers";

responseHeaderAccessControlAllowOrigin = prefix + "Allow-Origin";
responseHeaderAccessControlAllowCredentials = prefix + "Allow-Credentials";
responseHeaderAccessControlExposeHeaders = prefix + "Expose-Headers";
responseHeaderAccessControlMaxAge = prefix + "Max-Age";
responseHeaderAccessControlAllowMethods = prefix + "Allow-Methods";
responseHeaderAccessControlAllowHeaders = prefix + "Allow-Headers";

simpleRequestHeaders = new HashMap<String, String>();
simpleResponseHeaders = new HashMap<String, String>();

preflightRequestHeaders = new HashMap<String, String>();
preflightResponseHeaders = new HashMap<String, String>();


simpleRequestHeaders.put(requestHeaderOrigin, "http://openliberty.io");

simpleResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "openliberty.io");
simpleResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
simpleResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS, "MyHeader");
simpleResponseHeaders.put(responseHeaderAccessControlAllowOrigin,
"http://openliberty.io");
simpleResponseHeaders.put(responseHeaderAccessControlAllowCredentials,
"true");
simpleResponseHeaders.put(responseHeaderAccessControlExposeHeaders,
"MyHeader");

preflightRequestHeaders.put(REQUEST_HEADER_ORIGIN, "anywebsiteyoulike.com");
preflightRequestHeaders.put(REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD, "DELETE");
preflightRequestHeaders.put(REQUEST_HEADER_ACCESS_CONTROL_REQUEST_HEADERS, "MyOwnHeader2");
preflightRequestHeaders.put(requestHeaderOrigin, "anywebsiteyoulike.com");
preflightRequestHeaders.put(requestHeaderAccessControlRequestMethod,
"DELETE");
preflightRequestHeaders.put(requestHeaderAccessControlRequestHeaders,
"MyOwnHeader2");

preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "anywebsiteyoulike.com");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_MAX_AGE, "10");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_METHODS, "OPTIONS, DELETE");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_HEADERS, "MyOwnHeader1, MyOwnHeader2");
preflightResponseHeaders.put(responseHeaderAccessControlAllowOrigin,
"anywebsiteyoulike.com");
preflightResponseHeaders.put(responseHeaderAccessControlAllowCredentials,
"true");
preflightResponseHeaders.put(responseHeaderAccessControlMaxAge, "10");
preflightResponseHeaders.put(responseHeaderAccessControlAllowMethods,
"OPTIONS, DELETE");
preflightResponseHeaders.put(responseHeaderAccessControlAllowHeaders,
"MyOwnHeader1, MyOwnHeader2");
}

}
94 changes: 61 additions & 33 deletions start/src/test/java/it/io/openliberty/guides/cors/TestData.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,83 @@
// tag::comment[]
// tag::copyright[]
/*******************************************************************************
* Copyright (c) 2017 IBM Corporation and others.
* Copyright (c) 2017, 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* http://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* IBM Corporation - Initial implementation
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
// end::comment[]
// end::copyright[]
package it.io.openliberty.guides.cors;

import java.util.HashMap;
import java.util.Map;

public class TestData {

public static String REQUEST_HEADER_ORIGIN = "Origin";
public static String REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method";
public static String REQUEST_HEADER_ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
public static String requestHeaderOrigin;
public static String requestHeaderAccessControlRequestMethod;
public static String requestHeaderAccessControlRequestHeaders;
public static String responseHeaderAccessControlAllowOrigin;
public static String responseHeaderAccessControlAllowCredentials;
public static String responseHeaderAccessControlExposeHeaders;
public static String responseHeaderAccessControlMaxAge;
public static String responseHeaderAccessControlAllowMethods;
public static String responseHeaderAccessControlAllowHeaders;
public static Map<String, String> simpleRequestHeaders;
public static Map<String, String> simpleResponseHeaders;
public static Map<String, String> preflightRequestHeaders;
public static Map<String, String> preflightResponseHeaders;

public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
public static String RESPONSE_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS = "Access-Control-Expose-Headers";
public static String RESPONSE_HEADER_ACCESS_CONTROL_MAX_AGE = "Access-Control-Max-Age";
public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
public static String RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
public static String prefix;

public static Map<String, String> simpleRequestHeaders = new HashMap<String, String>();
public static Map<String, String> simpleResponseHeaders = new HashMap<String, String>();
static {

public static Map<String, String> preflightRequestHeaders = new HashMap<String, String>();
public static Map<String, String> preflightResponseHeaders = new HashMap<String, String>();
prefix = "Access-Control-";

static {
simpleRequestHeaders.put(REQUEST_HEADER_ORIGIN, "openliberty.io");
requestHeaderOrigin = "Origin";
requestHeaderAccessControlRequestMethod = prefix + "Request-Method";
requestHeaderAccessControlRequestHeaders = prefix + "Request-Headers";

responseHeaderAccessControlAllowOrigin = prefix + "Allow-Origin";
responseHeaderAccessControlAllowCredentials = prefix + "Allow-Credentials";
responseHeaderAccessControlExposeHeaders = prefix + "Expose-Headers";
responseHeaderAccessControlMaxAge = prefix + "Max-Age";
responseHeaderAccessControlAllowMethods = prefix + "Allow-Methods";
responseHeaderAccessControlAllowHeaders = prefix + "Allow-Headers";

simpleRequestHeaders = new HashMap<String, String>();
simpleResponseHeaders = new HashMap<String, String>();

preflightRequestHeaders = new HashMap<String, String>();
preflightResponseHeaders = new HashMap<String, String>();


simpleRequestHeaders.put(requestHeaderOrigin, "http://openliberty.io");

simpleResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "openliberty.io");
simpleResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
simpleResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS, "MyHeader");
simpleResponseHeaders.put(responseHeaderAccessControlAllowOrigin,
"http://openliberty.io");
simpleResponseHeaders.put(responseHeaderAccessControlAllowCredentials,
"true");
simpleResponseHeaders.put(responseHeaderAccessControlExposeHeaders,
"MyHeader");

preflightRequestHeaders.put(REQUEST_HEADER_ORIGIN, "anywebsiteyoulike.com");
preflightRequestHeaders.put(REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD, "DELETE");
preflightRequestHeaders.put(REQUEST_HEADER_ACCESS_CONTROL_REQUEST_HEADERS, "MyOwnHeader2");
preflightRequestHeaders.put(requestHeaderOrigin, "anywebsiteyoulike.com");
preflightRequestHeaders.put(requestHeaderAccessControlRequestMethod,
"DELETE");
preflightRequestHeaders.put(requestHeaderAccessControlRequestHeaders,
"MyOwnHeader2");

preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "anywebsiteyoulike.com");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_MAX_AGE, "10");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_METHODS, "OPTIONS, DELETE");
preflightResponseHeaders.put(RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_HEADERS, "MyOwnHeader1, MyOwnHeader2");
preflightResponseHeaders.put(responseHeaderAccessControlAllowOrigin,
"anywebsiteyoulike.com");
preflightResponseHeaders.put(responseHeaderAccessControlAllowCredentials,
"true");
preflightResponseHeaders.put(responseHeaderAccessControlMaxAge, "10");
preflightResponseHeaders.put(responseHeaderAccessControlAllowMethods,
"OPTIONS, DELETE");
preflightResponseHeaders.put(responseHeaderAccessControlAllowHeaders,
"MyOwnHeader1, MyOwnHeader2");
}

}