Search in sources :

Example 1 with NHINDPrincipal

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) NHINDPrincipal(org.nhindirect.common.rest.auth.NHINDPrincipal) Test(org.junit.Test)

Example 2 with NHINDPrincipal

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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) NHINDPrincipal(org.nhindirect.common.rest.auth.NHINDPrincipal) Test(org.junit.Test)

Example 3 with NHINDPrincipal

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());
}
Also used : BasicAuthValidator(org.nhindirect.common.rest.auth.BasicAuthValidator) NHINDPrincipal(org.nhindirect.common.rest.auth.NHINDPrincipal) Test(org.junit.Test)

Example 4 with NHINDPrincipal

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());
}
Also used : BasicAuthValidator(org.nhindirect.common.rest.auth.BasicAuthValidator) NHINDPrincipal(org.nhindirect.common.rest.auth.NHINDPrincipal) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 NHINDPrincipal (org.nhindirect.common.rest.auth.NHINDPrincipal)4 FilterChain (javax.servlet.FilterChain)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 BasicAuthValidator (org.nhindirect.common.rest.auth.BasicAuthValidator)2