Search in sources :

Example 86 with SecurityContext

use of org.springframework.security.core.context.SecurityContext in project head by mifos.

the class CustHistoricalDataActionStrutsTest method testUpdateHistoricalDataWhenCustHistoricalDataIsNotNull.

@Test
public void testUpdateHistoricalDataWhenCustHistoricalDataIsNotNull() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    createInitialObjects();
    CustomerHistoricalDataEntity customerHistoricalDataEntity = new CustomerHistoricalDataEntity(group);
    group.updateHistoricalData(customerHistoricalDataEntity);
    group.update();
    StaticHibernateUtil.flushSession();
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, group, request);
    setRequestPathInfo("/custHistoricalDataAction.do");
    addRequestParameter("method", "updateHistoricalData");
    addRequestParameter("productName", "Test");
    addRequestParameter("loanAmount", "200");
    addRequestParameter("totalAmountPaid", "150");
    addRequestParameter("interestPaid", "50");
    addRequestParameter("missedPaymentsCount", "2");
    addRequestParameter("totalPaymentsCount", "3");
    addRequestParameter("commentNotes", "Test notes");
    addRequestParameter("loanCycleNumber", "2");
    addRequestParameter("type", "Group");
    addRequestParameter("mfiJoiningDate", DateUtils.getCurrentDate(((UserContext) request.getSession().getAttribute("UserContext")).getPreferredLocale()));
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyForward(ActionForwards.updateHistoricalData_success.toString());
    verifyNoActionErrors();
    verifyNoActionMessages();
    group = TestObjectFactory.getGroup(group.getCustomerId());
    Assert.assertEquals("Test", group.getHistoricalData().getProductName());
    Assert.assertEquals("Test notes", group.getHistoricalData().getNotes());
    Assert.assertEquals(new Money(getCurrency(), "200"), group.getHistoricalData().getLoanAmount());
    Assert.assertEquals(new Money(getCurrency(), "150"), group.getHistoricalData().getTotalAmountPaid());
    Assert.assertEquals(new Money(getCurrency(), "50"), group.getHistoricalData().getInterestPaid());
    Assert.assertEquals(2, group.getHistoricalData().getMissedPaymentsCount().intValue());
    Assert.assertEquals(3, group.getHistoricalData().getTotalPaymentsCount().intValue());
    Assert.assertEquals(2, group.getHistoricalData().getLoanCycleNumber().intValue());
}
Also used : Money(org.mifos.framework.util.helpers.Money) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) UserContext(org.mifos.security.util.UserContext) CustomerHistoricalDataEntity(org.mifos.customers.business.CustomerHistoricalDataEntity) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 87 with SecurityContext

use of org.springframework.security.core.context.SecurityContext in project head by mifos.

the class MeetingActionStrutsTest method setMifosUserFromContext.

private void setMifosUserFromContext() {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUser(userContext.getId(), userContext.getBranchId(), userContext.getLevelId(), new ArrayList<Short>(userContext.getRoles()), userContext.getName(), "".getBytes(), true, true, true, true, new ArrayList<GrantedAuthority>(), userContext.getLocaleId());
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken)

Example 88 with SecurityContext

use of org.springframework.security.core.context.SecurityContext in project head by mifos.

the class GroupActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    userContext = TestObjectFactory.getContext();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    flowKey = createFlow(request, GroupCustAction.class);
    EntityMasterData.getInstance().init();
    FieldConfig fieldConfig = FieldConfig.getInstance();
    fieldConfig.init();
    getActionServlet().getServletContext().setAttribute(Constants.FIELD_CONFIGURATION, fieldConfig.getEntityMandatoryFieldMap());
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) FieldConfig(org.mifos.framework.components.fieldConfiguration.util.helpers.FieldConfig) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 89 with SecurityContext

use of org.springframework.security.core.context.SecurityContext in project head by mifos.

the class ClientCustActionStrutsTest method testCreateSuccessWithoutGroup.

