List of usage examples for org.springframework.http MediaType APPLICATION_FORM_URLENCODED
MediaType APPLICATION_FORM_URLENCODED
To view the source code for org.springframework.http MediaType APPLICATION_FORM_URLENCODED.
Click Source Link
From source file:sy.rest.controller.test.GreetingControllerTest.java
private String getAccessToken(String username, String password) throws Exception { String authorization = "Basic " + new String(Base64Utils.encode("clientapp:123456".getBytes())); String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8"; // @formatter:off String content = mvc// ww w. ja v a2s. co m .perform(post("/oauth/token").header("Authorization", authorization) .contentType(MediaType.APPLICATION_FORM_URLENCODED).param("username", username) .param("password", password).param("grant_type", "secret").param("scope", "read write") .param("client_id", "clientapp").param("client_secret", "123456")) .andExpect(status().isOk()).andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.access_token", is(notNullValue()))) .andExpect(jsonPath("$.token_type", is(equalTo("bearer")))) .andExpect(jsonPath("$.refresh_token", is(notNullValue()))) .andExpect(jsonPath("$.expires_in", is(greaterThan(4000)))) .andExpect(jsonPath("$.scope", is(equalTo("read write")))).andReturn().getResponse() .getContentAsString(); // @formatter:on return content.substring(17, 53); }
From source file:com.sinespera.GreetingControllerTest.java
private String getAccessToken(String username, String password) throws Exception { String authorization = "Basic " + new String(Base64Utils.encode("clientapp:123456".getBytes())); String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8"; // @formatter:off String content = mvc/*from w w w . j av a 2s . co m*/ .perform(post("/oauth/token").header("Authorization", authorization) .contentType(MediaType.APPLICATION_FORM_URLENCODED).param("username", username) .param("password", password).param("grant_type", "password").param("scope", "read write") .param("client_id", "clientapp").param("client_secret", "123456")) .andExpect(status().isOk()).andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.access_token", is(notNullValue()))) .andExpect(jsonPath("$.token_type", is(equalTo("bearer")))) .andExpect(jsonPath("$.refresh_token", is(notNullValue()))) .andExpect(jsonPath("$.expires_in", is(greaterThan(4000)))) .andExpect(jsonPath("$.scope", is(equalTo("read write")))).andReturn().getResponse() .getContentAsString(); // @formatter:on return content.substring(17, 53); }
From source file:cz.cvut.jirutjak.fastimport.droid.oauth2.DefaultAccessTokenProvider.java
protected HttpEntity<MultiValueMap<String, String>> createAccessTokenRequestEntity( MultiValueMap<String, String> formData) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); return new HttpEntity<MultiValueMap<String, String>>(formData, headers); }
From source file:net.ambulando.oauth.test.resources.GreetingControllerTest.java
private Map<String, ?> getAccessTokenFromRefreshToken(final String refreshToken, final String scope, final String clientId, final String secret, final String grant) throws Exception { final String credentials = clientId + ":" + secret; final String authorization = "Basic " + new String(Base64Utils.encode(credentials.getBytes())); final String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8"; final String content = mvc .perform(post("/oauth/token").header("Authorization", authorization) .contentType(MediaType.APPLICATION_FORM_URLENCODED).param("refresh_token", refreshToken) .param("grant_type", grant).param("scope", scope).param("client_id", clientId) .param("client_secret", secret)) .andExpect(status().isOk()).andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.access_token", is(notNullValue()))) .andExpect(jsonPath("$.token_type", is(equalTo("bearer")))) .andExpect(jsonPath("$.refresh_token", is(notNullValue()))) .andExpect(jsonPath("$.expires_in", is(greaterThan(4000)))) .andExpect(jsonPath("$.scope", is(equalTo("read write")))).andReturn().getResponse() .getContentAsString();// w ww . j a v a2s. com return mapper.readValue(content, new TypeReference<Map<String, ?>>() { }); }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManager.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); String password = (String) authentication.getCredentials(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(); parameters.set("username", username); parameters.set("password", password); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = restTemplate.exchange(loginUrl, HttpMethod.POST, new HttpEntity<MultiValueMap<String, Object>>(parameters, headers), Map.class); if (response.getStatusCode() == HttpStatus.OK) { String userFromUaa = (String) response.getBody().get("username"); if (userFromUaa.equals(userFromUaa)) { logger.info("Successful authentication request for " + authentication.getName()); return new UsernamePasswordAuthenticationToken(username, null, UaaAuthority.USER_AUTHORITIES); }//from www .j ava 2 s.c o m } else if (response.getStatusCode() == HttpStatus.UNAUTHORIZED) { logger.info("Failed authentication request"); throw new BadCredentialsException("Authentication failed"); } else if (response.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) { logger.info("Internal error from UAA. Please Check the UAA logs."); } else { logger.error("Unexpected status code " + response.getStatusCode() + " from the UAA." + " Is a compatible version running?"); } throw new RuntimeException("Could not authenticate with remote server"); }
From source file:com.company.project.web.controller.LoginTest.java
@Test public void testAdminLoginSuccess() throws Exception { session = (MockHttpSession) mockMvc/*from w w w .j a va 2 s . com*/ .perform(post("/login").with(csrf()).contentType(MediaType.APPLICATION_FORM_URLENCODED) .param("username", "admin").param("password", "admin").param("remember_me_checkbox", "0")) .andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/admin")).andReturn().getRequest() .getSession(); assertNotNull(session); testAuthenticatedAsAdminNavigateToPages(); //assertNotNull(session.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY)); //assertNotNull(SecurityContextHolder.getContext().getAuthentication()); //mockMvc.perform(SecurityMockMvcRequestBuilders.logout()); //mockMvc.perform(SecurityMockMvcRequestBuilders.logout("/logout")); }
From source file:org.zalando.boot.etcd.EtcdClientTest.java
@Test public void put() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")) .andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.put("sample", "Hello world"); Assert.assertNotNull("response", response); server.verify();//ww w . j av a 2s .com }
From source file:proto.GreetingControllerTest.java
private String getAccessToken(String username, String password) throws Exception { String authorization = "Basic " + new String(Base64Utils.encode("clientapp:123456".getBytes())); String contentType = MediaType.APPLICATION_JSON + ";charset=UTF-8"; // @formatter:off String content = mvc//ww w . j ava 2 s . c om .perform(post("/oauth/token").header("Authorization", authorization) .contentType(MediaType.APPLICATION_FORM_URLENCODED).param("username", username) .param("password", password).param("grant_type", "password").param("scope", "read write") .param("client_id", "clientapp").param("client_secret", "123456")) .andExpect(status().isOk()).andExpect(content().contentType(contentType)) .andExpect(jsonPath("$.access_token", is(notNullValue()))) .andExpect(jsonPath("$.token_type", is(equalTo("bearer")))) .andExpect(jsonPath("$.refresh_token", is(notNullValue()))) .andExpect(jsonPath("$.expires_in", is(greaterThan(4000)))) .andExpect(jsonPath("$.scope", is(equalTo("read write")))).andReturn().getResponse() .getContentAsString(); // @formatter:on return content.substring(17, content.indexOf(",") - 1); }
From source file:com.example.ProxyAuthorizationServerTokenServices.java
private HttpHeaders createHeaders() { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + Base64Utils.encodeToString("cf:".getBytes())); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); return headers; }