Search in sources :

Example 1 with TestingAuthenticationToken

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

the class RepayLoanActionStrutsTest 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 2 with TestingAuthenticationToken

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

the class ApplyAdjustmentActionStrutsTest method setUpSecurityContext.

private void setUpSecurityContext() {
    SecurityContext securityContext = new SecurityContextImpl();
    MifosUser mifosUser = new MifosUserBuilder().nonLoanOfficer().withAdminRole().build();
    Authentication authentication = new TestingAuthenticationToken(mifosUser, mifosUser);
    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)

Example 3 with TestingAuthenticationToken

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

the class ApplyChargeActionStrutsTest method testUpdateSuccess.

@Test
public void testUpdateSuccess() {
    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();
    accountBO = getLoanAccount(client, meeting);
    setRequestPathInfo("/applyChargeAction.do");
    addRequestParameter("method", "update");
    addRequestParameter("chargeType", IS_PENALTY_TYPE + ":" + FEE_ID + ":" + IS_NOT_RATE_TYPE);
    addRequestParameter("charge", "18");
    addRequestParameter("accountId", accountBO.getAccountId().toString());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    //        verifyForward("loanDetails_success");
    verifyNoActionErrors();
    verifyNoActionMessages();
}
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 4 with TestingAuthenticationToken

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

the class SavingsDepositWithdrawalActionStrutsTest 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.USER_CONTEXT_KEY, userContext);
    request.getSession(false).setAttribute("ActivityContext", TestObjectFactory.getActivityContext());
    flowKey = createFlow(request, SavingsDepositWithdrawalAction.class);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    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 5 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)

Aggregations

TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)453 Test (org.junit.jupiter.api.Test)283 Authentication (org.springframework.security.core.Authentication)182 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)84 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)71 Test (org.junit.Test)69 SecurityContext (org.springframework.security.core.context.SecurityContext)68 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)54 AccessDeniedException (org.springframework.security.access.AccessDeniedException)50 BeforeEach (org.junit.jupiter.api.BeforeEach)46 MifosUser (org.mifos.security.MifosUser)36 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)33 MockFilterChain (org.springframework.mock.web.MockFilterChain)33 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)31 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)28 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)26 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)26 JoinPoint (org.aspectj.lang.JoinPoint)25 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)25 Method (java.lang.reflect.Method)24