Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 313d03a

Browse files
SAMEER PANDITyaminikb
authored andcommitted
Fixes #21844: add current security context to SecurityContext thread … (#21861)
* Added securityContext tests
1 parent d6caf4e commit 313d03a

File tree

22 files changed

+1558
-31
lines changed

22 files changed

+1558
-31
lines changed

appserver/security/webintegration/src/main/java/com/sun/web/security/RealmAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,7 @@ private boolean validate(HttpRequest request,
16991699
!principalSetContainsOnlyAnonymousPrincipal(principalSet)) {
17001700

17011701
SecurityContext ctx = new SecurityContext(subject);
1702+
SecurityContext.setCurrent(ctx);
17021703
//XXX assuming no null principal here
17031704
Principal p = ctx.getCallerPrincipal();
17041705
WebPrincipal wp = new WebPrincipal(p, ctx);

appserver/tests/appserv-tests/devtests/security/jaccApi/build.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@
7878
<antcall target="run-ejbtests"/>
7979
<antcall target="run-urltests"/>
8080
<antcall target="run-webtests"/>
81+
<antcall target="run-prog-auth"/>
8182
</target>
8283

84+
<target name="run-prog-auth">
85+
<ant dir="prog-auth" target="all"/>
86+
</target>
8387
<target name="run-test" depends="init-common">
8488
<java classname="javax.security.jacc.Test" fork="yes"
8589
classpath="${s1astest.classpath}"/>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE project [
3+
<!--
4+
5+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6+
7+
Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
8+
9+
The contents of this file are subject to the terms of either the GNU
10+
General Public License Version 2 only ("GPL") or the Common Development
11+
and Distribution License("CDDL") (collectively, the "License"). You
12+
may not use this file except in compliance with the License. You can
13+
obtain a copy of the License at
14+
https://oss.oracle.com/licenses/CDDL+GPL-1.1
15+
or LICENSE.txt. See the License for the specific
16+
language governing permissions and limitations under the License.
17+
18+
When distributing the software, include this License Header Notice in each
19+
file and include the License file at LICENSE.txt.
20+
21+
GPL Classpath Exception:
22+
Oracle designates this particular file as subject to the "Classpath"
23+
exception as provided by Oracle in the GPL Version 2 section of the License
24+
file that accompanied this code.
25+
26+
Modifications:
27+
If applicable, add the following below the License Header, with the fields
28+
enclosed by brackets [] replaced by your own identifying information:
29+
"Portions Copyright [year] [name of copyright owner]"
30+
31+
Contributor(s):
32+
If you wish your version of this file to be governed by only the CDDL or
33+
only the GPL Version 2, indicate your decision by adding "[Contributor]
34+
elects to include this software in this distribution under the [CDDL or GPL
35+
Version 2] license." If you don't indicate a single choice of license, a
36+
recipient has the option to distribute your version of this file under
37+
either the CDDL, the GPL Version 2 or to extend the choice of license to
38+
its licensees as provided above. However, if you add GPL Version 2 code
39+
and therefore, elected the GPL Version 2 license, then the option applies
40+
only if the new code is made subject to such option by the copyright
41+
holder.
42+
43+
-->
44+
45+
<!ENTITY commonSetup SYSTEM "file:./../../../../config/properties.xml">
46+
<!ENTITY commonBuild SYSTEM "file:./../../../../config/common.xml">
47+
<!ENTITY commonRun SYSTEM "file:./../../../../config/run.xml">
48+
<!ENTITY testProperties SYSTEM "./../build.properties">
49+
]>
50+
51+
<project name="prog-auth" basedir="." default="usage" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
52+
53+
&commonSetup;
54+
&commonBuild;
55+
&commonRun;
56+
&testProperties;
57+
<property environment="env"/>
58+
<get src="http://central.maven.org/maven2/org/apache/maven/maven-ant-tasks/2.1.3/maven-ant-tasks-2.1.3.jar" dest="${env.APS_HOME}/lib/maven-ant-tasks-2.1.3.jar"/>
59+
<path id="maven-ant-tasks.classpath" path="${env.APS_HOME}/lib/maven-ant-tasks-2.1.3.jar" />
60+
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
61+
uri="antlib:org.apache.maven.artifact.ant"
62+
classpathref="maven-ant-tasks.classpath" />
63+
<target name="all" depends="runMaven"/>
64+
<target name="runMaven">
65+
<artifact:mvn mavenHome="${env.M2_HOME}" fork="true">
66+
<jvmarg value="-Dmaven.multiModuleProjectDirectory"/>
67+
<jvmarg value="-Dmaven.javadoc.skip=true" />
68+
<arg value="clean"/>
69+
<arg value="verify"/>
70+
</artifact:mvn>
71+
</target>
72+
</project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
https://oss.oracle.com/licenses/CDDL+GPL-1.1
14+
or LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
44+
<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/xsd/maven-4.0.0.xsd">
45+
<modelVersion>4.0.0</modelVersion>
46+
47+
<parent>
48+
<groupId>org.glassfish.jaccApi.test</groupId>
49+
<artifactId>prog-auth</artifactId>
50+
<version>5.0-SNAPSHOT</version>
51+
</parent>
52+
53+
<artifactId>jaccApi-common</artifactId>
54+
55+
<packaging>jar</packaging>
56+
<name>Java EE 7 Sample: jaccApi- common</name>
57+
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.jboss.arquillian.junit</groupId>
61+
<artifactId>arquillian-junit-container</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.jsoup</groupId>
65+
<artifactId>jsoup</artifactId>
66+
<version>1.9.2</version>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>junit</groupId>
71+
<artifactId>junit</artifactId>
72+
<version>4.11</version>
73+
<scope>provided</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>net.sourceforge.htmlunit</groupId>
77+
<artifactId>htmlunit</artifactId>
78+
<version>2.23</version>
79+
<scope>provided</scope>
80+
</dependency>
81+
</dependencies>
82+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://oss.oracle.com/licenses/CDDL+GPL-1.1
12+
* or LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jaccApi.common;
42+
43+
import static java.lang.Boolean.getBoolean;
44+
import static java.util.logging.Level.SEVERE;
45+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
46+
import static org.jsoup.Jsoup.parse;
47+
import static org.jsoup.parser.Parser.xmlParser;
48+
49+
import java.io.File;
50+
import java.io.IOException;
51+
import java.net.URL;
52+
import java.util.logging.Logger;
53+
54+
import org.jboss.arquillian.test.api.ArquillianResource;
55+
import org.jboss.shrinkwrap.api.Archive;
56+
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
57+
import org.jboss.shrinkwrap.api.spec.WebArchive;
58+
import org.junit.After;
59+
import org.junit.Before;
60+
import org.junit.Rule;
61+
import org.junit.rules.TestWatcher;
62+
import org.junit.runner.Description;
63+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
64+
65+
import java.io.File;
66+
67+
import org.jboss.shrinkwrap.api.importer.ZipImporter;
68+
import org.jboss.shrinkwrap.api.spec.WebArchive;
69+
70+
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
71+
import com.gargoylesoftware.htmlunit.WebClient;
72+
73+
/**
74+
*
75+
*
76+
*/
77+
public class ArquillianBase {
78+
79+
private static final String WEBAPP_SRC = "src/main/webapp";
80+
private static final Logger logger = Logger.getLogger(ArquillianBase.class.getName());
81+
82+
private WebClient webClient;
83+
private String response;
84+
85+
@Rule
86+
public TestWatcher ruleExample = new TestWatcher() {
87+
@Override
88+
protected void failed(Throwable e, Description description) {
89+
super.failed(e, description);
90+
91+
logger.log(SEVERE,
92+
"\n\nTest failed: " +
93+
description.getClassName() + "." + description.getMethodName() +
94+
95+
"\nMessage: " + e.getMessage() +
96+
97+
"\nLast response: " +
98+
99+
"\n\n" + formatHTML(response) + "\n\n");
100+
101+
}
102+
};
103+
104+
public static String formatHTML(String html) {
105+
try {
106+
return parse(html, "", xmlParser()).toString();
107+
} catch (Exception e) {
108+
return html;
109+
}
110+
}
111+
112+
public static Archive<?> defaultArchive() {
113+
return tryWrapEAR(defaultWebArchive());
114+
}
115+
116+
public static WebArchive defaultWebArchive() {
117+
return
118+
create(WebArchive.class, "test.war")
119+
.addPackages(true, "org.javaee7.jaspic")
120+
.deleteClass(ArquillianBase.class)
121+
.addAsWebInfResource(resource("web.xml"))
122+
.addAsWebInfResource(resource("jboss-web.xml"))
123+
.addAsWebInfResource(resource("glassfish-web.xml"));
124+
}
125+
126+
public static WebArchive mavenWar() {
127+
return create(ZipImporter.class, System.getProperty("finalName") + ".war")
128+
.importFrom(new File("target/" + System.getProperty("finalName") + ".war"))
129+
.as(WebArchive.class);
130+
}
131+
132+
public static Archive<?> tryWrapEAR(WebArchive webArchive) {
133+
if (getBoolean("useEarForJaspic")) {
134+
return
135+
// EAR archive
136+
create(EnterpriseArchive.class, "test.ear")
137+
138+
// Liberty needs to have the binding file in an ear.
139+
// TODO: this is no longer the case and this code can be removed (-bnd.xml
140+
// needs to be moved to correct place)
141+
.addAsManifestResource(resource("ibm-application-bnd.xml"))
142+
143+
// Web module
144+
// This is needed to prevent Arquillian generating an illegal application.xml
145+
.addAsModule(
146+
webArchive
147+
);
148+
} else {
149+
return webArchive;
150+
}
151+
}
152+
153+
public static File resource(String name) {
154+
return new File(WEBAPP_SRC + "/WEB-INF", name);
155+
}
156+
157+
public static File web(String name) {
158+
return new File(WEBAPP_SRC, name);
159+
}
160+
161+
@ArquillianResource
162+
private URL base;
163+
164+
@Before
165+
public void setUp() {
166+
webClient = new WebClient();
167+
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
168+
}
169+
170+
@After
171+
public void tearDown() {
172+
webClient.getCookieManager().clearCookies();
173+
webClient.close();
174+
}
175+
176+
177+
178+
protected WebClient getWebClient() {
179+
return webClient;
180+
}
181+
182+
protected URL getBase() {
183+
return base;
184+
}
185+
186+
/**
187+
* Gets content from the path that's relative to the base URL on which the Arquillian test
188+
* archive is deployed.
189+
*
190+
* @param path the path relative to the URL on which the Arquillian test is deployed
191+
* @return the raw content as a string as returned by the server
192+
*/
193+
protected String getFromServerPath(final String path) {
194+
response = null;
195+
for (int i=0; i<=3; i++) {
196+
try {
197+
response = webClient.getPage(base + path).getWebResponse().getContentAsString();
198+
if (!response.contains("The response wrapper must wrap the response obtained from getResponse()")) {
199+
return response;
200+
}
201+
} catch (FailingHttpStatusCodeException | IOException e) {
202+
throw new IllegalStateException(e);
203+
}
204+
}
205+
206+
return response;
207+
}
208+
209+
}

0 commit comments

Comments
 (0)