Java 类org.springframework.security.web.PortResolver 实例源码

项目:GitHub    文件:DefaultSavedRequestTest.java   
public void test_for_issue() throws Exception {
        MockHttpServletRequest mockReq = new MockHttpServletRequest();
        DefaultSavedRequest request = new DefaultSavedRequest(mockReq, new PortResolver() {

            public int getServerPort(ServletRequest servletRequest) {
                return 0;
            }
        });

        String str = JSON.toJSONString(request, SerializerFeature.WriteClassName);
//        System.out.println(str);


        JSON.parseObject(str, Object.class, config);

        JSON.parseObject(str);
    }
项目:eHMP    文件:AuthControllerTests.java   
@Test
public void testDisplayLoginPageWithOriginalSavedRequestIfSetupComplete() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE);
    when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.TRUE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/login"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
项目:eHMP    文件:AuthControllerTests.java   
@Test
public void testDisplayLoginPageAfterAjaxRequestWhichFailedDueToExpiredSession() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE);
    when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.TRUE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/login"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
项目:eHMP    文件:AuthControllerTests.java   
@Test
public void testDisplaySyncStatusPageWhenOperationalSyncIncomplete() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.TRUE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/initializing"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
项目:eHMP    文件:AuthControllerTests.java   
@Test
public void testDisplayReindexStatusPageWhenReindexingIncomplete() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.FALSE);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/reindexing"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
项目:eHMP    文件:AuthControllerTests.java   
@Test
public void testDisplayDataStreamErrorPageWhenDataStreamFailure() throws Exception {
    when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true");
    when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred");
    when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE);
    when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE);
    when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.FALSE);
    Map<String, Object> derr = new HashMap<>();
    derr.put("disableMsg","There's a bar stuck in the foo");
    when(mockSyncService.getDataStreamErrorDetails()).thenReturn(derr);

    MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest();
    mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest");
    mockOriginalRequest.setScheme("https");
    mockOriginalRequest.setServerName("example.org");
    mockOriginalRequest.setServerPort(3333);
    mockOriginalRequest.setRequestURI("/foo/bar/baz");

    PortResolver mockPortResolver = mock(PortResolver.class);
    when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333);

    // spring security will have put the original request in the session
    mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver));

    ModelAndView mav = c.login(mockRequest, mockResponse);
    assertThat(mav.getViewName(), equalTo("/auth/dataStreamError"));
    assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred"));
}
项目:webpedidos    文件:JsfLoginUrlAuthenticationEntryPoint.java   
public void setPortResolver(PortResolver portResolver) {
    this.portResolver = portResolver;
}
项目:webpedidos    文件:JsfLoginUrlAuthenticationEntryPoint.java   
protected PortResolver getPortResolver() {
    return portResolver;
}
项目:PedidoVenda    文件:JsfLoginUrlAuthenticationEntryPoint.java   
public void setPortResolver(PortResolver portResolver) {
    this.portResolver = portResolver;
}
项目:PedidoVenda    文件:JsfLoginUrlAuthenticationEntryPoint.java   
protected PortResolver getPortResolver() {
    return this.portResolver;
}
项目:eHMP    文件:WebUtilsTests.java   
@Before
public void setUp() throws Exception {
    mockPortResolver = mock(PortResolver.class);
}
项目:oauth-client-master    文件:OAuthConsumerContextFilter.java   
/**
 * The port resolver.
 *
 * @return The port resolver.
 */
public PortResolver getPortResolver() {
    return portResolver;
}
项目:oauth-client-master    文件:OAuthConsumerContextFilter.java   
/**
 * The port resolver.
 *
 * @param portResolver The port resolver.
 */
public void setPortResolver(PortResolver portResolver) {
    this.portResolver = portResolver;
}