Search in sources :

Example 6 with GroupPrincipal

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);
}
Also used : GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) NoSuchPrincipalException(org.apache.wiki.auth.NoSuchPrincipalException)

Example 7 with GroupPrincipal

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;
}
Also used : Group(org.apache.wiki.auth.authorize.Group) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal)

Example 8 with GroupPrincipal

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());
}
Also used : GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 9 with GroupPrincipal

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());
}
Also used : GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) Test(org.junit.Test)

Example 10 with GroupPrincipal

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);
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) Principal(java.security.Principal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) Before(org.junit.Before)

Aggregations

GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)13 WikiPrincipal (org.apache.wiki.auth.WikiPrincipal)4 Test (org.junit.Test)4 Principal (java.security.Principal)3 WikiPage (org.apache.wiki.WikiPage)3 Permission (java.security.Permission)2 Subject (javax.security.auth.Subject)2 GroupPermission (org.apache.wiki.auth.permissions.GroupPermission)2 Before (org.junit.Before)2 AccessControlContext (java.security.AccessControlContext)1 DomainCombiner (java.security.DomainCombiner)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ResourceBundle (java.util.ResourceBundle)1 SubjectDomainCombiner (javax.security.auth.SubjectDomainCombiner)1 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)1 TestEngine (org.apache.wiki.TestEngine)1 WikiSession (org.apache.wiki.WikiSession)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 AuthorizationManager (org.apache.wiki.auth.AuthorizationManager)1