use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class AnonymousLoginModuleTest method testLogout.
public final void testLogout() {
HttpServletRequest request = m_engine.newHttpRequest();
try {
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new AnonymousLoginModule();
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("127.0.0.1")));
Assert.assertFalse(principals.contains(Role.ANONYMOUS));
Assert.assertFalse(principals.contains(Role.ALL));
module.logout();
Assert.assertEquals(0, principals.size());
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class AnonymousLoginModuleTest method testLogin.
public final void testLogin() {
HttpServletRequest request = m_engine.newHttpRequest();
try {
// Test using IP address (AnonymousLoginModule succeeds)
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new AnonymousLoginModule();
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("127.0.0.1")));
Assert.assertFalse(principals.contains(Role.ANONYMOUS));
Assert.assertFalse(principals.contains(Role.ALL));
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of org.apache.wiki.auth.WikiPrincipal 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 org.apache.wiki.auth.WikiPrincipal 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 org.apache.wiki.auth.WikiPrincipal 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