Search in sources :

Example 41 with WikiPrincipal

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

the class JDBCGroupDatabaseTest method testDelete.

@Test
public void testDelete() throws WikiException {
    // First, count the number of groups in the db now.
    int oldUserCount = m_db.groups().length;
    // Create a new group with random name
    String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
    Group group = new Group(name, m_wiki);
    Principal al = new WikiPrincipal("Al");
    Principal bob = new WikiPrincipal("Bob");
    group.add(al);
    group.add(bob);
    m_db.save(group, new WikiPrincipal("Tester"));
    // Make sure the profile saved successfully
    group = backendGroup(name);
    Assert.assertEquals(name, group.getName());
    Assert.assertEquals(oldUserCount + 1, m_db.groups().length);
    // Now delete the profile; should be back to old count
    m_db.delete(group);
    Assert.assertEquals(oldUserCount, m_db.groups().length);
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 42 with WikiPrincipal

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

the class JDBCGroupDatabaseTest method testSave.

@Test
public void testSave() throws Exception {
    // Create a new group with random name
    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());
    Assert.assertEquals(3, group.members().length);
    Assert.assertTrue(group.isMember(new WikiPrincipal("Al")));
    Assert.assertTrue(group.isMember(new WikiPrincipal("Bob")));
    Assert.assertTrue(group.isMember(new WikiPrincipal("Cookie")));
    // The back-end should have timestamped the create/modify fields
    Assert.assertNotNull(group.getCreator());
    Assert.assertEquals("Tester", group.getCreator());
    Assert.assertNotNull(group.getCreated());
    Assert.assertNotNull(group.getModifier());
    Assert.assertEquals("Tester", group.getModifier());
    Assert.assertNotNull(group.getLastModified());
    Assert.assertNotSame(group.getCreated(), 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)

Example 43 with WikiPrincipal

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

the class XMLGroupDatabaseTest 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)

Example 44 with WikiPrincipal

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

the class XMLGroupDatabaseTest method testSave.

@Test
public void testSave() throws Exception {
    // Create a new group with random name
    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());
    Assert.assertEquals(3, group.members().length);
    Assert.assertTrue(group.isMember(new WikiPrincipal("Al")));
    Assert.assertTrue(group.isMember(new WikiPrincipal("Bob")));
    Assert.assertTrue(group.isMember(new WikiPrincipal("Cookie")));
    // The back-end should have timestamped the create/modify fields
    Assert.assertNotNull(group.getCreator());
    Assert.assertEquals("Tester", group.getCreator());
    Assert.assertNotNull(group.getCreated());
    Assert.assertNotNull(group.getModifier());
    Assert.assertEquals("Tester", group.getModifier());
    Assert.assertNotNull(group.getLastModified());
    Assert.assertNotSame(group.getCreated(), 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)

Example 45 with WikiPrincipal

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

the class XMLGroupDatabaseTest method testDelete.

@Test
public void testDelete() throws WikiException {
    // First, count the number of groups in the db now.
    int oldUserCount = m_db.groups().length;
    // Create a new group with random name
    String name = "TestGroup" + String.valueOf(System.currentTimeMillis());
    Group group = new Group(name, m_wiki);
    Principal al = new WikiPrincipal("Al");
    Principal bob = new WikiPrincipal("Bob");
    group.add(al);
    group.add(bob);
    m_db.save(group, new WikiPrincipal("Tester"));
    // Make sure the profile saved successfully
    group = backendGroup(name);
    Assert.assertEquals(name, group.getName());
    Assert.assertEquals(oldUserCount + 1, m_db.groups().length);
    // Now delete the profile; should be back to old count
    m_db.delete(group);
    Assert.assertEquals(oldUserCount, m_db.groups().length);
}
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