Skip to content

Added query parameter values for Liberty in default configuration #331

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

Merged
merged 2 commits into from
Nov 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.javaee7.jaspic.ejbpropagation.servlet;

import static java.util.logging.Level.SEVERE;

import java.io.IOException;
import java.util.logging.Logger;

import javax.ejb.EJB;
import javax.servlet.ServletException;
Expand All @@ -20,6 +23,7 @@
public class ProtectedServletProtectedEJB extends HttpServlet {

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

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

String ejbName = protectedEJB.getUserName();
String ejbName = "";
try {
ejbName = protectedEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

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

boolean webHasRole = request.isUserInRole("architect");
boolean ejbHasRole = protectedEJB.isUserArchitect();

boolean ejbHasRole = false;
try {
ejbHasRole = protectedEJB.isUserArchitect();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

response.getWriter().write(
"web user has role \"architect\": " + webHasRole + "\n" + "EJB user has role \"architect\": " + ejbHasRole
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.javaee7.jaspic.ejbpropagation.servlet;

import static java.util.logging.Level.SEVERE;

import java.io.IOException;
import java.util.logging.Logger;

import javax.ejb.EJB;
import javax.servlet.ServletException;
Expand All @@ -20,6 +23,7 @@
public class ProtectedServletPublicEJB extends HttpServlet {

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

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

String ejbName = publicEJB.getUserName();
try {
ejbName = publicEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.javaee7.jaspic.ejbpropagation.servlet;

import static java.util.logging.Level.SEVERE;

import java.io.IOException;
import java.util.logging.Logger;

import javax.ejb.EJB;
import javax.servlet.ServletException;
Expand All @@ -20,6 +23,7 @@
public class PublicServletProtectedEJB extends HttpServlet {

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

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

String ejbName = protectedEJB.getUserName();
String ejbName = "";
try {
ejbName = protectedEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

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

boolean webHasRole = request.isUserInRole("architect");
boolean ejbHasRole = protectedEJB.isUserArchitect();

boolean ejbHasRole = false;
try {
ejbHasRole = protectedEJB.isUserArchitect();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

response.getWriter().write(
"web user has role \"architect\": " + webHasRole + "\n" + "EJB user has role \"architect\": " + ejbHasRole
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.javaee7.jaspic.ejbpropagation.servlet;

import static java.util.logging.Level.SEVERE;

import java.io.IOException;
import java.util.logging.Logger;

import javax.ejb.EJB;
import javax.servlet.ServletException;
Expand All @@ -20,6 +23,7 @@
public class PublicServletPublicEJB extends HttpServlet {

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

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

String ejbName = publicEJB.getUserName();
String ejbName = "";
try {
ejbName = publicEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.javaee7.jaspic.ejbpropagation.servlet;

import static java.util.logging.Level.SEVERE;

import java.io.IOException;
import java.util.logging.Logger;

import javax.ejb.EJB;
import javax.servlet.ServletException;
Expand All @@ -21,6 +24,7 @@
public class PublicServletPublicEJBLogout extends HttpServlet {

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

@EJB
private PublicEJB publicEJB;
Expand All @@ -32,8 +36,13 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
if (request.getUserPrincipal() != null) {
webName = request.getUserPrincipal().getName();
}

String ejbName = publicEJB.getUserName();

String ejbName = "";
try {
ejbName = publicEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

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

String ejbNameAfterLogout = publicEJB.getUserName();
String ejbNameAfterLogout = "";
try {
ejbNameAfterLogout = publicEJB.getUserName();
} catch (Exception e) {
logger.log(SEVERE, "", e);
}

response.getWriter().write("web username: " + webName + "\n" + "EJB username: " + ejbName + "\n");
response.getWriter().write("web username after logout: " + webNameAfterLogout + "\n" + "EJB username after logout: " + ejbNameAfterLogout + "\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ public static Archive<?> createDeployment() {
}

@Test
public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXException {
public void protectedServletCallingProtectedEJB() throws IOException, SAXException {

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

// Both the web (HttpServletRequest) and EJB (EJBContext) should see the same
// user name.
assertTrue(response.contains("web username: test"));
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
assertTrue(
"User should have been authenticated in the web layer and given name \"test\", " +
" but does not appear to have this name",
response.contains("web username: test")
);
assertTrue(
"Web has user principal set, but EJB not.",
response.contains("EJB username: test")
);

// Both the web (HttpServletRequest) and EJB (EJBContext) should see that the
// user has the role "architect".
Expand All @@ -50,14 +57,21 @@ public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXExc
*
*/
@Test
public void testPublicServletWithLoginCallingEJB() throws IOException, SAXException {
public void publicServletCallingProtectedEJB() throws IOException, SAXException {

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

// Both the web (HttpServletRequest) and EJB (EJBContext) should see the same
// user name.
assertTrue(response.contains("web username: test"));
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
assertTrue(
"User should have been authenticated in the web layer and given name \"test\", " +
" but does not appear to have this name",
response.contains("web username: test")
);
assertTrue(
"Web has user principal set, but EJB not.",
response.contains("EJB username: test")
);

// Both the web (HttpServletRequest) and EJB (EJBContext) should see that the
// user has the role "architect".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.javaee7.jaspic.common.ArquillianBase;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xml.sax.SAXException;

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

@Test
public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXException {
public void publicServletCallingPublicEJBThenLogout() {

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

System.out.println(response);

// Both the web (HttpServletRequest) and EJB (EJBContext) should see the
// same
// user name.
// same user name.

assertTrue(response.contains("web username: test"));
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
assertTrue(
"User should have been authenticated in the web layer and given name \"test\", " +
" but does not appear to have this name",
response.contains("web username: test")
);
assertTrue(
"Web has user principal set, but EJB not.",
response.contains("EJB username: test")
);


// After logging out, both the web and EJB should no longer see the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.javaee7.jaspic.common.ArquillianBase;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xml.sax.SAXException;

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

@Test
public void testProtectedServletWithLoginCallingEJB() throws IOException, SAXException {
public void protectedServletCallingPublicEJB() {

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

// Both the web (HttpServletRequest) and EJB (EJBContext) should see the same
// user name.
assertTrue(response.contains("web username: test"));
assertTrue("Web has user principal set, but EJB not.", response.contains("EJB username: test"));
assertTrue(
"User should have been authenticated in the web layer and given name \"test\", " +
" but does not appear to have this name",
response.contains("web username: test")
);
assertTrue(
"Web has user principal set, but EJB not.",
response.contains("EJB username: test")
);
}

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

assertTrue("SAM method cleanSubject not called, but should have been.",
response.contains("cleanSubject invoked"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testRemembersSession() throws IOException, SAXException {
// JASPIC is normally stateless, but for this test the SAM uses the register session feature so now
// we should be logged-in when doing a call without explicitly logging in again.

response = getFromServerPath("protected/servlet?continueSession");
response = getFromServerPath("protected/servlet?continueSession=true");

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

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

response = getFromServerPath("public/servlet?continueSession");
response = getFromServerPath("public/servlet?continueSession=true");

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

response = getFromServerPath("protected/servlet?continueSession");
response = getFromServerPath("protected/servlet?continueSession=true");

// Logged-in thus should be accessible.
assertTrue(
Expand Down