use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class WikiSessionTest method testAssertionCookie.
@Test
public void testAssertionCookie() throws ServletException, IOException {
MockHttpServletRequest request;
WikiSession wikiSession;
// Adding the magic "assertion cookie" should set asserted status.
request = m_engine.newHttpRequest();
request.setUserPrincipal(null);
String cookieName = CookieAssertionLoginModule.PREFS_COOKIE_NAME;
request.setCookies(new Cookie[] { new Cookie(cookieName, "FredFlintstone") });
runSecurityFilter(m_engine, request);
wikiSession = WikiSession.getWikiSession(m_engine, request);
Assert.assertTrue(wikiSession.isAsserted());
Assert.assertEquals("FredFlintstone", wikiSession.getUserPrincipal().getName());
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class WikiSessionTest method containerAuthenticatedSession.
public static WikiSession containerAuthenticatedSession(TestEngine engine, String id, Principal[] roles) throws Exception {
// Build container session
MockHttpServletRequest request = engine.newHttpRequest();
Set<String> r = new HashSet<String>();
for (int i = 0; i < roles.length; i++) {
r.add(roles[i].getName());
}
request.setRoles(r);
request.setUserPrincipal(new WikiPrincipal(id));
// Log in
runSecurityFilter(engine, request);
// Make sure the user is actually authenticated
WikiSession session = WikiSession.getWikiSession(engine, request);
if (!session.isAuthenticated()) {
throw new IllegalStateException("Could not log in authenticated user '" + id + "'");
}
return session;
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class CookieAssertionLoginModuleTest method testLogin.
public final void testLogin() {
MockHttpServletRequest request = m_engine.newHttpRequest();
try {
// We can use cookies right?
Assert.assertTrue(m_engine.getAuthenticationManager().allowsCookieAssertions());
// Test using Cookie and IP address (AnonymousLoginModule succeeds)
Cookie cookie = new Cookie(CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle");
request.setCookies(new Cookie[] { cookie });
m_subject = new Subject();
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new CookieAssertionLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("Bullwinkle")));
Assert.assertFalse(principals.contains(Role.ASSERTED));
Assert.assertFalse(principals.contains(Role.ALL));
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class WebContainerLoginModuleTest method testLogin.
public final void testLogin() {
Principal principal = new WikiPrincipal("Andrew Jaquith");
MockHttpServletRequest request = m_engine.newHttpRequest();
request.setUserPrincipal(principal);
try {
// Test using Principal (WebContainerLoginModule succeeds)
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new WebContainerLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(principal));
Assert.assertFalse(principals.contains(Role.ANONYMOUS));
Assert.assertFalse(principals.contains(Role.ASSERTED));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class WebContainerLoginModuleTest method testLogout.
public final void testLogout() {
Principal principal = new WikiPrincipal("Andrew Jaquith");
MockHttpServletRequest request = m_engine.newHttpRequest();
request.setUserPrincipal(principal);
try {
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new WebContainerLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(principal));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
module.logout();
Assert.assertEquals(0, principals.size());
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
Aggregations