Search in sources :

Example 81 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project head by mifos.

the class EditStatusActionStrutsTest 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, EditStatusAction.class);
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().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)

Example 82 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project head by mifos.

the class LoanBOTestUtils method createLoanAccountWithDisbursement.

/**
     * Like
     * {@link #createLoanAccount(String, CustomerBO, AccountState, Date, LoanOfferingBO)}
     * but differs in various ways.
     *
     * Note: the manipulation done in this method looks very suspicious and
     * possibly wrong. Tests that use this method should be considered as
     * suspect.
     */
public static LoanBO createLoanAccountWithDisbursement(final CustomerBO customer, final AccountState state, final Date startDate, final LoanOfferingBO loanOffering, final int disbursalType, final Short noOfInstallments) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(startDate);
    MeetingBO meeting = TestObjectFactory.createLoanMeeting(customer.getCustomerMeeting().getMeeting());
    List<Date> meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), meeting, 6);
    MifosCurrency currency = TestUtils.RUPEE;
    List<CreateAccountFeeDto> accountFees = new ArrayList<CreateAccountFeeDto>();
    AmountFeeBO maintanenceFee = (AmountFeeBO) TestObjectFactory.createPeriodicAmountFee("Mainatnence Fee", FeeCategory.LOAN, "100", RecurrenceType.WEEKLY, Short.valueOf("1"));
    IntegrationTestObjectMother.saveFee(maintanenceFee);
    accountFees.add(new CreateAccountFeeDto(maintanenceFee.getFeeId().intValue(), maintanenceFee.getFeeAmount().toString()));
    AccountFeesEntity accountDisbursementFee = null;
    AmountFeeBO disbursementFee = null;
    AccountFeesEntity accountDisbursementFee2 = null;
    AmountFeeBO disbursementFee2 = null;
    if (disbursalType == 1 || disbursalType == 2) {
        disbursementFee = (AmountFeeBO) TestObjectFactory.createOneTimeAmountFee("Disbursement Fee 1", FeeCategory.LOAN, "10", FeePayment.TIME_OF_DISBURSEMENT);
        IntegrationTestObjectMother.saveFee(disbursementFee);
        accountFees.add(new CreateAccountFeeDto(disbursementFee.getFeeId().intValue(), disbursementFee.getFeeAmount().toString()));
        disbursementFee2 = (AmountFeeBO) TestObjectFactory.createOneTimeAmountFee("Disbursement Fee 2", FeeCategory.LOAN, "20", FeePayment.TIME_OF_DISBURSEMENT);
        IntegrationTestObjectMother.saveFee(disbursementFee2);
        accountFees.add(new CreateAccountFeeDto(disbursementFee2.getFeeId().intValue(), disbursementFee2.getFeeAmount().toString()));
    }
    BigDecimal loanAmount = BigDecimal.valueOf(DEFAULT_LOAN_AMOUNT);
    BigDecimal minAllowedLoanAmount = loanAmount;
    BigDecimal maxAllowedLoanAmount = loanAmount;
    Double interestRate = Double.valueOf("10.0");
    LocalDate disbursementDate = new LocalDate(meetingDates.get(0));
    int numberOfInstallments = noOfInstallments;
    int minAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int maxAllowedNumberOfInstallments = loanOffering.getEligibleInstallmentSameForAllLoan().getMaxNoOfInstall();
    int graceDuration = 0;
    Integer sourceOfFundId = null;
    Integer loanPurposeId = null;
    Integer collateralTypeId = null;
    String collateralNotes = null;
    String externalId = null;
    boolean repaymentScheduleIndependentOfCustomerMeeting = false;
    RecurringSchedule recurringSchedule = null;
    CreateLoanAccount createLoanAccount = new CreateLoanAccount(customer.getCustomerId(), loanOffering.getPrdOfferingId().intValue(), state.getValue().intValue(), loanAmount, minAllowedLoanAmount, maxAllowedLoanAmount, interestRate, disbursementDate, null, numberOfInstallments, minAllowedNumberOfInstallments, maxAllowedNumberOfInstallments, graceDuration, sourceOfFundId, loanPurposeId, collateralTypeId, collateralNotes, externalId, repaymentScheduleIndependentOfCustomerMeeting, recurringSchedule, accountFees, new ArrayList<CreateAccountPenaltyDto>());
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
    LoanBO loan = IntegrationTestObjectMother.createClientLoan(createLoanAccount);
    loan.updateDetails(TestUtils.makeUser());
    AccountFeesEntity accountPeriodicFee = new AccountFeesEntity(loan, maintanenceFee, new Double("10.0"));
    AccountTestUtils.addAccountFees(accountPeriodicFee, loan);
    if (disbursalType == 1 || disbursalType == 2) {
        accountDisbursementFee = new AccountFeesEntity(loan, disbursementFee, new Double("10.0"));
        AccountTestUtils.addAccountFees(accountDisbursementFee, loan);
        accountDisbursementFee2 = new AccountFeesEntity(loan, disbursementFee2, new Double("20.0"));
        AccountTestUtils.addAccountFees(accountDisbursementFee2, loan);
    }
    loan.setLoanMeeting(meeting);
    if (// 2-Interest At Disbursement
    disbursalType == 2) {
        loan.setInterestDeductedAtDisbursement(true);
        meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), loan.getLoanMeeting(), 6);
        short i = 0;
        for (Date date : meetingDates) {
            if (i == 0) {
                i++;
                loan.setDisbursementDate(date);
                LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i);
                actionDate.setActionDate(new java.sql.Date(date.getTime()));
                actionDate.setInterest(new Money(currency, "12.0"));
                actionDate.setPaymentStatus(PaymentStatus.UNPAID);
                AccountTestUtils.addAccountActionDate(actionDate, loan);
                // periodic fee
                AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "10.0"));
                setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
                actionDate.addAccountFeesAction(accountFeesaction);
                // dibursement fee one
                AccountFeesActionDetailEntity accountFeesaction1 = new LoanFeeScheduleEntity(actionDate, disbursementFee, accountDisbursementFee, new Money(currency, "10.0"));
                setFeeAmountPaid(accountFeesaction1, new Money(currency, "0.0"));
                actionDate.addAccountFeesAction(accountFeesaction1);
                // disbursementfee2
                AccountFeesActionDetailEntity accountFeesaction2 = new LoanFeeScheduleEntity(actionDate, disbursementFee2, accountDisbursementFee2, new Money(currency, "20.0"));
                setFeeAmountPaid(accountFeesaction2, new Money(currency, "0.0"));
                actionDate.addAccountFeesAction(accountFeesaction2);
                continue;
            }
            i++;
            LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i);
            actionDate.setActionDate(new java.sql.Date(date.getTime()));
            actionDate.setPrincipal(new Money(currency, "100.0"));
            actionDate.setInterest(new Money(currency, "12.0"));
            actionDate.setPaymentStatus(PaymentStatus.UNPAID);
            AccountTestUtils.addAccountActionDate(actionDate, loan);
            AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
            setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
            actionDate.addAccountFeesAction(accountFeesaction);
        }
    } else if (disbursalType == 1 || disbursalType == 3) {
        loan.setInterestDeductedAtDisbursement(false);
        meetingDates = TestObjectFactory.getMeetingDates(customer.getOfficeId(), loan.getLoanMeeting(), 6);
        short i = 0;
        for (Date date : meetingDates) {
            if (i == 0) {
                i++;
                loan.setDisbursementDate(date);
                continue;
            }
            LoanScheduleEntity actionDate = (LoanScheduleEntity) loan.getAccountActionDate(i++);
            actionDate.setActionDate(new java.sql.Date(date.getTime()));
            actionDate.setPrincipal(new Money(currency, "100.0"));
            actionDate.setInterest(new Money(currency, "12.0"));
            actionDate.setPaymentStatus(PaymentStatus.UNPAID);
            AccountTestUtils.addAccountActionDate(actionDate, loan);
            AccountFeesActionDetailEntity accountFeesaction = new LoanFeeScheduleEntity(actionDate, maintanenceFee, accountPeriodicFee, new Money(currency, "100.0"));
            setFeeAmountPaid(accountFeesaction, new Money(currency, "0.0"));
            actionDate.addAccountFeesAction(accountFeesaction);
        }
    }
    GracePeriodTypeEntity gracePeriodType = new GracePeriodTypeEntity(GraceType.NONE);
    loan.setGracePeriodType(gracePeriodType);
    loan.setCreatedBy(Short.valueOf("1"));
    // Set collateral type to lookup id 109, which references the lookup
    // value 'Type 1'
    loan.setCollateralTypeId(Integer.valueOf("109"));
    InterestTypesEntity interestTypes = new InterestTypesEntity(InterestType.FLAT);
    loan.setInterestType(interestTypes);
    loan.setInterestRate(10.0);
    loan.setCreatedDate(new Date(System.currentTimeMillis()));
    setLoanSummary(loan, currency);
    return loan;
}
Also used : InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) AccountFeesActionDetailEntity(org.mifos.accounts.business.AccountFeesActionDetailEntity) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) Money(org.mifos.framework.util.helpers.Money) CreateLoanAccount(org.mifos.clientportfolio.newloan.applicationservice.CreateLoanAccount) CreateAccountPenaltyDto(org.mifos.dto.domain.CreateAccountPenaltyDto) CreateAccountFeeDto(org.mifos.dto.domain.CreateAccountFeeDto) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosCurrency(org.mifos.application.master.business.MifosCurrency) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) BigDecimal(java.math.BigDecimal) RecurringSchedule(org.mifos.clientportfolio.loan.service.RecurringSchedule) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext)

