本文整理汇总了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