Search in sources :

Example 11 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class BirtReportsUploadActionStrutsTest method setupReportEditPermission.

private void setupReportEditPermission(boolean allowReportEdit) throws Exception {
    UserContext userContext = TestUtils.makeUser();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
    request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, ac);
    RoleBO role = legacyRolesPermissionsDao.getRole(userContext.getRoles().iterator().next());
    List<ActivityEntity> roleActivities = new ArrayList<ActivityEntity>(role.getActivities());
    List<ActivityEntity> updatedRoleActivities = new ArrayList<ActivityEntity>();
    for (ActivityEntity ae : roleActivities) {
        if (ae.getId() != SecurityConstants.EDIT_REPORT_INFORMATION || allowReportEdit) {
            updatedRoleActivities.add(ae);
        }
    }
    try {
        StaticHibernateUtil.startTransaction();
        role.update(userContext.getId(), "test", updatedRoleActivities);
        legacyRolesPermissionsDao.save(role);
        StaticHibernateUtil.flushSession();
        for (ActivityEntity ae : legacyRolesPermissionsDao.getActivities()) {
            StaticHibernateUtil.getSessionTL().refresh(ae);
        }
        StaticHibernateUtil.commitTransaction();
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "edit");
    addRequestParameter("reportId", "1");
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class ReportsActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    userContext = TestUtils.makeUser();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
    request.getSession(false).setAttribute("ActivityContext", ac);
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Before(org.junit.Before)

Example 13 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class ReportsUserParamsActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    userContext = TestUtils.makeUser();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
    request.getSession(false).setAttribute("ActivityContext", ac);
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Before(org.junit.Before)

Example 14 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class RolesPermissionsActionStrutsTest method testCreate.

@Test
public void testCreate() throws Exception {
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "load");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.load_success.toString());
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "create");
    addRequestParameter("name", "New Role");
    addRequestParameter("activity(1)", "checkbox");
    addRequestParameter("activity(2)", "3");
    addRequestParameter("activity(3)", "4");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.create_success.toString());
    role = legacyRolesPermissionsDao.getRole("New Role");
    Assert.assertEquals(2, role.getActivities().size());
    UserContext userContext = TestUtils.makeUser(role.getId());
    ActivityContext activityContext = new ActivityContext((short) 3, (short) 1, (short) 0);
    Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext((short) 4, (short) 1, (short) 0);
    Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext((short) 5, (short) 1, (short) 0);
    Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 15 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class RolesPermissionsActionStrutsTest method testUpdateSuccess.

@Test
public void testUpdateSuccess() throws Exception {
    rolesPermissionService.createRole(RolesAndPermissionConstants.ADMIN_ROLE, "New Role", legacyRolesPermissionsDao.getActivitieIds());
    role = legacyRolesPermissionsDao.getRole("New Role");
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "manage");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("id", role.getId().toString());
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.manage_success.toString());
    Assert.assertNotNull(request.getAttribute(Constants.CURRENTFLOWKEY));
    setRequestPathInfo("/rolesPermission.do");
    addRequestParameter("method", "update");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter("name", role.getName());
    addRequestParameter("activity(1)", "checkbox");
    addRequestParameter("activity(2)", "3");
    addRequestParameter("activity(3)", "4");
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.update_success.toString());
    Assert.assertNull(request.getAttribute(Constants.CURRENTFLOWKEY));
    role = legacyRolesPermissionsDao.getRole(role.getId());
    Assert.assertEquals(2, role.getActivities().size());
    UserContext userContext = TestUtils.makeUser(role.getId());
    ActivityContext activityContext = new ActivityContext((short) 3, (short) 1, (short) 0);
    Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext((short) 4, (short) 1, (short) 0);
    Assert.assertTrue(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
    activityContext = new ActivityContext((short) 5, (short) 1, (short) 0);
    Assert.assertFalse(legacyRolesPermissionsDao.isActivityAllowed(userContext, activityContext));
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Aggregations

ActivityContext (org.mifos.security.util.ActivityContext)24 Before (org.junit.Before)13 UserContext (org.mifos.security.util.UserContext)12 HttpSession (javax.servlet.http.HttpSession)5 Test (org.junit.Test)3 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)3 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 FieldConfig (org.mifos.framework.components.fieldConfiguration.util.helpers.FieldConfig)2 PreviousRequestValues (org.mifos.framework.util.helpers.PreviousRequestValues)2 Enumeration (java.util.Enumeration)1 Locale (java.util.Locale)1 Random (java.util.Random)1 ServletException (javax.servlet.ServletException)1 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionForward (org.apache.struts.action.ActionForward)1 ActionMessage (org.apache.struts.action.ActionMessage)1