use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class UserManagerTest method testSetUserProfile.
@Test
public void testSetUserProfile() throws Exception {
// First, count the number of users in the db now.
int oldUserCount = m_db.getWikiNames().length;
// Create a new user with random name
WikiSession session = m_engine.guestSession();
String loginName = "TestUser" + String.valueOf(System.currentTimeMillis());
UserProfile profile = m_db.newProfile();
profile.setEmail("jspwiki.tests@mailinator.com");
profile.setLoginName(loginName);
profile.setFullname("FullName" + loginName);
profile.setPassword("password");
m_mgr.setUserProfile(session, profile);
// Make sure the profile saved successfully
profile = m_mgr.getUserProfile(session);
Assert.assertEquals(loginName, profile.getLoginName());
Assert.assertEquals(oldUserCount + 1, m_db.getWikiNames().length);
// Now delete the profile; should be back to old count
m_db.deleteByLoginName(loginName);
Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class UserManagerTest method testSetUserProfileWithDenial.
@Test
public void testSetUserProfileWithDenial() throws Exception {
setUpWithWorkflow();
// First, count the number of users in the db now.
int oldUserCount = m_db.getWikiNames().length;
// Create a new user with random name
WikiSession session = m_engine.guestSession();
String loginName = "TestUser" + String.valueOf(System.currentTimeMillis());
UserProfile profile = m_db.newProfile();
profile.setEmail("jspwiki.tests@mailinator.com");
profile.setLoginName(loginName);
profile.setFullname("FullName" + loginName);
profile.setPassword("password");
// Because user profile saves require approvals, we will catch a Redirect
try {
m_mgr.setUserProfile(session, profile);
Assert.fail("We should have caught a DecisionRequiredException caused by approval!");
} catch (DecisionRequiredException e) {
}
// The user should NOT be saved yet
Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
// Now, look in Admin's queue, and verify there's a pending Decision there
DecisionQueue dq = m_engine.getWorkflowManager().getDecisionQueue();
Collection decisions = dq.getActorDecisions(m_engine.adminSession());
Assert.assertEquals(1, decisions.size());
// Verify that the Decision has all the facts and attributes we need
Decision d = (Decision) decisions.iterator().next();
List facts = d.getFacts();
Assert.assertEquals(new Fact(UserManager.PREFS_FULL_NAME, profile.getFullname()), facts.get(0));
Assert.assertEquals(new Fact(UserManager.PREFS_LOGIN_NAME, profile.getLoginName()), facts.get(1));
Assert.assertEquals(new Fact(UserManager.FACT_SUBMITTER, session.getUserPrincipal().getName()), facts.get(2));
Assert.assertEquals(new Fact(UserManager.PREFS_EMAIL, profile.getEmail()), facts.get(3));
Assert.assertEquals(profile, d.getWorkflow().getAttribute(UserManager.SAVED_PROFILE));
// Approve the profile
d.decide(Outcome.DECISION_DENY);
// Make sure the profile did NOT save
Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class UserManagerTest method testSetUserProfileWithApproval.
@Test
public void testSetUserProfileWithApproval() throws Exception {
setUpWithWorkflow();
// First, count the number of users in the db now.
int oldUserCount = m_db.getWikiNames().length;
// Create a new user with random name
WikiSession session = m_engine.guestSession();
String loginName = "TestUser" + String.valueOf(System.currentTimeMillis());
UserProfile profile = m_db.newProfile();
profile.setEmail("jspwiki.tests@mailinator.com");
profile.setLoginName(loginName);
profile.setFullname("FullName" + loginName);
profile.setPassword("password");
// Because user profile saves require approvals, we will catch a Redirect
try {
m_mgr.setUserProfile(session, profile);
Assert.fail("We should have caught a DecisionRequiredException caused by approval!");
} catch (DecisionRequiredException e) {
}
// The user should NOT be saved yet
Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
// Now, look in Admin's queue, and verify there's a pending Decision there
DecisionQueue dq = m_engine.getWorkflowManager().getDecisionQueue();
Collection decisions = dq.getActorDecisions(m_engine.adminSession());
Assert.assertEquals(1, decisions.size());
// Verify that the Decision has all the facts and attributes we need
Decision d = (Decision) decisions.iterator().next();
List facts = d.getFacts();
Assert.assertEquals(new Fact(UserManager.PREFS_FULL_NAME, profile.getFullname()), facts.get(0));
Assert.assertEquals(new Fact(UserManager.PREFS_LOGIN_NAME, profile.getLoginName()), facts.get(1));
Assert.assertEquals(new Fact(UserManager.FACT_SUBMITTER, session.getUserPrincipal().getName()), facts.get(2));
Assert.assertEquals(new Fact(UserManager.PREFS_EMAIL, profile.getEmail()), facts.get(3));
Assert.assertEquals(profile, d.getWorkflow().getAttribute(UserManager.SAVED_PROFILE));
// Approve the profile
d.decide(Outcome.DECISION_APPROVE);
// Make sure the profile saved successfully
Assert.assertEquals(oldUserCount + 1, m_db.getWikiNames().length);
// Now delete the profile; should be back to old count
m_db.deleteByLoginName(loginName);
Assert.assertEquals(oldUserCount, m_db.getWikiNames().length);
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class IfPluginTest method getJanneBasedWikiContextFor.
/**
* Returns a {@link WikiContext} for the given page, with user {@link Users#JANNE} logged in.
*
* @param page given {@link WikiPage}.
* @return {@link WikiContext} associated to given {@link WikiPage}.
* @throws WikiException problems while logging in.
*/
WikiContext getJanneBasedWikiContextFor(WikiPage page) throws WikiException {
MockHttpServletRequest request = testEngine.newHttpRequest();
WikiSession session = WikiSession.getWikiSession(testEngine, request);
testEngine.getAuthenticationManager().login(session, request, Users.JANNE, Users.JANNE_PASS);
return new WikiContext(testEngine, request, page);
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class AuthenticationManagerTest method testCustomAuthorizer.
/**
* Tests a dummy WebAuthorizer that is guaranteed to return true for one
* role for each of the two <code>isInRole</code> methods.
*
* @throws Exception
*/
@Test
public void testCustomAuthorizer() throws Exception {
Properties props = TestEngine.getTestProperties();
props.put(AuthorizationManager.PROP_AUTHORIZER, "org.apache.wiki.auth.AuthenticationManagerTest$DummyAuthorizer");
m_engine = new TestEngine(props);
// Start a session without any container roles: DummyAuthorizer should ALWAYS allow AuthorizerRole
WikiSession session = WikiSessionTest.authenticatedSession(m_engine, Users.JANNE, Users.JANNE_PASS);
Assert.assertTrue(session.hasPrincipal(Role.ALL));
Assert.assertTrue(session.hasPrincipal(Role.AUTHENTICATED));
Assert.assertTrue(session.hasPrincipal(new WikiPrincipal(Users.JANNE, WikiPrincipal.LOGIN_NAME)));
Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("JanneJalkanen", WikiPrincipal.WIKI_NAME)));
Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("Janne Jalkanen", WikiPrincipal.FULL_NAME)));
Assert.assertTrue(session.hasPrincipal(new Role("AuthorizerRole")));
Assert.assertFalse(session.hasPrincipal(new Role("ContainerRole")));
Assert.assertFalse(session.hasPrincipal(new Role("DummyRole")));
// Try again with a container-authenticated session: DummyAuthorizer should ALSO allow ContainerRole
session = WikiSessionTest.containerAuthenticatedSession(m_engine, Users.JANNE, new Principal[0]);
Assert.assertTrue(session.hasPrincipal(Role.ALL));
Assert.assertTrue(session.hasPrincipal(Role.AUTHENTICATED));
Assert.assertTrue(session.hasPrincipal(new WikiPrincipal(Users.JANNE, WikiPrincipal.LOGIN_NAME)));
Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("JanneJalkanen", WikiPrincipal.WIKI_NAME)));
Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("Janne Jalkanen", WikiPrincipal.FULL_NAME)));
Assert.assertTrue(session.hasPrincipal(new Role("AuthorizerRole")));
Assert.assertTrue(session.hasPrincipal(new Role("ContainerRole")));
Assert.assertFalse(session.hasPrincipal(new Role("DummyRole")));
}
Aggregations