use of org.apache.wiki.event.WikiSecurityEvent in project jspwiki by apache.
the class GroupManagerTest method testGroupAddEvents.
@Test
public void testGroupAddEvents() throws Exception {
// Flush any pre-existing groups (left over from previous Assert.failures, perhaps)
try {
m_groupMgr.removeGroup("Events");
} catch (NoSuchPrincipalException e) {
// It's not a problem if we get here...
}
m_trap.clearEvents();
Group group = m_groupMgr.parseGroup("Events", "", true);
m_groupMgr.setGroup(m_session, group);
WikiSecurityEvent event;
group = m_groupMgr.getGroup("Events");
group.add(new WikiPrincipal("Alice"));
group.add(new WikiPrincipal("Bob"));
group.add(new WikiPrincipal("Charlie"));
// We should see a GROUP_ADD event
WikiSecurityEvent[] events = m_trap.events();
Assert.assertEquals(1, events.length);
event = events[0];
Assert.assertEquals(m_groupMgr, event.getSrc());
Assert.assertEquals(WikiSecurityEvent.GROUP_ADD, event.getType());
Assert.assertEquals(group, event.getTarget());
// Clean up
m_groupMgr.removeGroup("Events");
}
use of org.apache.wiki.event.WikiSecurityEvent in project jspwiki by apache.
the class PageManager method actionPerformed.
/**
* Listens for {@link org.apache.wiki.event.WikiSecurityEvent#PROFILE_NAME_CHANGED}
* events. If a user profile's name changes, each page ACL is inspected. If an entry contains
* a name that has changed, it is replaced with the new one. No events are emitted
* as a consequence of this method, because the page contents are still the same; it is
* only the representations of the names within the ACL that are changing.
*
* @param event The event
*/
public void actionPerformed(WikiEvent event) {
if (!(event instanceof WikiSecurityEvent)) {
return;
}
WikiSecurityEvent se = (WikiSecurityEvent) event;
if (se.getType() == WikiSecurityEvent.PROFILE_NAME_CHANGED) {
UserProfile[] profiles = (UserProfile[]) se.getTarget();
Principal[] oldPrincipals = new Principal[] { new WikiPrincipal(profiles[0].getLoginName()), new WikiPrincipal(profiles[0].getFullname()), new WikiPrincipal(profiles[0].getWikiName()) };
Principal newPrincipal = new WikiPrincipal(profiles[1].getFullname());
// Examine each page ACL
try {
int pagesChanged = 0;
Collection pages = getAllPages();
for (Iterator it = pages.iterator(); it.hasNext(); ) {
WikiPage page = (WikiPage) it.next();
boolean aclChanged = changeAcl(page, oldPrincipals, newPrincipal);
if (aclChanged) {
// If the Acl needed changing, change it now
try {
m_engine.getAclManager().setPermissions(page, page.getAcl());
} catch (WikiSecurityException e) {
log.error("Could not change page ACL for page " + page.getName() + ": " + e.getMessage(), e);
}
pagesChanged++;
}
}
log.info("Profile name change for '" + newPrincipal.toString() + "' caused " + pagesChanged + " page ACLs to change also.");
} catch (ProviderException e) {
// Oooo! This is really bad...
log.error("Could not change user name in Page ACLs because of Provider error:" + e.getMessage(), e);
}
}
}
use of org.apache.wiki.event.WikiSecurityEvent in project jspwiki by apache.
the class GroupManager method actionPerformed.
/**
* Listens for {@link org.apache.wiki.event.WikiSecurityEvent#PROFILE_NAME_CHANGED}
* events. If a user profile's name changes, each group is inspected. If an entry contains
* a name that has changed, it is replaced with the new one. No group events are emitted
* as a consequence of this method, because the group memberships are still the same; it is
* only the representations of the names within that are changing.
* @param event the incoming event
*/
public void actionPerformed(WikiEvent event) {
if (!(event instanceof WikiSecurityEvent)) {
return;
}
WikiSecurityEvent se = (WikiSecurityEvent) event;
if (se.getType() == WikiSecurityEvent.PROFILE_NAME_CHANGED) {
WikiSession session = se.getSrc();
UserProfile[] profiles = (UserProfile[]) se.getTarget();
Principal[] oldPrincipals = new Principal[] { new WikiPrincipal(profiles[0].getLoginName()), new WikiPrincipal(profiles[0].getFullname()), new WikiPrincipal(profiles[0].getWikiName()) };
Principal newPrincipal = new WikiPrincipal(profiles[1].getFullname());
// Examine each group
int groupsChanged = 0;
try {
for (Group group : m_groupDatabase.groups()) {
boolean groupChanged = false;
for (Principal oldPrincipal : oldPrincipals) {
if (group.isMember(oldPrincipal)) {
group.remove(oldPrincipal);
group.add(newPrincipal);
groupChanged = true;
}
}
if (groupChanged) {
setGroup(session, group);
groupsChanged++;
}
}
} catch (WikiException e) {
// Oooo! This is really bad...
log.error("Could not change user name in Group lists because of GroupDatabase error:" + e.getMessage());
}
log.info("Profile name change for '" + newPrincipal.toString() + "' caused " + groupsChanged + " groups to change also.");
}
}
Aggregations