}
// Log in 'janne' and verify there are 5 principals in the subject
// (ALL, AUTHENTICATED, login, fullname, wikiname Principals)
WikiSession session = WikiSession.guestSession( m_engine );
m_auth.login( session, Users.JANNE, Users.JANNE_PASS );
assertEquals( 3, session.getPrincipals().length );
assertEquals( 2, session.getRoles().length );
assertTrue( session.hasPrincipal( new WikiPrincipal( "JanneJalkanen", WikiPrincipal.WIKI_NAME ) ) );
// Listen for any manager group-add events
GroupManager manager = m_engine.getGroupManager();
SecurityEventTrap trap = new SecurityEventTrap();
manager.addWikiEventListener( trap );
// Create two groups; one with Janne in it, and one without
Group groupTest1 = m_groupMgr.parseGroup( "Test1", "JanneJalkanen \n Bob \n Charlie", true );
m_groupMgr.setGroup( m_session, groupTest1 );
groupTest1 = m_groupMgr.getGroup( "Test1" );
Principal principalTest1 = groupTest1.getPrincipal();
Group groupTest2 = m_groupMgr.parseGroup( "Test2", "Alice \n Bob \n Charlie", true );
m_groupMgr.setGroup( m_session, groupTest2 );
groupTest2 = m_groupMgr.getGroup( "Test2" );
Principal principalTest2 = groupTest2.getPrincipal();
// We should see two security events (one for each group create)
// We should also see a GroupPrincipal for group Test1, but not Test2
assertEquals( 2, trap.events().length );
assertTrue( session.hasPrincipal( principalTest1 ) );
assertFalse( session.hasPrincipal( principalTest2 ) );
// If we remove Test1, the GroupPrincipal should disappear
m_groupMgr.removeGroup( "Test1" );
assertFalse( session.hasPrincipal( principalTest1 ) );
assertFalse( session.hasPrincipal( principalTest2 ) );
// Now, add 'JanneJalkanen' to Test2 group manually; we should see the
// GroupPrincipal
groupTest2.add( new WikiPrincipal( "JanneJalkanen" ) );
m_groupMgr.setGroup( session, groupTest2 );
assertFalse( session.hasPrincipal( principalTest1 ) );
assertTrue( session.hasPrincipal( principalTest2 ) );
// Remove 'JanneJalkenen' manually; the GroupPrincipal should disappear
groupTest2.remove( new WikiPrincipal( "JanneJalkanen" ) );
m_groupMgr.setGroup( session, groupTest2 );
assertFalse( session.hasPrincipal( principalTest1 ) );
assertFalse( session.hasPrincipal( principalTest2 ) );
// Clean up
m_groupMgr.removeGroup( "Test2" );
}