Search in sources :

Example 81 with SecurityContext

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

the class ApplyChargeActionStrutsTest 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 82 with SecurityContext

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

the class SavingsServiceFacadeWebTierTest method setupAndInjectDependencies.

@Before
public void setupAndInjectDependencies() {
    oldCurrency = Money.getDefaultCurrency();
    Money.setDefaultCurrency(TestUtils.RUPEE);
    savingsServiceFacade = new SavingsServiceFacadeWebTier(savingsDao, savingsProductDao, personnelDao, customerDao, holidayDao);
    ((SavingsServiceFacadeWebTier) savingsServiceFacade).setSavingsInterestScheduledEventFactory(savingsInterestScheduledEventFactory);
    ((SavingsServiceFacadeWebTier) savingsServiceFacade).setTransactionHelper(transactionHelper);
    MifosUser principal = new MifosUserBuilder().build();
    SecurityContext securityContext = SecurityContextHolder.getContext();
    if (securityContext == null) {
        securityContext = new SecurityContextImpl();
        SecurityContextHolder.setContext(securityContext);
    }
    if (securityContext.getAuthentication() == null || !securityContext.getAuthentication().isAuthenticated()) {
        Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal, principal.getAuthorities());
        securityContext.setAuthentication(authentication);
    }
}
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) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) Before(org.junit.Before)

Example 83 with SecurityContext

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

the class EditCustomerStatusActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    UserContext 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) UserContext(org.mifos.security.util.UserContext) 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 SecurityContext

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

the class MifosMockStrutsTestCase method beforeStrutsTest.

@Before
public void beforeStrutsTest() throws Exception {
    mockStruts.setUp();
    if (!strutsConfigSet) {
        setStrutsConfig();
        strutsConfigSet = true;
    }
    getActionServlet().getServletContext().setAttribute(ShutdownManager.class.getName(), new ShutdownManager());
    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) ShutdownManager(org.mifos.application.admin.system.ShutdownManager) MifosUser(org.mifos.security.MifosUser) MifosUserBuilder(org.mifos.builders.MifosUserBuilder) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Before(org.junit.Before)

Example 85 with SecurityContext

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

the class PersonnelNoteActionStrutsTest method testSuccessCreatePersonnelNote.

@Test
public void testSuccessCreatePersonnelNote() 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.create.toString());
    addRequestParameter("personnelId", personnel.getPersonnelId().toString());
    addRequestParameter("comment", "Test");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward(ActionForwards.create_success.toString());
    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)

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