Search in sources :

Example 1 with SecurityContext

use of org.springframework.security.core.context.SecurityContext 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 SecurityContext

use of org.springframework.security.core.context.SecurityContext 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 SecurityContext

use of org.springframework.security.core.context.SecurityContext 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 SecurityContext

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

the class SavingsClosureActionStrutsTest method tearDown.

@After
public void tearDown() throws Exception {
    SecurityContext securityContext = new SecurityContextImpl();
    SecurityContextHolder.setContext(securityContext);
    savings = null;
    client1 = null;
    client2 = null;
    client3 = null;
    client4 = null;
    group = null;
    center = null;
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) SecurityContext(org.springframework.security.core.context.SecurityContext) After(org.junit.After)

Example 5 with SecurityContext

use of org.springframework.security.core.context.SecurityContext 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)

Aggregations

SecurityContext (org.springframework.security.core.context.SecurityContext)535 Authentication (org.springframework.security.core.Authentication)214 Test (org.junit.jupiter.api.Test)130 Test (org.junit.Test)128 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)120 SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)89 GrantedAuthority (org.springframework.security.core.GrantedAuthority)69 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)61 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)55 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)44 ArrayList (java.util.ArrayList)42 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)41 MifosUser (org.mifos.security.MifosUser)38 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 List (java.util.List)24 TransientSecurityContext (org.springframework.security.core.context.TransientSecurityContext)24 UserDetails (org.springframework.security.core.userdetails.UserDetails)24 Before (org.junit.Before)23 User (org.springframework.security.core.userdetails.User)22 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)20