Search in sources :

Example 36 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class GroupTest method testAdd2.

@Test
public void testAdd2() {
    Principal u1 = new WikiPrincipal("Alice");
    Principal u2 = new WikiPrincipal("Bob");
    Assert.assertTrue("adding alice", m_group.add(u1));
    Assert.assertTrue("adding bob", m_group.add(u2));
    Assert.assertTrue("Alice", m_group.isMember(u1));
    Assert.assertTrue("Bob", m_group.isMember(u2));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 37 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class GroupTest method testRemove.

@Test
public void testRemove() {
    Principal u1 = new WikiPrincipal("Alice");
    Principal u2 = new WikiPrincipal("Bob");
    Principal u3 = new WikiPrincipal("Bob");
    m_group.add(u1);
    m_group.add(u2);
    m_group.remove(u3);
    Assert.assertTrue("Alice", m_group.isMember(u1));
    Assert.assertFalse("Bob", m_group.isMember(u2));
    Assert.assertFalse("Bob 2", m_group.isMember(u3));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 38 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class GroupTest method testAdd3.

/**
 * Check that different objects match as well.
 */
@Test
public void testAdd3() {
    Principal u1 = new WikiPrincipal("Alice");
    Principal u2 = new WikiPrincipal("Bob");
    Principal u3 = new WikiPrincipal("Bob");
    Assert.assertTrue("adding alice", m_group.add(u1));
    Assert.assertTrue("adding bob", m_group.add(u2));
    Assert.assertTrue("Alice", m_group.isMember(u1));
    Assert.assertTrue("Bob", m_group.isMember(u3));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 39 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class GroupTest method testAdd1.

@Test
public void testAdd1() {
    Principal u1 = new WikiPrincipal("Alice");
    m_group.add(u1);
    Assert.assertTrue(m_group.isMember(u1));
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 40 with WikiPrincipal

use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.

the class JDBCGroupDatabaseTest method testResave.

@Test
public void testResave() throws Exception {
    // Create a new group with random name & 3 members
    String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
    Group group = new Group(name, m_wiki);
    Principal al = new WikiPrincipal("Al");
    Principal bob = new WikiPrincipal("Bob");
    Principal cookie = new WikiPrincipal("Cookie");
    group.add(al);
    group.add(bob);
    group.add(cookie);
    m_db.save(group, new WikiPrincipal("Tester"));
    // Make sure the profile saved successfully
    group = backendGroup(name);
    Assert.assertEquals(name, group.getName());
    // Modify the members by adding the group; re-add Al while we're at it
    Principal dave = new WikiPrincipal("Dave");
    group.add(al);
    group.add(dave);
    m_db.save(group, new WikiPrincipal("SecondTester"));
    // We should see 4 members and new timestamp info
    Principal[] members = group.members();
    Assert.assertEquals(4, members.length);
    Assert.assertNotNull(group.getCreator());
    Assert.assertEquals("Tester", group.getCreator());
    Assert.assertNotNull(group.getCreated());
    Assert.assertNotNull(group.getModifier());
    Assert.assertEquals("SecondTester", group.getModifier());
    Assert.assertNotNull(group.getLastModified());
    // Check the back-end; We should see the same thing
    group = backendGroup(name);
    members = group.members();
    Assert.assertEquals(4, members.length);
    Assert.assertNotNull(group.getCreator());
    Assert.assertEquals("Tester", group.getCreator());
    Assert.assertNotNull(group.getCreated());
    Assert.assertNotNull(group.getModifier());
    Assert.assertEquals("SecondTester", group.getModifier());
    Assert.assertNotNull(group.getLastModified());
    // Remove the group
    m_db.delete(group);
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

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