Codota Logo
MockHttpServletRequestBuilder.principal
Code IndexAdd Codota to your IDE (free)

How to use
principal
method
in
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder

Best Java code snippets using org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.principal (Showing top 17 results out of 315)

  • Common ways to obtain MockHttpServletRequestBuilder
private void myMethod () {
MockHttpServletRequestBuilder m =
  • Codota IconMockMvcRequestBuilders.get("<changeme>")
  • Codota IconString httpMethod;URI url;new MockHttpServletRequestBuilder(httpMethod, url)
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-framework

@Test
public void principal() {
  User user = new User();
  this.builder.principal(user);
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals(user, request.getUserPrincipal());
}
origin: spring-projects/spring-security

@Test
public void loginWhenJeeFilterThenExtractsRoles() throws Exception {
  this.spring.configLocations(xml("JeeFilter")).autowire();
  Principal user = mock(Principal.class);
  when(user.getName()).thenReturn("joe");
  this.mvc.perform(get("/roles")
      .principal(user)
      .with(request -> {
        request.addUserRole("admin");
        request.addUserRole("user");
        request.addUserRole("unmapped");
        return request;
      }))
      .andExpect(content().string("ROLE_admin,ROLE_user"));
}
origin: cloudfoundry/uaa

@Test
public void testSpecialMessageWhenNoAppsAreAuthorized() throws Exception {
  Mockito.when(approvalStore.getApprovalsForUser(anyString(), anyString())).thenReturn(Collections.emptyList());
  UaaPrincipal uaaPrincipal = new UaaPrincipal("fake-user-id", "username", "email@example.com", OriginKeys.UAA, null, IdentityZoneHolder.get().getId());
  UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(uaaPrincipal, null);
  mockMvc.perform(get("/profile").principal(authentication))
      .andExpect(status().isOk())
      .andExpect(model().attributeExists("approvals"))
      .andExpect(content().contentTypeCompatibleWith(TEXT_HTML))
      .andExpect(content().string(containsString("You have not yet authorized any third party applications.")));
}
origin: rest-assured/rest-assured

requestBuilder.principal((Principal) authentication);
origin: cloudfoundry/uaa

@Test
public void testPasswordLinkHiddenWhenUsersOriginIsNotUaa() throws Exception {
  UaaPrincipal uaaPrincipal = new UaaPrincipal("fake-user-id", "username", "email@example.com", OriginKeys.LDAP, "dnEntryForLdapUser", IdentityZoneHolder.get().getId());
  UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(uaaPrincipal, null);
  mockMvc.perform(get("/profile").principal(authentication))
      .andExpect(status().isOk())
      .andExpect(model().attribute("isUaaManagedUser", false))
      .andExpect(content().string(not(containsString("Change Password"))));
}
origin: cloudfoundry/uaa

public void testGetProfile(String name) throws Exception {
  UaaPrincipal uaaPrincipal = new UaaPrincipal("fake-user-id", "username", "email@example.com", OriginKeys.UAA, null, IdentityZoneHolder.get().getId());
  UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(uaaPrincipal, null);
  mockMvc.perform(get("/profile").principal(authentication))
    .andExpect(status().isOk())
    .andExpect(model().attributeExists("clientnames"))
    .andExpect(model().attribute("clientnames", hasKey("app")))
    .andExpect(model().attribute("clientnames", hasValue(is(name))))
    .andExpect(model().attribute("isUaaManagedUser", true))
    .andExpect(model().attribute("approvals", hasKey("app")))
    .andExpect(model().attribute("approvals", hasValue(hasSize(2))))
    .andExpect(content().contentTypeCompatibleWith(TEXT_HTML))
    .andExpect(content().string(containsString("These applications have been granted access to your account.")))
    .andExpect(content().string(containsString("Change Password")))
    .andExpect(content().string(containsString("<h3>"+name)))
    .andExpect(content().string(containsString("Are you sure you want to revoke access to " + name)));
}
origin: cloudfoundry/uaa

@Test
void testAccessConfirmationPage(
    @Autowired JdbcScimUserProvisioning jdbcScimUserProvisioning
) throws Exception {
  ScimUser marissa = jdbcScimUserProvisioning.query("username eq \"marissa\" and origin eq \"uaa\"", IdentityZoneHolder.get().getId()).get(0);
  UaaPrincipal uaaPrincipal = new UaaPrincipal(marissa.getId(), marissa.getUserName(), marissa.getPrimaryEmail(), marissa.getOrigin(), marissa.getExternalId(), IdentityZoneHolder.get().getId());
  UaaAuthentication principal = new UaaAuthentication(uaaPrincipal, singletonList(UaaAuthority.fromAuthorities("uaa.user")), null);
  MockHttpSession session = new MockHttpSession();
  SecurityContext securityContext = new SecurityContextImpl();
  securityContext.setAuthentication(principal);
  session.putValue("SPRING_SECURITY_CONTEXT", securityContext);
  MockHttpServletRequestBuilder get = get("/oauth/authorize")
      .accept(TEXT_HTML)
      .param("response_type", "code")
      .param("client_id", "app")
      .param("state", "somestate")
      .param("redirect_uri", "http://localhost:8080/app/")
      .session(session)
      .principal(principal);
  mockMvc.perform(get)
      .andExpect(status().isOk())
      .andExpect(forwardedUrl("/oauth/confirm_access"));
}
origin: zalando/nakadi

@Test
public void whenPostTimelineThenCreated() throws Exception {
  Mockito.doNothing().when(timelineService).createTimeline(Mockito.any(), Mockito.any(), Mockito.any());
  mockMvc.perform(MockMvcRequestBuilders.post("/event-types/event_type/timelines")
      .contentType(MediaType.APPLICATION_JSON)
      .content(new JSONObject().put("storage_id", "default").toString())
      .principal(PrincipalMockFactory.mockPrincipal("nakadi")))
      .andExpect(MockMvcResultMatchers.status().isCreated());
}
origin: zalando/nakadi

protected ResultActions deleteEventType(final String eventTypeName, final String clientId) throws Exception {
  return mockMvc.perform(delete("/event-types/" + eventTypeName).principal(mockPrincipal(clientId)));
}
origin: zalando/nakadi

@Test
public void testDeleteUnusedStorage() throws Exception {
  doNothing().when(storageService).deleteStorage("s1", Optional.empty());
  when(adminService.isAdmin(AuthorizationService.Operation.WRITE)).thenReturn(true);
  mockMvc.perform(delete("/storages/s1")
      .principal(mockPrincipal("nakadi")))
      .andExpect(status().isNoContent());
}
origin: zalando/nakadi

@Test
public void testPostStorage() throws Exception {
  final JSONObject json = createJsonKafkaStorage("test_storage");
  doNothing().when(storageService).createStorage(any(), any());
  when(adminService.isAdmin(AuthorizationService.Operation.WRITE)).thenReturn(true);
  mockMvc.perform(post("/storages")
      .contentType(APPLICATION_JSON)
      .content(json.toString())
      .principal(mockPrincipal("nakadi")))
      .andExpect(status().isCreated());
}
origin: zalando/nakadi

@Test
public void whenGetTimelinesThenOk() throws Exception {
  final Storage kafkaStorage = StoragesControllerTest.createKafkaStorage("deafult");
  final ImmutableList<Timeline> timelines = ImmutableList.of(
      Timeline.createTimeline("event_type", 0, kafkaStorage, "topic", new Date()),
      Timeline.createTimeline("event_type_1", 1, kafkaStorage, "topic_1", new Date()));
  Mockito.when(timelineService.getTimelines(Mockito.any())).thenReturn(timelines);
  final List<TimelineView> timelineViews = timelines.stream().map(TimelineView::new).collect(Collectors.toList());
  mockMvc.perform(MockMvcRequestBuilders.get("/event-types/event_type/timelines")
      .contentType(MediaType.APPLICATION_JSON)
      .principal(PrincipalMockFactory.mockPrincipal("nakadi")))
      .andExpect(MockMvcResultMatchers.status().isOk())
      .andExpect(MockMvcResultMatchers.content().json(
          TestUtils.OBJECT_MAPPER.writeValueAsString(timelineViews)));
}
origin: zalando/nakadi

@Test
public void testListStorages() throws Exception {
  final List<Storage> storages = createStorageList();
  when(storageService.listStorages())
      .thenReturn(storages);
  when(adminService.isAdmin(AuthorizationService.Operation.READ)).thenReturn(true);
  mockMvc.perform(get("/storages")
      .principal(mockPrincipal("nakadi")))
      .andExpect(status().isOk());
}
origin: zalando/nakadi

@Test
public void testSetDefaultStorageOk() throws Exception {
  when(storageService.setDefaultStorage("test_storage"))
      .thenReturn(createKafkaStorage("test_storage"));
  when(adminService.isAdmin(AuthorizationService.Operation.WRITE)).thenReturn(true);
  mockMvc.perform(put("/storages/default/test_storage")
      .contentType(APPLICATION_JSON)
      .principal(mockPrincipal("nakadi")))
      .andExpect(status().isOk());
}
origin: zalando/nakadi

@Test
public void testSetDefaultStorageAccessDenied() throws Exception {
  when(adminService.isAdmin(AuthorizationService.Operation.WRITE)).thenReturn(false);
  mockMvc.perform(put("/storages/default/test_storage")
      .contentType(APPLICATION_JSON)
      .principal(mockPrincipal("nakadi")))
      .andExpect(status().isForbidden());
}
origin: zalando/nakadi

protected ResultActions putEventType(final String content, final String name, final String clientId)
    throws Exception {
  final MockHttpServletRequestBuilder requestBuilder = put("/event-types/" + name)
      .principal(mockPrincipal(clientId))
      .contentType(APPLICATION_JSON)
      .content(content);
  return mockMvc.perform(requestBuilder);
}
origin: mstine/RefactoringTheMonolith

  @Test
  public void loadsCustomerForHome() throws Exception {
    this.mockMvc.perform(get("/")
        .principal(() -> "rey@theresistance.com"))
        .andExpect(status().isOk())
        .andExpect(model().attributeExists("currentCustomer"))
        .andExpect(view().name("home"));
  }
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuilderprincipal

Javadoc

Set the principal of the request.

Popular methods of MockHttpServletRequestBuilder

  • contentType
    Set the 'Content-Type' header of the request.
  • content
    Set the request body.
  • param
    Add a request parameter to the MockHttpServletRequest.If called more than once, new values get added
  • accept
    Set the 'Accept' header to the given media type(s).
  • header
    Add a header to the request. Values are always added.
  • with
    An extension point for further initialization of MockHttpServletRequestin ways not built directly in
  • requestAttr
    Set a request attribute.
  • buildRequest
    Build a MockHttpServletRequest.
  • contextPath
    Specify the portion of the requestURI that represents the context path. The context path, if specifi
  • flashAttr
    Set an "input" flash attribute.
  • headers
    Add all headers to the request. Values are always added.
  • session
    Set the HTTP session to use, possibly re-used across requests.Individual attributes provided via #se
  • headers,
  • session,
  • sessionAttr,
  • cookie,
  • params,
  • servletPath,
  • <init>,
  • characterEncoding,
  • locale

Popular in Java

  • Reading from database using SQL prepared statement
  • scheduleAtFixedRate (ScheduledExecutorService)
  • runOnUiThread (Activity)
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • List (java.util)
    A List is a collection which maintains an ordering for its elements. Every element in the List has a
  • Vector (java.util)
    The Vector class implements a growable array of objects. Like an array, it contains components that
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now