Search in sources :

Example 51 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-security-oauth by spring-projects.

the class RemoteTokenServices method loadAuthentication.

@Override
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException, InvalidTokenException {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add(tokenName, accessToken);
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", getAuthorizationHeader(clientId, clientSecret));
    Map<String, Object> map = postForMap(checkTokenEndpointUrl, formData, headers);
    if (map.containsKey("error")) {
        logger.debug("check_token returned error: " + map.get("error"));
        throw new InvalidTokenException(accessToken);
    }
    Assert.state(map.containsKey("client_id"), "Client id must be present in response from auth server");
    return tokenConverter.extractAuthentication(map);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) InvalidTokenException(org.springframework.security.oauth2.common.exceptions.InvalidTokenException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 52 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-security-oauth by spring-projects.

the class CustomProviderTests method customGrant.

@Test
public void customGrant() throws Exception {
    LinkedMultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("grant_type", "custom");
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Basic " + new String(Base64.encode(("my-trusted-client:").getBytes())));
    @SuppressWarnings("rawtypes") ResponseEntity<Map> response = http.postForMap("/oauth/token", headers, form);
    assertEquals(HttpStatus.OK, response.getStatusCode());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 53 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class SpringBootWebSecurityConfigurationTests method testHiddenHttpMethodFilterOrderedFirst.

// gh-3447
@Test
public void testHiddenHttpMethodFilterOrderedFirst() throws Exception {
    this.context = SpringApplication.run(DenyPostRequestConfig.class, "--server.port=0");
    int port = Integer.parseInt(this.context.getEnvironment().getProperty("local.server.port"));
    TestRestTemplate rest = new TestRestTemplate();
    // not overriding causes forbidden
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    ResponseEntity<Object> result = rest.postForEntity("http://localhost:" + port + "/", form, Object.class);
    assertThat(result.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
    // override method with GET
    form = new LinkedMultiValueMap<>();
    form.add("_method", "GET");
    result = rest.postForEntity("http://localhost:" + port + "/", form, Object.class);
    assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 54 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class SampleGroovyTemplateApplicationTests method testCreate.

@Test
public void testCreate() throws Exception {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.set("text", "FOO text");
    map.set("summary", "FOO");
    URI location = this.restTemplate.postForLocation("/", map);
    assertThat(location.toString()).contains("localhost:" + this.port);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) URI(java.net.URI) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 55 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-boot by spring-projects.

the class SampleMethodSecurityApplicationTests method testLogin.

@Test
public void testLogin() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set("username", "admin");
    form.set("password", "admin");
    getCsrf(form, headers);
    ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
    assertThat(entity.getHeaders().getLocation().toString()).isEqualTo("http://localhost:" + this.port + "/");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)76 Test (org.junit.Test)40 HttpHeaders (org.springframework.http.HttpHeaders)20 MultiValueMap (org.springframework.util.MultiValueMap)19 Map (java.util.Map)9 HttpEntity (org.springframework.http.HttpEntity)9 RestTemplate (org.springframework.web.client.RestTemplate)9 ClassPathResource (org.springframework.core.io.ClassPathResource)8 MediaType (org.springframework.http.MediaType)7 URI (java.net.URI)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Resource (org.springframework.core.io.Resource)5 HashMap (java.util.HashMap)4 FileItem (org.apache.commons.fileupload.FileItem)4 Credential (org.apereo.cas.authentication.Credential)4 IdmAuditDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)3