Skip to content

Commit 78b5668

Browse files
committed
Merge pull request #331 from arjantijms/master
Added query parameter values for Liberty in default configuration
2 parents 3f52c35 + 0b303a0 commit 78b5668

File tree

10 files changed

+115
-32
lines changed

10 files changed

+115
-32
lines changed

jaspic/ejb-propagation/src/main/java/org/javaee7/jaspic/ejbpropagation/servlet/ProtectedServletProtectedEJB.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.javaee7.jaspic.ejbpropagation.servlet;
22

3+
import static java.util.logging.Level.SEVERE;
4+
35
import java.io.IOException;
6+
import java.util.logging.Logger;
47

58
import javax.ejb.EJB;
69
import javax.servlet.ServletException;
@@ -20,6 +23,7 @@
2023
public class ProtectedServletProtectedEJB extends HttpServlet {
2124

2225
private static final long serialVersionUID = 1L;
26+
private final static Logger logger = Logger.getLogger(ProtectedServletProtectedEJB.class.getName());
2327

2428
@EJB
2529
private ProtectedEJB protectedEJB;
@@ -32,12 +36,23 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
3236
webName = request.getUserPrincipal().getName();
3337
}
3438

35-
String ejbName = protectedEJB.getUserName();
39+
String ejbName = "";
40+
try {
41+
ejbName = protectedEJB.getUserName();
42+
} catch (Exception e) {
43+
logger.log(SEVERE, "", e);
44+
}
3645

3746
response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
3847

3948
boolean webHasRole = request.isUserInRole("architect");
40-
boolean ejbHasRole = protectedEJB.isUserArchitect();
49+
50+
boolean ejbHasRole = false;
51+
try {
52+
ejbHasRole = protectedEJB.isUserArchitect();
53+
} catch (Exception e) {
54+
logger.log(SEVERE, "", e);
55+
}
4156

