use of org.apache.wiki.auth.WikiPrincipal 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);
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class WikiSessionTest method containerAuthenticatedSession.
public static WikiSession containerAuthenticatedSession(TestEngine engine, String id, Principal[] roles) throws Exception {
// Build container session
MockHttpServletRequest request = engine.newHttpRequest();
Set<String> r = new HashSet<String>();
for (int i = 0; i < roles.length; i++) {
r.add(roles[i].getName());
}
request.setRoles(r);
request.setUserPrincipal(new WikiPrincipal(id));
// Log in
runSecurityFilter(engine, request);
// Make sure the user is actually authenticated
WikiSession session = WikiSession.getWikiSession(engine, request);
if (!session.isAuthenticated()) {
throw new IllegalStateException("Could not log in authenticated user '" + id + "'");
}
return session;
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class AclImplTest method testCharlie.
@Test
public void testCharlie() {
// Charlie should be able to view, but not edit, comment or delete
Principal wup = new WikiPrincipal("Charlie");
Assert.assertTrue("view", inArray(m_acl.findPrincipals(PagePermission.VIEW), wup));
Assert.assertFalse("edit", inArray(m_acl.findPrincipals(PagePermission.EDIT), wup));
Assert.assertFalse("comment", inArray(m_acl.findPrincipals(PagePermission.COMMENT), wup));
Assert.assertFalse("delete", inArray(m_acl.findPrincipals(PagePermission.DELETE), wup));
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class AclImplTest method setUp.
/**
* We setup the following rules: Alice = may view Bob = may view, may edit
* Charlie = may view Dave = may view, may comment groupAcl: FooGroup =
* Alice, Bob - may edit BarGroup = Bob, Charlie - may view
*/
@Before
public void setUp() throws Exception {
Properties props = TestEngine.getTestProperties();
TestEngine engine = new TestEngine(props);
m_groupMgr = engine.getGroupManager();
m_session = WikiSessionTest.adminSession(engine);
m_acl = new AclImpl();
m_aclGroup = new AclImpl();
m_groups = new HashMap<String, Group>();
Principal uAlice = new WikiPrincipal("Alice");
Principal uBob = new WikiPrincipal("Bob");
Principal uCharlie = new WikiPrincipal("Charlie");
Principal uDave = new WikiPrincipal("Dave");
// Alice can view
AclEntry ae = new AclEntryImpl();
ae.addPermission(PagePermission.VIEW);
ae.setPrincipal(uAlice);
// Charlie can view
AclEntry ae2 = new AclEntryImpl();
ae2.addPermission(PagePermission.VIEW);
ae2.setPrincipal(uCharlie);
// Bob can view and edit (and by implication, comment)
AclEntry ae3 = new AclEntryImpl();
ae3.addPermission(PagePermission.VIEW);
ae3.addPermission(PagePermission.EDIT);
ae3.setPrincipal(uBob);
// Dave can view and comment
AclEntry ae4 = new AclEntryImpl();
ae4.addPermission(PagePermission.VIEW);
ae4.addPermission(PagePermission.COMMENT);
ae4.setPrincipal(uDave);
// Create ACL with Alice, Bob, Charlie, Dave
m_acl.addEntry(ae);
m_acl.addEntry(ae2);
m_acl.addEntry(ae3);
m_acl.addEntry(ae4);
// Foo group includes Alice and Bob
Group foo = m_groupMgr.parseGroup("FooGroup", "", true);
m_groupMgr.setGroup(m_session, foo);
foo.add(uAlice);
foo.add(uBob);
AclEntry ag1 = new AclEntryImpl();
ag1.setPrincipal(foo.getPrincipal());
ag1.addPermission(PagePermission.EDIT);
m_aclGroup.addEntry(ag1);
m_groups.put("FooGroup", foo);
// Bar group includes Bob and Charlie
Group bar = m_groupMgr.parseGroup("BarGroup", "", true);
m_groupMgr.setGroup(m_session, bar);
bar.add(uBob);
bar.add(uCharlie);
AclEntry ag2 = new AclEntryImpl();
ag2.setPrincipal(bar.getPrincipal());
ag2.addPermission(PagePermission.VIEW);
m_aclGroup.addEntry(ag2);
m_groups.put("BarGroup", bar);
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class DefaultAclManagerTest method testGetPermissions.
@Test
public void testGetPermissions() {
WikiPage page = m_engine.getPage("TestDefaultPage");
Acl acl = m_engine.getAclManager().getPermissions(page);
Assert.assertNotNull(page.getAcl());
Assert.assertTrue(page.getAcl().isEmpty());
page = m_engine.getPage("TestAclPage");
acl = m_engine.getAclManager().getPermissions(page);
Assert.assertNotNull(page.getAcl());
Assert.assertFalse(page.getAcl().isEmpty());
Principal[] p;
// Charlie is an editor; reading is therefore implied
p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "view"));
Assert.assertEquals(2, p.length);
Assert.assertTrue(ArrayUtils.contains(p, new WikiPrincipal("Charlie")));
// Charlie should be in the ACL as an editor
p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "edit"));
Assert.assertEquals(2, p.length);
Assert.assertTrue(ArrayUtils.contains(p, new WikiPrincipal("Charlie")));
// Charlie should not be able to delete this page
p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "delete"));
Assert.assertEquals(0, p.length);
// Herman is an unregistered user and editor; reading is implied
p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "view"));
Assert.assertEquals(2, p.length);
Assert.assertTrue(ArrayUtils.contains(p, new UnresolvedPrincipal("Herman")));
// Herman should be in the ACL as an editor
p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "edit"));
Assert.assertEquals(2, p.length);
Assert.assertTrue(ArrayUtils.contains(p, new UnresolvedPrincipal("Herman")));
// Herman should not be able to delete this page
p = acl.findPrincipals(PermissionFactory.getPagePermission(page, "delete"));
Assert.assertEquals(0, p.length);
}
Aggregations