Search in sources :

Example 46 with WikiPrincipal

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 47 with WikiPrincipal

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 48 with WikiPrincipal

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);
    }
}
Also used : Cookie(javax.servlet.http.Cookie) CallbackHandler(javax.security.auth.callback.CallbackHandler) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) LoginModule(javax.security.auth.spi.LoginModule) Subject(javax.security.auth.Subject) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) LoginException(javax.security.auth.login.LoginException) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 49 with WikiPrincipal

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);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Example 50 with WikiPrincipal

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);
    }
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) LoginException(javax.security.auth.login.LoginException) LoginModule(javax.security.auth.spi.LoginModule) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal)

Aggregations

WikiPrincipal (org.apache.wiki.auth.WikiPrincipal)60 Principal (java.security.Principal)41 Test (org.junit.Test)32 LoginException (javax.security.auth.login.LoginException)13 GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)13 CallbackHandler (javax.security.auth.callback.CallbackHandler)8 LoginModule (javax.security.auth.spi.LoginModule)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)6 IOException (java.io.IOException)5 Callback (javax.security.auth.callback.Callback)5 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)5 WikiSessionTest (org.apache.wiki.WikiSessionTest)5 NoSuchPrincipalException (org.apache.wiki.auth.NoSuchPrincipalException)5 WikiSecurityException (org.apache.wiki.auth.WikiSecurityException)4 UserProfile (org.apache.wiki.auth.user.UserProfile)4 Before (org.junit.Before)4 Properties (java.util.Properties)3 Subject (javax.security.auth.Subject)3 FailedLoginException (javax.security.auth.login.FailedLoginException)3