本文整理匯總了Java中org.springframework.mock.web.MockHttpServletRequest.setRemoteAddr方法的典型用法代碼示例。如果您正苦於以下問題:Java MockHttpServletRequest.setRemoteAddr方法的具體用法?Java MockHttpServletRequest.setRemoteAddr怎麽用?Java MockHttpServletRequest.setRemoteAddr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.mock.web.MockHttpServletRequest
的用法示例。
在下文中一共展示了MockHttpServletRequest.setRemoteAddr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyTgtToSetRemovingOldTgt
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyTgtToSetRemovingOldTgt() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr(LOCALHOST_IP);
request.setLocalAddr(LOCALHOST_IP);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
final MockHttpServletResponse response = new MockHttpServletResponse();
request.addHeader("User-Agent", "Test");
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn(TEST_STRING);
request.setCookies(new Cookie("TGT", "test5"));
WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
assertEquals(SUCCESS, this.action.execute(this.context).getId());
request.setCookies(response.getCookies());
assertEquals(tgt.getId(), this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));
}
示例2: ensureRemoteIpShouldBeChecked
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void ensureRemoteIpShouldBeChecked() {
final BaseSpnegoKnownClientSystemsFilterAction action =
new BaseSpnegoKnownClientSystemsFilterAction("^192\\.158\\..+", "", 0);
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("192.158.5.781");
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
示例3: ensureRemoteIpShouldBeChecked
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void ensureRemoteIpShouldBeChecked() {
final BaseSpnegoKnownClientSystemsFilterAction action =
new BaseSpnegoKnownClientSystemsFilterAction("^192\\.158\\..+");
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("192.158.5.781");
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
示例4: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress)
throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event("", "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
getThrottle().preHandle(request, response, null);
try {
authenticationManager.authenticate(AuthenticationTransaction.wrap(badCredentials(username)));
} catch (final AuthenticationException e) {
getThrottle().postHandle(request, response, null, null);
return response;
}
fail("Expected AbstractAuthenticationException");
return null;
}
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:25,代碼來源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
示例5: ensureAltRemoteIpHeaderShouldBeChecked
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void ensureAltRemoteIpHeaderShouldBeChecked() {
final BaseSpnegoKnownClientSystemsFilterAction action =
new BaseSpnegoKnownClientSystemsFilterAction("^74\\.125\\..+", "alternateRemoteIp");
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("555.555.555.555");
req.addHeader("alternateRemoteIp", "74.125.136.102");
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:18,代碼來源:AllSpnegoKnownClientSystemsFilterActionTest.java
示例6: verifyIpMismatchWhenCheckingHostnameForSpnego
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyIpMismatchWhenCheckingHostnameForSpnego() {
final HostNameSpnegoKnownClientSystemsFilterAction action =
new HostNameSpnegoKnownClientSystemsFilterAction("\\w+\\.\\w+\\.\\w+");
action.setIpsToCheckPattern("14\\..+");
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("74.125.136.102");
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().no(this).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:19,代碼來源:AllSpnegoKnownClientSystemsFilterActionTest.java
示例7: ensureHostnameAndIpShouldDoSpnego
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void ensureHostnameAndIpShouldDoSpnego() {
final HostNameSpnegoKnownClientSystemsFilterAction action =
new HostNameSpnegoKnownClientSystemsFilterAction("\\w+\\.\\w+\\.\\w+");
action.setIpsToCheckPattern("74\\..+");
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("74.125.136.102");
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:19,代碼來源:AllSpnegoKnownClientSystemsFilterActionTest.java
示例8: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
throttle.preHandle(request, response, null);
try {
authenticationManager.authenticate(AuthenticationTransaction.wrap(CoreAuthenticationTestUtils.getService(), badCredentials(username)));
} catch (final AuthenticationException e) {
throttle.postHandle(request, response, null, null);
return response;
}
fail("Expected AbstractAuthenticationException");
return null;
}
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
示例9: ensureAltRemoteIpHeaderShouldBeChecked
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void ensureAltRemoteIpHeaderShouldBeChecked() {
final BaseSpnegoKnownClientSystemsFilterAction action =
new BaseSpnegoKnownClientSystemsFilterAction("^74\\.125\\..+", "alternateRemoteIp", 120);
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("555.555.555.555");
req.addHeader("alternateRemoteIp", ALTERNATE_REMOTE_IP);
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
示例10: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress)
throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event("", "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
getThrottle().preHandle(request, response, null);
try {
authenticationManager.authenticate(badCredentials(username));
} catch (final AuthenticationException e) {
getThrottle().postHandle(request, response, null, null);
return response;
}
fail("Expected AuthenticationException");
return null;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:25,代碼來源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
示例11: testAddEventWithWebAuthenticationDetails
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testAddEventWithWebAuthenticationDetails() {
HttpSession session = new MockHttpSession(null, "test-session-id");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
request.setRemoteAddr("1.2.3.4");
WebAuthenticationDetails details = new WebAuthenticationDetails(request);
Map<String, Object> data = new HashMap<>();
data.put("test-key", details);
AuditEvent event = new AuditEvent("test-user", "test-type", data);
customAuditEventRepository.add(event);
List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
assertThat(persistentAuditEvents).hasSize(1);
PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
示例12: verifyIpMismatchWhenCheckingHostnameForSpnego
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyIpMismatchWhenCheckingHostnameForSpnego() {
final HostNameSpnegoKnownClientSystemsFilterAction action =
new HostNameSpnegoKnownClientSystemsFilterAction("14\\..+", "", 0, "\\w+\\.\\w+\\.\\w+");
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr(ALTERNATE_REMOTE_IP);
final ServletExternalContext extCtx = new ServletExternalContext(
new MockServletContext(), req,
new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().no(this).getId());
}
示例13: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress)
throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event("", "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
getThrottle().preHandle(request, response, null);
try {
authenticationManager.authenticate(badCredentials(username));
} catch (final AuthenticationException e) {
getThrottle().postHandle(request, response, null, null);
return response;
}
fail("Expected AuthenticationException");
return null;
}
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:25,代碼來源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
示例14: loginUnsuccessfully
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event("", "error"));
request.setAttribute("flowRequestContext", context);
getThrottle().preHandle(request, response, null);
getThrottle().postHandle(request, response, null, null);
return response;
}
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:15,代碼來源:AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
示例15: setUp
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@BeforeClass
public static void setUp() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("1.2.3.4");
request.setLocalAddr("7.8.9.0");
ClientInfoHolder.setClientInfo(new ClientInfo(request));
}