use of org.nhindirect.common.rest.auth.NHINDPrincipal in project nhin-d by DirectProject.
the class BasicAuthFilter_doFilterTest method testDoFilter_exsitingPrincipal.
@Test
public void testDoFilter_exsitingPrincipal() throws Exception {
final HttpSession session = mock(HttpSession.class);
final BasicAuthFilter filter = buildFilter();
final HttpServletRequest request = mock(HttpServletRequest.class);
final HttpServletResponse response = mock(HttpServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
when(request.getUserPrincipal()).thenReturn(new NHINDPrincipal("gm2552", "admin"));
filter.doFilter(request, response, chain);
verify(chain, times(1)).doFilter((HttpServletRequest) any(), eq(response));
verify(request, never()).getSession(eq(true));
verify(session, never()).setAttribute(eq("NHINDAuthPrincipalAttr"), (Principal) any());
verify(response, never()).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED));
verify(request, never()).getHeader(eq("Authorization"));
}
use of org.nhindirect.common.rest.auth.NHINDPrincipal in project nhin-d by DirectProject.
the class BasicAuthFilter_doFilterTest method testDoFilter_existingSession.
@Test
public void testDoFilter_existingSession() throws Exception {
final HttpSession session = mock(HttpSession.class);
final BasicAuthFilter filter = buildFilter();
final HttpServletRequest request = mock(HttpServletRequest.class);
final HttpServletResponse response = mock(HttpServletResponse.class);
final FilterChain chain = mock(FilterChain.class);
when(request.getSession(true)).thenReturn(session);
when(session.getAttribute("NHINDAuthPrincipalAttr")).thenReturn(new NHINDPrincipal("gm2552", "admin"));
filter.doFilter(request, response, chain);
verify(chain, times(1)).doFilter((HttpServletRequest) any(), eq(response));
verify(session, never()).setAttribute(eq("NHINDAuthPrincipalAttr"), (Principal) any());
verify(response, never()).sendError(eq(HttpServletResponse.SC_UNAUTHORIZED));
verify(request, never()).getHeader(eq("Authorization"));
}
use of org.nhindirect.common.rest.auth.NHINDPrincipal in project nhin-d by DirectProject.
the class HashableBasicAuthValidator_authenticateRawTest method testAuthenticate_validCredentials_assertPrinciple.
@Test
public void testAuthenticate_validCredentials_assertPrinciple() throws Exception {
BasicAuthValidator validator = buildValidator();
final String rawAuth = buildRawCredential("gm2552", "password");
NHINDPrincipal prin = validator.authenticate(rawAuth);
assertEquals("gm2552", prin.getName());
assertEquals("admin", prin.getRole());
}
use of org.nhindirect.common.rest.auth.NHINDPrincipal in project nhin-d by DirectProject.
the class HashableBasicAuthValidator_authenticateTest method testAuthenticate_validCredentials_assertPrinciple.
@Test
public void testAuthenticate_validCredentials_assertPrinciple() throws Exception {
BasicAuthValidator validator = buildValidator();
NHINDPrincipal prin = validator.authenticate("gm2552", "password");
assertEquals("gm2552", prin.getName());
assertEquals("admin", prin.getRole());
}
Aggregations