Example 83 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project head by mifos.

the class MessageLookupIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    messageLookup = ApplicationContextProvider.getBean(MessageLookup.class);
    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)

Example 84 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project head by mifos.

the class SavingsActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    userContext = TestObjectFactory.getContext();
    userContext.setPreferredLocale(new Locale("en", "GB"));
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    createFlowAndAddToRequest(SavingsAction.class);
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser principal = new MifosUserBuilder().build();
    Authentication authentication = new TestingAuthenticationToken(principal, principal);
    securityContext.setAuthentication(authentication);
    SecurityContextHolder.setContext(securityContext);
}
Also used : Locale(java.util.Locale) 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)

Example 85 with TestingAuthenticationToken

use of org.springframework.security.authentication.TestingAuthenticationToken in project head by mifos.

the class ClientCustActionStrutsTest method testCreateSuccessWithAssociatedSavingsOfferings.

@Test
public void testCreateSuccessWithAssociatedSavingsOfferings() 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);
    savingsOffering1 = TestObjectFactory.createSavingsProduct("savingsPrd1", "s1", SavingsType.MANDATORY, ApplicableTo.CLIENTS, new Date(System.currentTimeMillis()));
    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();
    List<SavingsDetailDto> savingsOfferingList = getSavingsOfferingsFromSession();
    SavingsDetailDto savingsOffering = savingsOfferingList.get(0);
    setRequestPathInfo("/clientCustAction.do");
    addRequestParameter("method", "preview");
    addRequestParameter("input", "mfiInfo");
    addRequestParameter("loanOfficerId", "1");
    addRequestParameter("formedByPersonnel", "1");
    addRequestParameter("savingsOffering[0]", savingsOffering.getPrdOfferingId().toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    actionPerform();
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward(ActionForwards.preview_success.toString());
    MeetingBO weeklyMeeting = new MeetingBuilder().weekly().every(1).occuringOnA(WeekDay.WEDNESDAY).build();
    SessionUtils.setAttribute(CustomerConstants.CUSTOMER_MEETING, weeklyMeeting, request);
    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());
    Assert.assertNotNull(client);
    Assert.assertNotNull(client.getOfferingsAssociatedInCreate());
    Assert.assertEquals(1, client.getOfferingsAssociatedInCreate().size());
    for (ClientInitialSavingsOfferingEntity offering : client.getOfferingsAssociatedInCreate()) {
        Assert.assertEquals(savingsOffering1.getPrdOfferingId(), offering.getSavingsOffering().getPrdOfferingId());
        Assert.assertTrue(true);
    }
    removeFees(feesToRemove);
    savingsOffering1 = (SavingsOfferingBO) TestObjectFactory.getObject(SavingsOfferingBO.class, savingsOffering.getPrdOfferingId());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) BusinessActivityEntity(org.mifos.application.master.business.BusinessActivityEntity) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ApplicableAccountFeeDto(org.mifos.dto.domain.ApplicableAccountFeeDto) FeeDto(org.mifos.accounts.fees.business.FeeDto) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) Date(java.util.Date) 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)

Aggregations

TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)183 Test (org.junit.Test)106 Authentication (org.springframework.security.core.Authentication)76 SecurityContext (org.springframework.security.core.context.SecurityContext)46 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)38 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)38 MifosUser (org.mifos.security.MifosUser)36 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)32 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)28 Before (org.junit.Before)25 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 ConfigAttribute (org.springframework.security.access.ConfigAttribute)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 MockFilterChain (org.springframework.mock.web.MockFilterChain)9 GrantedAuthority (org.springframework.security.core.GrantedAuthority)9 FilterChain (javax.servlet.FilterChain)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)8 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)7