1+ package org .javaee7 .jaspic .ejbpropagation ;
2+
3+ import static org .junit .Assert .assertTrue ;
4+ import static org .junit .Assert .assertFalse ;
5+
6+ import java .io .IOException ;
7+
8+ import org .javaee7 .jaspic .common .ArquillianBase ;
9+ import org .jboss .arquillian .container .test .api .Deployment ;
10+ import org .jboss .arquillian .junit .Arquillian ;
11+ import org .jboss .shrinkwrap .api .spec .WebArchive ;
12+ import org .junit .Test ;
13+ import org .junit .runner .RunWith ;
14+ import org .xml .sax .SAXException ;
15+
16+ /**
17+ * This tests that the established authenticated identity propagates correctly
18+ * from the web layer to a "public" EJB (an EJB without declarative role
19+ * checking) and that after logging out but still within the same request this
20+ * identity is cleared.
21+ *
22+ * @author Arjan Tijms
23+ *
24+ */
25+ @ RunWith (Arquillian .class )
26+ public class PublicEJBPropagationLogoutTest extends ArquillianBase {
27+
28+ @ Deployment (testable = false )
29+ public static WebArchive createDeployment () {
30+ return defaultArchive ();
31+ }
32+
33+ @ Test
34+ public void testProtectedServletWithLoginCallingEJB () throws IOException , SAXException {
35+
36+ String response = getFromServerPath ("public/servlet-public-ejb-logout?doLogin" );
37+
38+ System .out .println (response );
39+
40+ // Both the web (HttpServletRequest) and EJB (EJBContext) should see the
41+ // same
42+ // user name.
43+
44+ assertTrue (response .contains ("web username: test" ));
45+ assertTrue ("Web has user principal set, but EJB not." , response .contains ("EJB username: test" ));
46+
47+
48+ // After logging out, both the web and EJB should no longer see the user
49+ // name
50+
51+ assertFalse (
52+ "Web module did not clear authenticated identity after logout" ,
53+ response .contains ("web username after logout: test" )
54+ );
55+ assertFalse (
56+ "EJB did not clear authenticated identity after logout" ,
57+ response .contains ("EJB username after logout: test" )
58+ );
59+
60+ }
61+
62+ }
0 commit comments