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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations