use of org.apache.wiki.auth.GroupPrincipal in project jspwiki by apache.
the class GroupManager method removeGroup.
/**
* Removes a named Group from the group database. If not found, throws a
* <code>NoSuchPrincipalException</code>. After removal, this method will
* commit the delete to the back-end group database. It will also fire a
* {@link org.apache.wiki.event.WikiSecurityEvent#GROUP_REMOVE} event with
* the GroupManager instance as the source and the Group as target.
* If <code>index</code> is <code>null</code>, this method throws
* an {@link IllegalArgumentException}.
* @param index the group to remove
* @throws WikiSecurityException if the Group cannot be removed by
* the back-end
* @see org.apache.wiki.auth.authorize.GroupDatabase#delete(Group)
*/
public void removeGroup(String index) throws WikiSecurityException {
if (index == null) {
throw new IllegalArgumentException("Group cannot be null.");
}
Group group = m_groups.get(new GroupPrincipal(index));
if (group == null) {
throw new NoSuchPrincipalException("Group " + index + " not found");
}
// TODO: need rollback procedure
synchronized (m_groups) {
m_groups.remove(group.getPrincipal());
}
m_groupDatabase.delete(group);
fireEvent(WikiSecurityEvent.GROUP_REMOVE, group);
}
use of org.apache.wiki.auth.GroupPrincipal in project jspwiki by apache.
the class AclImplTest method inGroup.
private boolean inGroup(Object[] array, Principal key) {
for (int i = 0; i < array.length; i++) {
if (array[i] instanceof GroupPrincipal) {
String groupName = ((GroupPrincipal) array[i]).getName();
Group group = m_groups.get(groupName);
if (group != null && group.isMember(key)) {
return true;
}
}
}
return false;
}
use of org.apache.wiki.auth.GroupPrincipal in project jspwiki by apache.
the class CommandResolverTest method testFindWikiActionWithParams.
@Test
public void testFindWikiActionWithParams() throws Exception {
Command a;
WikiPage page = m_engine.getPage("SinglePage");
// Passing an EDIT request with page param yields a wrapped action
MockHttpServletRequest request = m_engine.newHttpRequest("/Edit.jsp?page=SinglePage");
request.getParameterMap().put("page", new String[] { "SinglePage" });
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertNotSame(PageCommand.EDIT, a);
Assert.assertEquals("EditContent.jsp", a.getContentTemplate());
Assert.assertEquals("Edit.jsp", a.getJSP());
Assert.assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
Assert.assertEquals(page, a.getTarget());
// Passing an EDIT request with page=Search yields FIND action, *not* edit
request.setContextPath("/Edit.jsp?page=Search");
request.getParameterMap().put("page", new String[] { "Search" });
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertEquals(WikiCommand.FIND, a);
Assert.assertEquals("FindContent.jsp", a.getContentTemplate());
Assert.assertEquals("Search.jsp", a.getJSP());
Assert.assertEquals("%uSearch.jsp", a.getURLPattern());
Assert.assertNull(a.getTarget());
// Passing an EDIT request with group="Foo" yields wrapped VIEW_GROUP
request = m_engine.newHttpRequest("/Group.jsp?group=Foo");
request.getParameterMap().put("group", new String[] { "Foo" });
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertNotSame(GroupCommand.VIEW_GROUP, a);
Assert.assertEquals("GroupContent.jsp", a.getContentTemplate());
Assert.assertEquals("Group.jsp", a.getJSP());
Assert.assertEquals("%uGroup.jsp?group=%n", a.getURLPattern());
Assert.assertEquals(new GroupPrincipal("Foo"), a.getTarget());
}
use of org.apache.wiki.auth.GroupPrincipal in project jspwiki by apache.
the class GroupCommandTest method testTargetedCommand.
@Test
public void testTargetedCommand() {
// Get view command
Command a = GroupCommand.VIEW_GROUP;
GroupPrincipal group = new GroupPrincipal("Test");
// Combine with wiki group; make sure it's not equal to old command
Command b = a.targetedCommand(group);
Assert.assertNotSame(a, b);
Assert.assertEquals(a.getRequestContext(), b.getRequestContext());
Assert.assertEquals(a.getJSP(), b.getJSP());
Assert.assertEquals(a.getURLPattern(), b.getURLPattern());
Assert.assertEquals(a.getContentTemplate(), b.getContentTemplate());
Assert.assertNotNull(b.getTarget());
Assert.assertNotNull(b.requiredPermission());
Assert.assertEquals(new GroupPermission("*:Test", "view"), b.requiredPermission());
Assert.assertEquals(group, b.getTarget());
// Do the same with edit command
a = GroupCommand.EDIT_GROUP;
b = a.targetedCommand(group);
Assert.assertNotSame(a, b);
Assert.assertNotNull(b.getTarget());
Assert.assertNotNull(b.requiredPermission());
Assert.assertEquals(new GroupPermission("*:Test", "edit"), b.requiredPermission());
Assert.assertEquals(group, b.getTarget());
// Do the same with delete command
a = GroupCommand.DELETE_GROUP;
b = a.targetedCommand(group);
Assert.assertNotSame(a, b);
Assert.assertNotNull(b.getTarget());
Assert.assertNotNull(b.requiredPermission());
Assert.assertEquals(new GroupPermission("*:Test", "delete"), b.requiredPermission());
Assert.assertEquals(group, b.getTarget());
}
use of org.apache.wiki.auth.GroupPrincipal in project jspwiki by apache.
the class WorkflowTest method setUp.
@Before
public void setUp() throws Exception {
// Create workflow; owner is test user
w = new Workflow("workflow.myworkflow", new WikiPrincipal("Owner1"));
// Create custom initialization task
initTask = new TaskTest.NormalTask(w);
// Create finish task
finishTask = new TaskTest.NormalTask(w);
// Create an intermetidate decision step
Principal actor = new GroupPrincipal("Admin");
decision = new SimpleDecision(w, "decision.AdminDecision", actor);
// Hook the steps together
initTask.addSuccessor(Outcome.STEP_COMPLETE, decision);
decision.addSuccessor(Outcome.DECISION_APPROVE, finishTask);
// Stash page name as message attribute
w.addMessageArgument("MyPage");
// Set workflow's first step
w.setFirstStep(initTask);
}
Aggregations