本文整理匯總了Java中org.springframework.mock.web.MockHttpServletRequest.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java MockHttpServletRequest.setAttribute方法的具體用法?Java MockHttpServletRequest.setAttribute怎麽用?Java MockHttpServletRequest.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.mock.web.MockHttpServletRequest
的用法示例。
在下文中一共展示了MockHttpServletRequest.setAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:25,代碼來源:InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
示例2: renderView
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
private Map<?, ?> renderView() throws Exception{
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
final JstlView v = (JstlView) resolver.resolveViewName(modelAndView.getViewName(), Locale.getDefault());
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
v.setServletContext(req.getServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
new GenericWebApplicationContext(req.getServletContext()));
final Cas30ResponseView view = new Cas30ResponseView(v);
view.setServicesManager(this.servicesManager);
view.setCasAttributeEncoder(new DefaultCasAttributeEncoder(this.servicesManager));
final MockHttpServletResponse resp = new MockHttpServletResponse();
view.render(modelAndView.getModel(), req, resp);
return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
示例3: verifyView
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyView() throws Exception {
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
final JstlView v = (JstlView) resolver.resolveViewName(modelAndView.getViewName(), Locale.getDefault());
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
v.setServletContext(req.getServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
new GenericWebApplicationContext(req.getServletContext()));
final Cas20ResponseView view = new Cas20ResponseView(v);
final MockHttpServletResponse resp = new MockHttpServletResponse();
view.render(modelAndView.getModel(), req, resp);
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_CHAINED_AUTHENTICATIONS));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRIMARY_AUTHENTICATION));
assertNotNull(req.getAttribute(CasViewConstants.MODEL_ATTRIBUTE_NAME_PRINCIPAL));
assertNotNull(req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_PROXY_GRANTING_TICKET_IOU));
}
示例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(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
示例5: 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
示例6: renderView
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
private Map<?, ?> renderView() throws Exception {
final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, new GenericWebApplicationContext(req.getServletContext()));
final ProtocolAttributeEncoder encoder = new DefaultCasProtocolAttributeEncoder(this.servicesManager, NoOpCipherExecutor.getInstance());
final View viewDelegated = new View() {
@Override
public String getContentType() {
return MediaType.TEXT_HTML_VALUE;
}
@Override
public void render(final Map<String, ?> map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
map.forEach(request::setAttribute);
}
};
final Cas30ResponseView view = new Cas30ResponseView(true, encoder, servicesManager,
"attribute", viewDelegated, true);
final MockHttpServletResponse resp = new MockHttpServletResponse();
view.render(modelAndView.getModel(), req, resp);
return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
示例7: 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
示例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("", "error"));
request.setAttribute("flowRequestContext", context);
getThrottle().preHandle(request, response, null);
getThrottle().postHandle(request, response, null, null);
return response;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:15,代碼來源:AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
示例9: testError
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testError() {
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, 500);
mockRequest.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, "http://foo/bar");
mockRequest.setAttribute(RequestDispatcher.ERROR_MESSAGE, "Something was wrong");
mockRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, new IllegalStateException());
testResponse(new ErrorResource().errorHTML(mockRequest), false);
testResponse(new ErrorResource().errorText(mockRequest), false);
testResponse(new ErrorResource().errorEmpty(mockRequest), true);
}
示例10: verifyCreateSimpleWebApplicationServiceImplFromServiceAttribute
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyCreateSimpleWebApplicationServiceImplFromServiceAttribute() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute("service", "service");
final WebApplicationService impl = new WebApplicationServiceFactory().createService(request);
assertNotNull(impl);
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:8,代碼來源:SimpleWebApplicationServiceImplTests.java
示例11: verifyCredentialsResultsInSuccess
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyCredentialsResultsInSuccess() throws Exception {
final MockRequestContext context = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[] {VALID_CERTIFICATE});
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
assertEquals("success", this.action.execute(context).getId());
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:10,代碼來源:X509CertificateCredentialsNonInteractiveActionTests.java
示例12: verifyCredentialsResultsInSuccess
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyCredentialsResultsInSuccess() throws Exception {
final MockRequestContext context = new MockRequestContext();
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[]{VALID_CERTIFICATE});
context.setExternalContext(new ServletExternalContext(
new MockServletContext(), request, new MockHttpServletResponse()));
assertEquals("success", this.action.execute(context).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);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
request.setAttribute("flowRequestContext", context);
response.setStatus(HttpStatus.UNAUTHORIZED.value());
throttle.preHandle(request, response, null);
throttle.postHandle(request, response, null, null);
return response;
}
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:16,代碼來源:AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
示例14: verifyCreateSimpleWebApplicationServiceImplFromServiceAttribute
import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyCreateSimpleWebApplicationServiceImplFromServiceAttribute() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, SERVICE);
final WebApplicationService impl = new WebApplicationServiceFactory().createService(request);
assertNotNull(impl);
}
示例15: 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