use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class GroupTest method testEquals4.
@Test
public void testEquals4() {
Group group1 = new Group("BlibBlab", m_wiki);
Principal u1 = new WikiPrincipal("Alice");
Principal u2 = new WikiPrincipal("Bob");
group1.add(u1);
group1.add(u2);
Group group2 = new Group("Blib", m_wiki);
Principal u3 = new WikiPrincipal("Alice");
Principal u4 = new WikiPrincipal("Bob");
group2.add(u3);
group2.add(u4);
Assert.assertFalse(m_group.equals(group2));
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class CookieAssertionLoginModuleTest method testLogout.
public final void testLogout() {
MockHttpServletRequest request = m_engine.newHttpRequest();
Cookie cookie = new Cookie(CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle");
request.setCookies(new Cookie[] { cookie });
try {
CallbackHandler handler = new WebContainerCallbackHandler(m_engine, request);
LoginModule module = new CookieAssertionLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("Bullwinkle")));
Assert.assertFalse(principals.contains(Role.ANONYMOUS));
Assert.assertFalse(principals.contains(Role.ALL));
module.logout();
Assert.assertEquals(0, principals.size());
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class UserDatabaseLoginModuleTest method testLogout.
public final void testLogout() {
try {
CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
LoginModule module = new UserDatabaseLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
module.logout();
Assert.assertEquals(0, principals.size());
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class UserDatabaseLoginModuleTest method testLogin.
public final void testLogin() {
try {
// Log in with a user that isn't in the database
CallbackHandler handler = new WikiCallbackHandler(m_engine, null, "user", "password");
LoginModule module = new UserDatabaseLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
Set<Principal> principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("user", WikiPrincipal.LOGIN_NAME)));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
// Login with a user that IS in the database
m_subject = new Subject();
handler = new WikiCallbackHandler(m_engine, null, "janne", "myP@5sw0rd");
module = new UserDatabaseLoginModule();
module.initialize(m_subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
module.login();
module.commit();
principals = m_subject.getPrincipals();
Assert.assertEquals(1, principals.size());
Assert.assertTrue(principals.contains(new WikiPrincipal("janne", WikiPrincipal.LOGIN_NAME)));
Assert.assertFalse(principals.contains(Role.AUTHENTICATED));
Assert.assertFalse(principals.contains(Role.ALL));
} catch (LoginException e) {
System.err.println(e.getMessage());
Assert.assertTrue(false);
}
}
use of org.apache.wiki.auth.WikiPrincipal in project jspwiki by apache.
the class ApprovalWorkflowTest method testBuildApprovalWorkflowDeny.
@Test
public void testBuildApprovalWorkflowDeny() throws WikiException {
Principal submitter = new WikiPrincipal("Submitter");
String workflowApproverKey = "workflow.approvalWorkflow";
Task prepTask = new TestPrepTask("task.preSaveWikiPage");
String decisionKey = "decision.saveWikiPage";
Fact[] facts = new Fact[3];
facts[0] = new Fact("fact1", new Integer(1));
facts[1] = new Fact("fact2", "A factual String");
facts[2] = new Fact("fact3", Outcome.DECISION_ACKNOWLEDGE);
Task completionTask = new TestPrepTask("task.saveWikiPage");
String rejectedMessageKey = "notification.saveWikiPage.reject";
Workflow w = m_builder.buildApprovalWorkflow(submitter, workflowApproverKey, prepTask, decisionKey, facts, completionTask, rejectedMessageKey);
w.setWorkflowManager(m_engine.getWorkflowManager());
// Start the workflow
w.start();
// Now, deny the Decision and the submitter should see a notification
Step step = w.getCurrentStep();
Assert.assertTrue(step instanceof Decision);
Decision decision = (Decision) step;
decision.decide(Outcome.DECISION_DENY);
Assert.assertFalse(w.isCompleted());
// Check that the notification is ok, then acknowledge it
step = w.getCurrentStep();
Assert.assertTrue(step instanceof SimpleNotification);
Assert.assertEquals(rejectedMessageKey, step.getMessageKey());
SimpleNotification notification = (SimpleNotification) step;
notification.acknowledge();
// Workflow should be complete now
Assert.assertTrue(w.isCompleted());
Assert.assertNull(w.getCurrentStep());
Assert.assertEquals(3, w.getHistory().size());
Assert.assertEquals(notification, w.getHistory().get(2));
}
Aggregations