Search in sources :

Example 86 with TestingAuthenticationToken

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

the class CustomerNotesActionStrutsTest 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 87 with TestingAuthenticationToken

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

the class CustomerUIHelperFnStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    userContext = TestObjectFactory.getContext();
    request.getSession().setAttribute(Constants.USER_CONTEXT_KEY, userContext);
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    flowKey = createFlow(request, EditCustomerStatusAction.class);
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    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) EditCustomerStatusAction(org.mifos.customers.struts.action.EditCustomerStatusAction) Before(org.junit.Before)

Example 88 with TestingAuthenticationToken

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

the class ApprovalInterceptorTest method init.

@BeforeClass
public static void init() {
    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) BeforeClass(org.junit.BeforeClass)

Example 89 with TestingAuthenticationToken

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

the class PersonnelNoteActionStrutsTest method testSuccessSearch.

@Test
public void testSuccessSearch() 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);
    createPersonnelAndSetInSession(getBranchOffice(), PersonnelLevel.LOAN_OFFICER);
    setRequestPathInfo("/personnelNoteAction.do");
    addRequestParameter("method", Methods.load.toString());
    addRequestParameter("personnelId", personnel.getPersonnelId().toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    setRequestPathInfo("/personnelNoteAction.do");
    addRequestParameter("method", Methods.preview.toString());
    addRequestParameter("comment", "Notes created");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    setRequestPathInfo("/personnelNoteAction.do");
    addRequestParameter("method", Methods.create.toString());
    addRequestParameter("comment", "Notes created");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    StaticHibernateUtil.flushSession();
    setRequestPathInfo("/PersonAction.do");
    addRequestParameter("method", Methods.get.toString());
    addRequestParameter("globalPersonnelNum", personnel.getGlobalPersonnelNum());
    StaticHibernateUtil.flushAndClearSession();
    actionPerform();
    setRequestPathInfo("/personnelNoteAction.do");
    addRequestParameter("method", Methods.search.toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward(ActionForwards.search_success.toString());
    verifyNoActionErrors();
    verifyNoActionMessages();
    Assert.assertEquals("Size of the search result should be 1", 1, ((QueryResult) SessionUtils.getAttribute(Constants.SEARCH_RESULTS, request)).getSize());
    StaticHibernateUtil.flushSession();
    personnel = (PersonnelBO) TestObjectFactory.getObject(PersonnelBO.class, personnel.getPersonnelId());
}
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) Test(org.junit.Test)

Example 90 with TestingAuthenticationToken

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

the class CustHistoricalDataActionStrutsTest method testUpdateHistoricalDataWhenCustHistoricalDataIsNull.

@Test
public void testUpdateHistoricalDataWhenCustHistoricalDataIsNull() 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();
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, group, request);
    setRequestPathInfo("/custHistoricalDataAction.do");
    addRequestParameter("method", "updateHistoricalData");
    addRequestParameter("productName", "Test");
    addRequestParameter("loanAmount", "100");
    addRequestParameter("totalAmountPaid", "50");
    addRequestParameter("interestPaid", "10");
    addRequestParameter("missedPaymentsCount", "1");
    addRequestParameter("totalPaymentsCount", "2");
    addRequestParameter("commentNotes", "Test notes");
    addRequestParameter("loanCycleNumber", "1");
    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(), "100"), group.getHistoricalData().getLoanAmount());
    Assert.assertEquals(new Money(getCurrency(), "50"), group.getHistoricalData().getTotalAmountPaid());
    Assert.assertEquals(new Money(getCurrency(), "10"), group.getHistoricalData().getInterestPaid());
    Assert.assertEquals(1, group.getHistoricalData().getMissedPaymentsCount().intValue());
    Assert.assertEquals(2, group.getHistoricalData().getTotalPaymentsCount().intValue());
    Assert.assertEquals(1, 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) 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)

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