@Test
public void testCreateSuccessWithoutGroup() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    //        List<FeeDto> feesToRemove = getFees(RecurrenceType.WEEKLY);
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "load");
    addRequestParameter("officeId", "3");
    addRequestParameter("groupFlag", "0");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    flowKey = (String) request.getAttribute(Constants.CURRENTFLOWKEY);
    List<BusinessActivityEntity> povertyStatus = (List<BusinessActivityEntity>) SessionUtils.getAttribute(ClientConstants.POVERTY_STATUS, request);
    List<CustomFieldDto> customFieldDefs = getCustomFieldFromSession();
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "next");
    addRequestParameter("officeId", "3");
    addRequestParameter("clientName.salutation", "1");
    addRequestParameter("clientName.firstName", "Client");
    addRequestParameter("clientName.lastName", "LastName");
    addRequestParameter("spouseName.firstName", "Spouse");
    addRequestParameter("spouseName.lastName", "LastName");
    addRequestParameter("spouseName.nameType", "1");
    addRequestDateParameter("dateOfBirth", "20/3/1987");
    addRequestParameter("clientDetailView.gender", "1");
    addRequestParameter("input", "personalInfo");
    addRequestParameter("customerDetail.povertyStatus", povertyStatus.get(0).getId().toString());
    int i = 0;
    for (CustomFieldDto customFieldDef : customFieldDefs) {
        addRequestParameter("customField[" + i + "].fieldId", customFieldDef.getFieldId().toString());
        addRequestParameter("customField[" + i + "].fieldValue", "Req");
        i++;
    }
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    MeetingBO weeklyMeeting = new MeetingBuilder().weekly().every(1).occuringOnA(WeekDay.WEDNESDAY).build();
    SessionUtils.setAttribute(CustomerConstants.CUSTOMER_MEETING, weeklyMeeting, request);
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "preview");
    addRequestParameter("input", "mfiInfo");
    addRequestParameter("loanOfficerId", "1");
    addRequestParameter("formedByPersonnel", "1");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.preview_success.toString());
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "create");
    addRequestParameter("input", "create");
    addRequestParameter("status", "1");
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.create_success.toString());
    ClientCustActionForm actionForm = (ClientCustActionForm) request.getSession().getAttribute("clientCustActionForm");
    client = TestObjectFactory.getClient(actionForm.getCustomerIdAsInt());
//        removeFees(feesToRemove);
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) BusinessActivityEntity(org.mifos.application.master.business.BusinessActivityEntity) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) List(java.util.List) ArrayList(java.util.ArrayList) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) Test(org.junit.Test)

Example 90 with SecurityContext

use of org.springframework.security.core.context.SecurityContext in project head by mifos.

the class LoanArrearsAgingHelperIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    StaticHibernateUtil.getSessionTL().clear();
    oldRoundingMode = (String) MifosConfigurationManager.getInstance().getProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE);
    //FIXME this test was using CELLING ROUNDING MODE due to MIFOS-2659
    MifosConfigurationManager.getInstance().setProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE, RoundingMode.CEILING.toString());
    /*
         * Takes lateness days out of the equation so that the LoanArrearsTask will set all overdue account into bad
         * standing.
         *
         * Resetting the database in tear down puts the original value back for other tests
         */
    setLatenessDaysToZero();
    LoanArrearsTask arrearsTask = new LoanArrearsTask();
    loanArrearHelper = (LoanArrearsHelper) arrearsTask.getTaskHelper();
    LoanArrearsAgingTask loanArrearsAgingTask = new LoanArrearsAgingTask();
    loanArrearsAgingHelper = (LoanArrearsAgingHelper) loanArrearsAgingTask.getTaskHelper();
    dateTime = initializeToFixedDateTime();
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Aggregations

SecurityContext (org.springframework.security.core.context.SecurityContext)147 Test (org.junit.Test)65 Authentication (org.springframework.security.core.Authentication)63 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)46 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)46 MifosUser (org.mifos.security.MifosUser)38 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)21 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 HttpServletResponse (javax.servlet.http.HttpServletResponse)15 Before (org.junit.Before)15 GrantedAuthority (org.springframework.security.core.GrantedAuthority)13 ArrayList (java.util.ArrayList)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)7 SessionDestroyedEvent (org.springframework.security.core.session.SessionDestroyedEvent)7 HttpSession (javax.servlet.http.HttpSession)6 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)6