Example usage for org.springframework.mock.web MockHttpServletRequest addUserRole

List of usage examples for org.springframework.mock.web MockHttpServletRequest addUserRole

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest addUserRole.

Prototype

public void addUserRole(String role) 

Source Link

Usage

From source file:org.opennms.core.test.rest.AbstractSpringJerseyRestTestCase.java

protected static MockHttpServletRequest createRequest(final ServletContext context, final String requestType,
        final String urlPath, Map<String, String> parameterMap, final String username,
        final Collection<String> roles) {
    final MockHttpServletRequest request = new MockHttpServletRequestThatWorks(context, requestType,
            contextPath + urlPath);//w  w  w.  jav  a 2  s  .c  o  m
    request.setContextPath(contextPath);
    request.setUserPrincipal(MockUserPrincipal.getInstance());
    MockUserPrincipal.setName(username);
    if (username != null) {
        for (final String role : roles) {
            request.addUserRole(role);
        }
    }
    if (parameterMap != null) {
        for (Entry<String, String> eachEntry : parameterMap.entrySet()) {
            request.addParameter(eachEntry.getKey(), eachEntry.getValue());
        }
    }
    return request;
}