use of org.codice.ddf.security.handler.api.UPAuthenticationToken in project ddf by codice.
the class LoginFilterTest method testValidUsernameToken.
@Test
public void testValidUsernameToken() throws IOException, XMLStreamException, ServletException, ParserConfigurationException, SAXException, SecurityServiceException {
FilterConfig filterConfig = mock(FilterConfig.class);
LoginFilter loginFilter = new LoginFilter();
loginFilter.setSessionFactory(sessionFactory);
ddf.security.service.SecurityManager securityManager = mock(ddf.security.service.SecurityManager.class);
loginFilter.setSecurityManager(securityManager);
loginFilter.init(filterConfig);
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
UPAuthenticationToken token = new UPAuthenticationToken("foo", "bar");
HandlerResult result = new HandlerResult(HandlerResult.Status.COMPLETED, token);
when(servletRequest.getAttribute("ddf.security.token")).thenReturn(result);
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession(true)).thenReturn(session);
when(session.getAttribute(SecurityConstants.SAML_ASSERTION)).thenReturn(new SecurityTokenHolder());
when(sessionFactory.getOrCreateSession(servletRequest)).thenReturn(session);
Subject subject = mock(Subject.class, RETURNS_DEEP_STUBS);
when(securityManager.getSubject(token)).thenReturn(subject);
SecurityAssertion assertion = mock(SecurityAssertion.class);
SecurityToken securityToken = mock(SecurityToken.class);
when(assertion.getSecurityToken()).thenReturn(securityToken);
when(subject.getPrincipals().asList()).thenReturn(Arrays.asList(assertion));
when(securityToken.getToken()).thenReturn(readDocument("/good_saml.xml").getDocumentElement());
loginFilter.doFilter(servletRequest, servletResponse, filterChain);
}
Aggregations