Search in sources :

Example 16 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project gocd by gocd.

the class ElasticAgentRequestProcessorTest method shouldProcessListAgentRequest.

@Test
public void shouldProcessListAgentRequest() throws Exception {
    LinkedMultiValueMap<String, ElasticAgentMetadata> allAgents = new LinkedMultiValueMap<>();
    ElasticAgentMetadata agent = new ElasticAgentMetadata("foo", "bar", "docker", AgentRuntimeStatus.Building, AgentConfigStatus.Disabled);
    allAgents.put("docker", Arrays.asList(agent));
    when(agentService.allElasticAgents()).thenReturn(allAgents);
    GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(REQUEST_SERVER_LIST_AGENTS, "1.0", pluginIdentifier));
    JSONAssert.assertEquals("[{\"agent_id\":\"bar\",\"agent_state\":\"Building\",\"build_state\":\"Building\",\"config_state\":\"Disabled\"}]", response.responseBody(), true);
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 17 with LinkedMultiValueMap

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

the class SampleMethodSecurityApplicationTests method testDenied.

@Test
public void testDenied() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
    form.set("username", "user");
    form.set("password", "user");
    getCsrf(form, headers);
    ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
    String cookie = entity.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);
    ResponseEntity<String> page = this.restTemplate.exchange(entity.getHeaders().getLocation(), HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
    assertThat(page.getBody()).contains("Access denied");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.

the class RestServiceRegistryConfiguration method restfulServiceRegistry.

@Bean
@RefreshScope
@SneakyThrows
public ServiceRegistry restfulServiceRegistry() {
    final ServiceRegistryProperties registry = casProperties.getServiceRegistry();
    final RestTemplate restTemplate = new RestTemplate();
    final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    if (StringUtils.isNotBlank(registry.getRest().getBasicAuthUsername()) && StringUtils.isNotBlank(registry.getRest().getBasicAuthPassword())) {
        final String auth = registry.getRest().getBasicAuthUsername() + ":" + registry.getRest().getBasicAuthPassword();
        final byte[] encodedAuth = EncodingUtils.encodeBase64ToByteArray(auth.getBytes(StandardCharsets.UTF_8));
        final String authHeader = "Basic " + new String(encodedAuth, StandardCharsets.UTF_8);
        headers.put("Authorization", CollectionUtils.wrap(authHeader));
    }
    return new RestServiceRegistry(restTemplate, registry.getRest().getUrl(), headers);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ServiceRegistryProperties(org.apereo.cas.configuration.model.core.services.ServiceRegistryProperties) RestTemplate(org.springframework.web.client.RestTemplate) RestServiceRegistry(org.apereo.cas.services.RestServiceRegistry) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) SneakyThrows(lombok.SneakyThrows) Bean(org.springframework.context.annotation.Bean)

Example 19 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.

the class X509RestHttpRequestCredentialFactoryTests method createX509Credential.

@Test
public void createX509Credential() throws IOException {
    final MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
    final Scanner scan = new Scanner(new ClassPathResource("ldap-crl.crt").getFile(), StandardCharsets.UTF_8.name());
    final String certStr = scan.useDelimiter("\\Z").next();
    scan.close();
    requestBody.add("cert", certStr);
    final Credential cred = factory.fromRequestBody(requestBody).iterator().next();
    assertTrue(cred instanceof X509CertificateCredential);
}
Also used : Scanner(java.util.Scanner) X509CertificateCredential(org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential) Credential(org.apereo.cas.authentication.Credential) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) X509CertificateCredential(org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 20 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.

the class X509RestHttpRequestCredentialFactoryTests method createDefaultCredential.

@Test
public void createDefaultCredential() {
    final MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
    requestBody.add("username", "name");
    requestBody.add("password", "passwd");
    final Collection cred = factory.fromRequestBody(requestBody);
    assertTrue(cred.isEmpty());
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)413 Test (org.junit.Test)153 HttpHeaders (org.springframework.http.HttpHeaders)126 MultiValueMap (org.springframework.util.MultiValueMap)94 Test (org.junit.jupiter.api.Test)88 HttpEntity (org.springframework.http.HttpEntity)60 List (java.util.List)42 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)40 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)37 HashMap (java.util.HashMap)36 MediaType (org.springframework.http.MediaType)34 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 URI (java.net.URI)33 Map (java.util.Map)31 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)30 ArrayList (java.util.ArrayList)27 UUID (java.util.UUID)27 lombok.val (lombok.val)27 IOException (java.io.IOException)26 Assert (org.junit.Assert)25