Search in sources :

Example 1 with GroupPrincipal

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

the class DecisionQueueTest method setUp.

@Before
public void setUp() throws Exception {
    Properties props = TestEngine.getTestProperties();
    m_engine = new TestEngine(props);
    m_queue = m_engine.getWorkflowManager().getDecisionQueue();
    adminSession = m_engine.adminSession();
    janneSession = m_engine.janneSession();
    w = new Workflow("workflow.key", new WikiPrincipal("Owner1"));
    w.setWorkflowManager(m_engine.getWorkflowManager());
    d1 = new SimpleDecision(w, "decision1.key", new GroupPrincipal("Admin"));
    d2 = new SimpleDecision(w, "decision2.key", new WikiPrincipal("Owner2"));
    d3 = new SimpleDecision(w, "decision3.key", janneSession.getUserPrincipal());
    m_queue.add(d1);
    m_queue.add(d2);
    m_queue.add(d3);
}
Also used : WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) Before(org.junit.Before)

Example 2 with GroupPrincipal

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

the class WorkflowManagerTest method testGetApprover.

@Test
public void testGetApprover() throws WikiException {
    // Test properties says workflow.saveWikiPage approver is GP Admin; workflow.foo is 'janne'
    Assert.assertEquals(new WikiPrincipal("janne", WikiPrincipal.LOGIN_NAME), wm.getApprover("workflow.foo"));
    Assert.assertEquals(new GroupPrincipal("Admin"), wm.getApprover("workflow.bar"));
    // 'saveWikiPage' workflow doesn't require approval, so we will need to catch an Exception
    try {
        Assert.assertEquals(new GroupPrincipal("Admin"), wm.getApprover("workflow.saveWikiPage"));
    } catch (WikiException e) {
        // Swallow
        return;
    }
    // We should never get here
    Assert.fail("Workflow.bar doesn't need approval!");
}
Also used : WikiException(org.apache.wiki.api.exceptions.WikiException) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) Test(org.junit.Test)

Example 3 with GroupPrincipal

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

the class WorkflowTest method testCurrentActor.

@Test
public void testCurrentActor() throws WikiException {
    // Before starting, actor should be null
    Assert.assertNull(w.getCurrentActor());
    // After starting, actor should be GroupPrincipal Admin
    w.start();
    Assert.assertEquals(new GroupPrincipal("Admin"), w.getCurrentActor());
    // After decision, actor should be null again
    Decision d = (Decision) w.getCurrentStep();
    d.decide(Outcome.DECISION_APPROVE);
    Assert.assertNull(w.getCurrentActor());
}
Also used : GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) Test(org.junit.Test)

Example 4 with GroupPrincipal

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

the class UserProfileTag method printGroups.

/**
 * Returns a sorted list of the {@link org.apache.wiki.auth.authorize.Group} objects a user possesses
 * in his or her WikiSession. The result is computed by consulting
 * {@link org.apache.wiki.WikiSession#getRoles()}
 * and extracting those that are of type Group.
 * @return the list of groups, sorted by name
 */
public static String printGroups(WikiContext context) {
    Principal[] roles = context.getWikiSession().getRoles();
    List<String> tempRoles = new ArrayList<String>();
    ResourceBundle rb = Preferences.getBundle(context, InternationalizationManager.CORE_BUNDLE);
    for (Principal role : roles) {
        if (role instanceof GroupPrincipal) {
            tempRoles.add(role.getName());
        }
    }
    if (tempRoles.size() == 0) {
        return rb.getString("userprofile.nogroups");
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < tempRoles.size(); i++) {
        String name = tempRoles.get(i);
        sb.append(name);
        if (i < (tempRoles.size() - 1)) {
            sb.append(',');
            sb.append(' ');
        }
    }
    return sb.toString();
}
Also used : GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) ArrayList(java.util.ArrayList) ResourceBundle(java.util.ResourceBundle) Principal(java.security.Principal) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal)

Example 5 with GroupPrincipal

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

the class PermissionTag method checkPermission.

/**
 *  Checks a single permission.
 *
 *  @param permission
 *  @return true if granted, false if not
 */
private boolean checkPermission(String permission) {
    WikiSession session = m_wikiContext.getWikiSession();
    WikiPage page = m_wikiContext.getPage();
    AuthorizationManager mgr = m_wikiContext.getEngine().getAuthorizationManager();
    boolean gotPermission = false;
    if (CREATE_GROUPS.equals(permission) || CREATE_PAGES.equals(permission) || EDIT_PREFERENCES.equals(permission) || EDIT_PROFILE.equals(permission) || LOGIN.equals(permission)) {
        gotPermission = mgr.checkPermission(session, new WikiPermission(page.getWiki(), permission));
    } else if (VIEW_GROUP.equals(permission) || EDIT_GROUP.equals(permission) || DELETE_GROUP.equals(permission)) {
        Command command = m_wikiContext.getCommand();
        gotPermission = false;
        if (command instanceof GroupCommand && command.getTarget() != null) {
            GroupPrincipal group = (GroupPrincipal) command.getTarget();
            String groupName = group.getName();
            String action = "view";
            if (EDIT_GROUP.equals(permission)) {
                action = "edit";
            } else if (DELETE_GROUP.equals(permission)) {
                action = "delete";
            }
            gotPermission = mgr.checkPermission(session, new GroupPermission(groupName, action));
        }
    } else if (ALL_PERMISSION.equals(permission)) {
        gotPermission = mgr.checkPermission(session, new AllPermission(m_wikiContext.getEngine().getApplicationName()));
    } else if (page != null) {
        // 
        if (EDIT.equals(permission)) {
            WikiPage latest = m_wikiContext.getEngine().getPage(page.getName());
            if (page.getVersion() != WikiProvider.LATEST_VERSION && latest.getVersion() != page.getVersion()) {
                return false;
            }
        }
        Permission p = PermissionFactory.getPagePermission(page, permission);
        gotPermission = mgr.checkPermission(session, p);
    }
    return gotPermission;
}
Also used : WikiSession(org.apache.wiki.WikiSession) GroupCommand(org.apache.wiki.ui.GroupCommand) Command(org.apache.wiki.ui.Command) GroupCommand(org.apache.wiki.ui.GroupCommand) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) WikiPage(org.apache.wiki.WikiPage) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Permission(java.security.Permission) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) AuthorizationManager(org.apache.wiki.auth.AuthorizationManager) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission)

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