Search in sources :

Example 6 with IPersonManager

use of org.apereo.portal.security.IPersonManager in project uPortal by Jasig.

the class PersonalizationTestUtils method mockPersonManager.

public static IPersonManager mockPersonManager(HttpServletRequest req, IPerson person) {
    IPersonManager pMgr = Mockito.mock(IPersonManager.class);
    Mockito.when(pMgr.getPerson(req)).thenReturn(person);
    return pMgr;
}
Also used : IPersonManager(org.apereo.portal.security.IPersonManager)

Example 7 with IPersonManager

use of org.apereo.portal.security.IPersonManager in project uPortal by Jasig.

the class PersonalizationFilterTest method mockPersonManager.

public static IPersonManager mockPersonManager(HttpServletRequest req, IPerson person) {
    IPersonManager pMgr = Mockito.mock(IPersonManager.class);
    Mockito.when(pMgr.getPerson(req)).thenReturn(person);
    return pMgr;
}
Also used : IPersonManager(org.apereo.portal.security.IPersonManager)

Example 8 with IPersonManager

use of org.apereo.portal.security.IPersonManager in project uPortal by Jasig.

the class MaxInactiveFilterTest method noSessionWorkflow.

@Test
public void noSessionWorkflow() throws IOException, ServletException {
    final HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getSession()).thenReturn(null);
    // no calls, used in doFilter()
    final ServletResponse resp = mock(ServletResponse.class);
    final FilterChain chain = mock(FilterChain.class);
    final IPersonManager personManager = mock(IPersonManager.class);
    final IMaxInactiveStrategy maxInactiveStrategy = mock(IMaxInactiveStrategy.class);
    final MaxInactiveFilter filter = new MaxInactiveFilter();
    ReflectionTestUtils.setField(filter, "personManager", personManager);
    ReflectionTestUtils.setField(filter, "maxInactiveStrategy", maxInactiveStrategy);
    filter.doFilter(req, resp, chain);
    verifyNoMoreInteractions(personManager);
    verifyNoMoreInteractions(maxInactiveStrategy);
    verifyNoMoreInteractions(resp);
    verify(req, only()).getSession(false);
    verify(chain, only()).doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletResponse(javax.servlet.ServletResponse) IPersonManager(org.apereo.portal.security.IPersonManager) FilterChain(javax.servlet.FilterChain) Test(org.junit.Test)

Example 9 with IPersonManager

use of org.apereo.portal.security.IPersonManager in project uPortal by Jasig.

the class MaxInactiveFilterTest method noSecurityContextWorkflow.

@Test
public void noSecurityContextWorkflow() throws IOException, ServletException {
    final HttpSession session = mock(HttpSession.class);
    final HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getSession(false)).thenReturn(session);
    // no calls, used in doFilter()
    final ServletResponse resp = mock(ServletResponse.class);
    final FilterChain chain = mock(FilterChain.class);
    final IPerson person = mock(IPerson.class);
    when(person.getSecurityContext()).thenReturn(null);
    when(person.getAttribute(IPerson.USERNAME)).thenReturn("jsmith");
    final IPersonManager personManager = mock(IPersonManager.class);
    when(personManager.getPerson(req)).thenReturn(person);
    final IMaxInactiveStrategy maxInactiveStrategy = mock(IMaxInactiveStrategy.class);
    final MaxInactiveFilter filter = new MaxInactiveFilter();
    ReflectionTestUtils.setField(filter, "personManager", personManager);
    ReflectionTestUtils.setField(filter, "maxInactiveStrategy", maxInactiveStrategy);
    filter.doFilter(req, resp, chain);
    verify(person, times(1)).getSecurityContext();
    verify(person, times(1)).getAttribute(IPerson.USERNAME);
    verify(personManager, times(1)).getPerson(req);
    verifyNoMoreInteractions(maxInactiveStrategy);
    verifyNoMoreInteractions(resp);
    verifyNoMoreInteractions(session);
    verify(chain, only()).doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletResponse(javax.servlet.ServletResponse) IPerson(org.apereo.portal.security.IPerson) IPersonManager(org.apereo.portal.security.IPersonManager) HttpSession(javax.servlet.http.HttpSession) FilterChain(javax.servlet.FilterChain) Test(org.junit.Test)

Example 10 with IPersonManager

use of org.apereo.portal.security.IPersonManager in project uPortal by Jasig.

the class MaxInactiveFilterTest method timeSetOutsideRefreshDurationWorkflow.

@Test
public void timeSetOutsideRefreshDurationWorkflow() throws IOException, ServletException {
    final HttpSession session = mock(HttpSession.class);
    final HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getSession(false)).thenReturn(session);
    // no calls, used in doFilter()
    final ServletResponse resp = mock(ServletResponse.class);
    final FilterChain chain = mock(FilterChain.class);
    final ISecurityContext securityContext = mock(ISecurityContext.class);
    when(securityContext.isAuthenticated()).thenReturn(true);
    final IPerson person = mock(IPerson.class);
    when(person.getSecurityContext()).thenReturn(securityContext);
    final LocalDateTime lastTime = LocalDateTime.now(tz).minusMinutes(REFRESH_MINUTES + 2);
    when(person.getAttribute(SESSION_MAX_INACTIVE_SET_ATTR)).thenReturn(lastTime);
    when(person.getAttribute(IPerson.USERNAME)).thenReturn("jsmith");
    final IPersonManager personManager = mock(IPersonManager.class);
    when(personManager.getPerson(req)).thenReturn(person);
    final IMaxInactiveStrategy maxInactiveStrategy = mock(IMaxInactiveStrategy.class);
    when(maxInactiveStrategy.calcMaxInactive(person)).thenReturn(null);
    final MaxInactiveFilter filter = new MaxInactiveFilter();
    ReflectionTestUtils.setField(filter, "personManager", personManager);
    ReflectionTestUtils.setField(filter, "maxInactiveStrategy", maxInactiveStrategy);
    filter.doFilter(req, resp, chain);
    verify(person, times(1)).setAttribute(eq(SESSION_MAX_INACTIVE_SET_ATTR), any(LocalDateTime.class));
    verify(maxInactiveStrategy, times(1)).calcMaxInactive(person);
    verify(securityContext, times(1)).isAuthenticated();
    verify(person, times(1)).getSecurityContext();
    verify(person, times(1)).getAttribute(SESSION_MAX_INACTIVE_SET_ATTR);
    verify(person, times(1)).getAttribute(IPerson.USERNAME);
    verify(personManager, times(1)).getPerson(req);
    verifyNoMoreInteractions(resp);
    verifyNoMoreInteractions(session);
    verify(chain, only()).doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LocalDateTime(java.time.LocalDateTime) ServletResponse(javax.servlet.ServletResponse) IPerson(org.apereo.portal.security.IPerson) IPersonManager(org.apereo.portal.security.IPersonManager) HttpSession(javax.servlet.http.HttpSession) FilterChain(javax.servlet.FilterChain) ISecurityContext(org.apereo.portal.security.ISecurityContext) Test(org.junit.Test)

Aggregations

IPersonManager (org.apereo.portal.security.IPersonManager)10 FilterChain (javax.servlet.FilterChain)7 ServletResponse (javax.servlet.ServletResponse)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Test (org.junit.Test)7 HttpSession (javax.servlet.http.HttpSession)6 IPerson (org.apereo.portal.security.IPerson)6 ISecurityContext (org.apereo.portal.security.ISecurityContext)4 LocalDateTime (java.time.LocalDateTime)3 Before (org.junit.Before)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1