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);
}
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!");
}
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());
}
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();
}
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;
}
Aggregations