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

Commit a34e19e

Browse files
SAMEER PANDITyaminikb
authored andcommitted
Fixes #21667: SessionContext.getCallerPrincipal() returns previous principal on TimerService (#22185)
* Reset SecurityContext after ejb async call * Added test app
1 parent a19298c commit a34e19e

14 files changed

Lines changed: 826 additions & 1 deletion

File tree

appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EjbAsyncTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public V call()
103103
if (returnValue instanceof Future) {
104104
returnValue = (V) ((Future) returnValue).get();
105105
}
106-
107106
} catch (InvocationTargetException ite) {
108107
inv.exception = ite.getCause();
109108
inv.exceptionFromBeanMethod = inv.exception;
@@ -133,6 +132,7 @@ public V call()
133132
ejbFutureTask.setResultException(ee);
134133
throw ee;
135134
} finally {
135+
SecurityContext.setCurrent(null);
136136
Utility.setContextClassLoader(prevCL);
137137
}
138138
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<property name="module" value="security"/>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 "./../../../config/properties.xml">
46+
<!ENTITY commonBuild SYSTEM "./../../../config/common.xml">
47+
<!ENTITY commonRun SYSTEM "./../../../config/run.xml">
48+
<!ENTITY testProperties SYSTEM "./build.properties">
49+
<!ENTITY commonSecurity SYSTEM "./../common.xml">
50+
]>
51+
52+
53+
<project name="ejb-auth-propagation" basedir="." default="usage" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
54+
55+
&commonSetup;
56+
&commonBuild;
57+
&commonRun;
58+
&testProperties;
59+
&commonSecurity;
60+
<property environment="env"/>
61+
<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"/>
62+
<path id="maven-ant-tasks.classpath" path="${env.APS_HOME}/lib/maven-ant-tasks-2.1.3.jar" />
63+
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
64+
uri="antlib:org.apache.maven.artifact.ant"
65+
classpathref="maven-ant-tasks.classpath" />
66+
<target name="all" depends="runMaven"/>
67+
<target name="runMaven">
68+
<artifact:mvn mavenHome="${env.M2_HOME}" fork="true">
69+
<jvmarg value="-Dmaven.multiModuleProjectDirectory"/>
70+
<jvmarg value="-Dmaven.javadoc.skip=true" />
71+
<arg value="clean"/>
72+
<arg value="verify"/>
73+
</artifact:mvn>
74+
</target>
75+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!--
2+
3+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4+
5+
Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
6+
7+
The contents of this file are subject to the terms of either the GNU
8+
General Public License Version 2 only ("GPL") or the Common Development
9+
and Distribution License("CDDL") (collectively, the "License"). You
10+
may not use this file except in compliance with the License. You can
11+
obtain a copy of the License at
12+
https://oss.oracle.com/licenses/CDDL+GPL-1.1
13+
or LICENSE.txt. See the License for the specific
14+
language governing permissions and limitations under the License.
15+
16+
When distributing the software, include this License Header Notice in each
17+
file and include the License file at LICENSE.txt.
18+
19+
GPL Classpath Exception:
20+
Oracle designates this particular file as subject to the "Classpath"
21+
exception as provided by Oracle in the GPL Version 2 section of the License
22+
file that accompanied this code.
23+
24+
Modifications:
25+
If applicable, add the following below the License Header, with the fields
26+
enclosed by brackets [] replaced by your own identifying information:
27+
"Portions Copyright [year] [name of copyright owner]"
28+
29+
Contributor(s):
30+
If you wish your version of this file to be governed by only the CDDL or
31+
only the GPL Version 2, indicate your decision by adding "[Contributor]
32+
elects to include this software in this distribution under the [CDDL or GPL
33+
Version 2] license." If you don't indicate a single choice of license, a
34+
recipient has the option to distribute your version of this file under
35+
either the CDDL, the GPL Version 2 or to extend the choice of license to
36+
its licensees as provided above. However, if you add GPL Version 2 code
37+
and therefore, elected the GPL Version 2 license, then the option applies
38+
only if the new code is made subject to such option by the copyright
39+
holder.
40+
41+
-->
42+
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
45+
<parent>
46+
<groupId>org.glassfish.main</groupId>
47+
<artifactId>glassfish-nucleus-parent</artifactId>
48+
<version>5.0-SNAPSHOT</version>
49+
<relativePath/>
50+
</parent>
51+
<modelVersion>4.0.0</modelVersion>
52+
<groupId>org.glassfish.test.authpropagation</groupId>
53+
<artifactId>scheduler-service</artifactId>
54+
<version>1.0-SNAPSHOT</version>
55+
<packaging>war</packaging>
56+
<dependencies>
57+
<dependency>
58+
<groupId>javax</groupId>
59+
<artifactId>javaee-api</artifactId>
60+
<version>7.0</version>
61+
<scope>provided</scope>
62+
</dependency>
63+
</dependencies>
64+
<build>
65+
<finalName>scheduler-service</finalName>
66+
</build>
67+
<properties>
68+
<maven.compiler.source>1.8</maven.compiler.source>
69+
<maven.compiler.target>1.8</maven.compiler.target>
70+
<failOnMissingWebXml>false</failOnMissingWebXml>
71+
</properties>
72+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.test.authpropagation;
42+
43+
import javax.ejb.EJB;
44+
import javax.servlet.http.HttpServletRequest;
45+
import javax.ws.rs.GET;
46+
import javax.ws.rs.POST;
47+
import javax.ws.rs.Path;
48+
import javax.ws.rs.core.Context;
49+
import javax.ws.rs.core.Response;
50+
51+
@Path("/")
52+
public class AppResource {
53+
@EJB
54+
private Service service;
55+
56+
@GET
57+
public Response hello() throws Exception {
58+
return Response.ok("hello").build();
59+
}
60+
61+
@POST
62+
public Response login(@Context HttpServletRequest request) throws Exception {
63+
request.getSession(true);
64+
request.login("user1", "user1");
65+
service.exec();
66+
return Response.ok("ok").build();
67+
}
68+
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.test.authpropagation;
42+
43+
import javax.persistence.*;
44+
import java.io.Serializable;
45+
import java.util.List;
46+
47+
@Entity
48+
public class AuthGroup implements Serializable {
49+
50+
51+
@Id
52+
private String groupName;
53+
54+
@ManyToMany
55+
@JoinTable(
56+
joinColumns = @JoinColumn(name = "groupName", referencedColumnName = "groupName"),
57+
inverseJoinColumns = @JoinColumn(name = "userName", referencedColumnName = "userName"))
58+
private List<MyUser> users;
59+
60+
61+
protected AuthGroup() {
62+
super();
63+
}
64+
65+
public AuthGroup(String groupName, List<MyUser> users) {
66+
this.groupName = groupName;
67+
this.users = users;
68+
}
69+
}

0 commit comments

Comments
 (0)