4257
response.getWriter().write(
4358
"web user has role \"architect\": " + webHasRole + "\n" + "EJB user has role \"architect\": " + ejbHasRole

jaspic/ejb-propagation/src/main/java/org/javaee7/jaspic/ejbpropagation/servlet/ProtectedServletPublicEJB.java

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.javaee7.jaspic.ejbpropagation.servlet;
22

3+
import static java.util.logging.Level.SEVERE;
4+
35
import java.io.IOException;
6+
import java.util.logging.Logger;
47

58
import javax.ejb.EJB;
69
import javax.servlet.ServletException;
@@ -20,6 +23,7 @@
2023
public class ProtectedServletPublicEJB extends HttpServlet {
2124

2225
private static final long serialVersionUID = 1L;
26+
private final static Logger logger = Logger.getLogger(ProtectedServletPublicEJB.class.getName());
2327

2428
@EJB
2529
private PublicEJB publicEJB;
@@ -33,6 +37,11 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
3337
}
3438

3539
String ejbName = publicEJB.getUserName();
40+
try {
41+
ejbName = publicEJB.getUserName();
42+
} catch (Exception e) {
43+
logger.log(SEVERE, "", e);
44+
}
3645

3746
response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
3847

jaspic/ejb-propagation/src/main/java/org/javaee7/jaspic/ejbpropagation/servlet/PublicServletProtectedEJB.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.javaee7.jaspic.ejbpropagation.servlet;
22

3+
import static java.util.logging.Level.SEVERE;
4+
35
import java.io.IOException;
6+
import java.util.logging.Logger;
47

58
import javax.ejb.EJB;
69
import javax.servlet.ServletException;
@@ -20,6 +23,7 @@
2023
public class PublicServletProtectedEJB extends HttpServlet {
2124

2225
private static final long serialVersionUID = 1L;
26+
private final static Logger logger = Logger.getLogger(PublicServletProtectedEJB.class.getName());
2327

2428
@EJB
2529
private ProtectedEJB protectedEJB;
@@ -32,12 +36,23 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
3236
webName = request.getUserPrincipal().getName();
3337
}
3438

35-
String ejbName = protectedEJB.getUserName();
39+
String ejbName = "";
40+
try {
41+
ejbName = protectedEJB.getUserName();
42+
} catch (Exception e) {
43+
logger.log(SEVERE, "", e);
44+
}
3645

3746
response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
3847

3948
boolean webHasRole = request.isUserInRole("architect");
40-
boolean ejbHasRole = protectedEJB.isUserArchitect();
49+
50+
boolean ejbHasRole = false;
51+
try {
52+
ejbHasRole = protectedEJB.isUserArchitect();
53+
} catch (Exception e) {
54+
logger.log(SEVERE, "", e);
55+
}
4156

4257
response.getWriter().write(
4358
"web user has role \"architect\": " + webHasRole + "\n" + "EJB user has role \"architect\": " + ejbHasRole

jaspic/ejb-propagation/src/main/java/org/javaee7/jaspic/ejbpropagation/servlet/PublicServletPublicEJB.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.javaee7.jaspic.ejbpropagation.servlet;
22

3+
import static java.util.logging.Level.SEVERE;
4+
35
import java.io.IOException;
6+
import java.util.logging.Logger;
47

58
import javax.ejb.EJB;
69
import javax.servlet.ServletException;
@@ -20,6 +23,7 @@
2023
public class PublicServletPublicEJB extends HttpServlet {
2124

2225
private static final long serialVersionUID = 1L;
26+
private final static Logger logger = Logger.getLogger(PublicServletPublicEJB.class.getName());
2327

2428
@EJB
2529
private PublicEJB publicEJB;
@@ -32,7 +36,12 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
3236
webName = request.getUserPrincipal().getName();
3337
}
3438

35-
String ejbName = publicEJB.getUserName();
39+
String ejbName = "";
40+
try {
41+
ejbName = publicEJB.getUserName();
42+
} catch (Exception e) {
43+
logger.log(SEVERE, "", e);
44+
}
3645

3746
response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
3847

jaspic/ejb-propagation/src/main/java/org/javaee7/jaspic/ejbpropagation/servlet/PublicServletPublicEJBLogout.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.javaee7.jaspic.ejbpropagation.servlet;
22

3+
import static java.util.logging.Level.SEVERE;
4+
35
import java.io.IOException;
6+
import java.util.logging.Logger;
47

58
import javax.ejb.EJB;
69
import javax.servlet.ServletException;
@@ -21,6 +24,7 @@
2124
public class PublicServletPublicEJBLogout extends HttpServlet {
2225

2326
private static final long serialVersionUID = 1L;
27+
private final static Logger logger = Logger.getLogger(PublicServletPublicEJBLogout.class.getName());
2428

2529
@EJB
2630
private PublicEJB publicEJB;
@@ -32,8 +36,13 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
3236
if (request.getUserPrincipal() != null) {
3337
webName = request.getUserPrincipal().getName();
3438
}
35-
36-
String ejbName = publicEJB.getUserName();
39+
40+
String ejbName = "";
41+
try {
42+
ejbName = publicEJB.getUserName();
43+
} catch (Exception e) {
44+
logger.log(SEVERE, "", e);
45+
}
3746

3847
request.logout();
3948
HttpSession session = request.getSession(false);
@@ -46,7 +55,12 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
4655
webNameAfterLogout = request.getUserPrincipal().getName();
4756
}
4857

49-
String ejbNameAfterLogout = publicEJB.getUserName();
58+
String ejbNameAfterLogout = "";
59+
try {
60+
ejbNameAfterLogout = publicEJB.getUserName();
61+
} catch (Exception e) {
62+
logger.log(SEVERE, "", e);
63+
}
5064

5165
response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
5266
response.getWriter().write("web username after logout: " + webNameAfterLogout + "\n" + "EJB username after logout: " + ejbNameAfterLogout + "\n");

jaspic/ejb-propagation/src/test/java/org/javaee7/jaspic/ejbpropagation/ProtectedEJBPropagationTest.java

+20-6
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ public static Archive<?> createDeployment() {
2828
}
2929

3030
@Test
31-
public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXException {
31+
public void protectedServletCallingProtectedEJB() throws IOException, SAXException {
3232

3333
String response = getFromServerPath("protected/servlet-protected-ejb?doLogin=true");
3434

3535
// Both the web (HttpServletRequest) and EJB (EJBContext) should see the same
3636
// user name.
37-
assertTrue(response.contains("web username: test"));
38-
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
37+
assertTrue(
38+
"User should have been authenticated in the web layer and given name \"test\", " +
39+
" but does not appear to have this name",
40+
response.contains("web username: test")
41+
);
42+
assertTrue(
43+
"Web has user principal set, but EJB not.",
44+
response.contains("EJB username: test")
45+
);
3946

4047
// Both the web (HttpServletRequest) and EJB (EJBContext) should see that the
4148
// user has the role "architect".
@@ -50,14 +57,21 @@ public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXExc
5057
*
5158
*/
5259
@Test
53-
public void testPublicServletWithLoginCallingEJB() throws IOException, SAXException {
60+
public void publicServletCallingProtectedEJB() throws IOException, SAXException {
5461

5562
String response = getFromServerPath("public/servlet-protected-ejb?doLogin=true");
5663

5764
// Both the web (HttpServletRequest) and EJB (EJBContext) should see the same
5865
// user name.
59-
assertTrue(response.contains("web username: test"));
60-
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
66+
assertTrue(
67+
"User should have been authenticated in the web layer and given name \"test\", " +
68+
" but does not appear to have this name",
69+
response.contains("web username: test")
70+
);
71+
assertTrue(
72+
"Web has user principal set, but EJB not.",
73+
response.contains("EJB username: test")
74+
);
6175

6276
// Both the web (HttpServletRequest) and EJB (EJBContext) should see that the
6377
// user has the role "architect".

jaspic/ejb-propagation/src/test/java/org/javaee7/jaspic/ejbpropagation/PublicEJBPropagationLogoutTest.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import static org.junit.Assert.assertFalse;
44
import static org.junit.Assert.assertTrue;
55

6-
import java.io.IOException;
7-
86
import org.javaee7.jaspic.common.ArquillianBase;
97
import org.jboss.arquillian.container.test.api.Deployment;
108
import org.jboss.arquillian.junit.Arquillian;
119
import org.jboss.shrinkwrap.api.Archive;
1210
import org.junit.Test;
1311
import org.junit.runner.RunWith;
14-
import org.xml.sax.SAXException;
1512

1613
/**
1714
* This tests that the established authenticated identity propagates correctly
@@ -31,18 +28,24 @@ public static Archive<?> createDeployment() {
3128
}
3229

3330
@Test
34-
public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXException {
31+
public void publicServletCallingPublicEJBThenLogout() {
3532

3633
String response = getFromServerPath("public/servlet-public-ejb-logout?doLogin=true");
3734

3835
System.out.println(response);
3936

4037
// Both the web (HttpServletRequest) and EJB (EJBContext) should see the
41-
// same
42-
// user name.
38+
// same user name.
4339

44-
assertTrue(response.contains("web username: test"));
45-
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
40+
assertTrue(
41+
"User should have been authenticated in the web layer and given name \"test\", " +
42+
" but does not appear to have this name",
43+
response.contains("web username: test")
44+
);
45+
assertTrue(
46+
"Web has user principal set, but EJB not.",
47+
response.contains("EJB username: test")
48+
);
4649

4750

4851
// After logging out, both the web and EJB should no longer see the user

jaspic/ejb-propagation/src/test/java/org/javaee7/jaspic/ejbpropagation/PublicEJBPropagationTest.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import static org.junit.Assert.assertTrue;
44

5-
import java.io.IOException;
6-
75
import org.javaee7.jaspic.common.ArquillianBase;
86
import org.jboss.arquillian.container.test.api.Deployment;
97
import org.jboss.arquillian.junit.Arquillian;
108
import org.jboss.shrinkwrap.api.Archive;
119
import org.junit.Test;
1210
import org.junit.runner.RunWith;
13-
import org.xml.sax.SAXException;
1411

1512
/**
1613
* This tests that the established authenticated identity propagates correctly from the web layer to a "public" EJB (an EJB
@@ -28,14 +25,21 @@ public static Archive<?> createDeployment() {
2825
}
2926

3027
@Test
31-
public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXException {
28+
public void protectedServletCallingPublicEJB() {
3229

3330
String response = getFromServerPath("protected/servlet-public-ejb?doLogin=true");
3431

3532
// Both the web (HttpServletRequest) and EJB (EJBContext) should see the same
3633
// user name.
37-
assertTrue(response.contains("web username: test"));
38-
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
34+
assertTrue(
35+
"User should have been authenticated in the web layer and given name \"test\", " +
36+
" but does not appear to have this name",
37+
response.contains("web username: test")
38+
);
39+
assertTrue(
40+
"Web has user principal set, but EJB not.",
41+
response.contains("EJB username: test")
42+
);
3943
}
4044

4145
}

jaspic/lifecycle/src/test/java/org/javaee7/jaspic/lifecycle/AuthModuleMethodInvocationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void testLogout() throws IOException, SAXException {
7373
// Note that we don't explicitly log-in; the test SAM uses for this test does that automatically before the resource
7474
// (servlet)
7575
// is invoked. Once we reach the Servlet we should be logged-in and can proceed to logout.
76-
String response = getFromServerPath("protected/servlet?doLogout");
76+
String response = getFromServerPath("protected/servlet?doLogout=true");
7777

7878
assertTrue("SAM method cleanSubject not called, but should have been.",
7979
response.contains("cleanSubject invoked"));

jaspic/register-session/src/test/java/org/javaee7/jaspic/registersession/RegisterSessionTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testRemembersSession() throws IOException, SAXException {
5050
// JASPIC is normally stateless, but for this test the SAM uses the register session feature so now
5151
// we should be logged-in when doing a call without explicitly logging in again.
5252

53-
response = getFromServerPath("protected/servlet?continueSession");
53+
response = getFromServerPath("protected/servlet?continueSession=true");
5454

5555
// Logged-in thus should be accessible.
5656
assertTrue(
@@ -72,7 +72,7 @@ public void testRemembersSession() throws IOException, SAXException {
7272

7373
// The session should also be remembered for other resources, including public ones
7474

75-
response = getFromServerPath("public/servlet?continueSession");
75+
response = getFromServerPath("public/servlet?continueSession=true");
7676

7777
// This test almost can't fail, but include for clarity
7878
assertTrue(response.contains("This is a public servlet"));
@@ -105,7 +105,7 @@ public void testJoinSessionIsOptional() throws IOException, SAXException {
105105
// JASPIC is normally stateless, but for this test the SAM uses the register session feature so now
106106
// we should be logged-in when doing a call without explicitly logging in again.
107107

108-
response = getFromServerPath("protected/servlet?continueSession");
108+
response = getFromServerPath("protected/servlet?continueSession=true");
109109

110110
// Logged-in thus should be accessible.
111111
assertTrue(

0 commit comments

Comments
 (0)