/** * Add an asynchronous part with {@link Publisher}-based content. * @param name the name of the part to add * @param publisher the part contents * @param elementClass the type of elements contained in the publisher * @return builder that allows for further customization of part headers */ public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publisher, Class<T> elementClass) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(elementClass, "'elementClass' must not be null"); HttpHeaders headers = new HttpHeaders(); PublisherPartBuilder<T, P> builder = new PublisherPartBuilder<>(headers, publisher, elementClass); this.parts.add(name, builder); return builder; }
@Test public void addAll() throws Exception { map.add("key", "value1"); map.addAll("key", Arrays.asList("value2", "value3")); assertEquals(1, map.size()); List<String> expected = new ArrayList<>(2); expected.add("value1"); expected.add("value2"); expected.add("value3"); assertEquals(expected, map.get("key")); }
/** * Variant of {@link #asyncPart(String, Publisher, Class)} that accepts a * {@link ParameterizedTypeReference} for the element type, which allows * specifying generic type information. * @param name the name of the part to add * @param publisher the part contents * @param typeReference the type of elements contained in the publisher * @return builder that allows for further customization of part headers */ public <T, P extends Publisher<T>> PartBuilder asyncPart( String name, P publisher, ParameterizedTypeReference<T> typeReference) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(typeReference, "'typeReference' must not be null"); HttpHeaders headers = new HttpHeaders(); PublisherPartBuilder<T, P> builder = new PublisherPartBuilder<>(headers, publisher, typeReference); this.parts.add(name, builder); return builder; }
/** * Add an asynchronous part with {@link Publisher}-based content. * @param name the name of the part to add * @param publisher the part contents * @param elementClass the type of elements contained in the publisher * @return builder that allows for further customization of part headers */ public <T, P extends Publisher<T>> PartBuilder asyncPart(String name, P publisher, Class<T> elementClass) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(elementClass, "'elementClass' must not be null"); HttpHeaders headers = new HttpHeaders(); PublisherPartBuilder<T, P> builder = new PublisherPartBuilder<>(headers, publisher, elementClass); this.parts.add(name, builder); return builder; }
public void updateAfterNewSubscription(String destination, String sessionId, String subsId) { synchronized (this.updateCache) { this.updateCache.forEach((cachedDestination, subscriptions) -> { if (getPathMatcher().match(destination, cachedDestination)) { // Subscription id's may also be populated via getSubscriptions() List<String> subsForSession = subscriptions.get(sessionId); if (subsForSession == null || !subsForSession.contains(subsId)) { subscriptions.add(sessionId, subsId); this.accessCache.put(cachedDestination, subscriptions.deepCopy()); } } }); } }
/** * Variant of {@link #asyncPart(String, Publisher, Class)} that accepts a * {@link ParameterizedTypeReference} for the element type, which allows * specifying generic type information. * @param name the name of the part to add * @param publisher the part contents * @param typeReference the type of elements contained in the publisher * @return builder that allows for further customization of part headers */ public <T, P extends Publisher<T>> PartBuilder asyncPart( String name, P publisher, ParameterizedTypeReference<T> typeReference) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(publisher, "'publisher' must not be null"); Assert.notNull(typeReference, "'typeReference' must not be null"); HttpHeaders headers = new HttpHeaders(); PublisherPartBuilder<T, P> builder = new PublisherPartBuilder<>(headers, publisher, typeReference); this.parts.add(name, builder); return builder; }
public LinkedMultiValueMap<String, ElasticAgentMetadata> allElasticAgentsGroupedByPluginId() { LinkedMultiValueMap<String, ElasticAgentMetadata> map = new LinkedMultiValueMap<>(); for (Map.Entry<String, AgentInstance> entry : agentInstances.entrySet()) { AgentInstance agentInstance = entry.getValue(); if (agentInstance.isElastic()) { ElasticAgentMetadata metadata = agentInstance.elasticAgentMetadata(); map.add(metadata.elasticPluginId(), metadata); } } return map; }
@Test public void pathSegmentParams() throws Exception { // basic LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("colors", "red"); params.add("colors", "blue"); params.add("colors", "green"); params.add("year", "2012"); testPathSegment("cars;colors=red,blue,green;year=2012", "cars", params); // trailing semicolon params = new LinkedMultiValueMap<>(); params.add("p", "1"); testPathSegment("path;p=1;", "path", params); // params with spaces params = new LinkedMultiValueMap<>(); params.add("param name", "param value"); testPathSegment("path;param%20name=param%20value;%20", "path", params); // empty params params = new LinkedMultiValueMap<>(); params.add("p", "1"); testPathSegment("path;;;%20;%20;p=1;%20", "path", params); }
public LinkedMultiValueMap<String, String> getSubscriptions(String destination, Message<?> message) { LinkedMultiValueMap<String, String> result = this.accessCache.get(destination); if (result == null) { synchronized (this.updateCache) { result = new LinkedMultiValueMap<>(); for (SessionSubscriptionInfo info : subscriptionRegistry.getAllSubscriptions()) { for (String destinationPattern : info.getDestinations()) { if (getPathMatcher().match(destinationPattern, destination)) { for (Subscription sub : info.getSubscriptions(destinationPattern)) { result.add(info.sessionId, sub.getId()); } } } } if (!result.isEmpty()) { this.updateCache.put(destination, result.deepCopy()); this.accessCache.put(destination, result); } } } return result; }
private String getLoginReadBearerToken() { HttpHeaders accessTokenHeaders = new HttpHeaders(); String basicDigestHeaderValue = "Basic " + new String(Base64.encodeBase64(("login:loginsecret").getBytes())); accessTokenHeaders.add("Authorization", basicDigestHeaderValue); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("grant_type", "client_credentials"); params.add("client_id", "login"); params.add("scope", "oauth.login"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, accessTokenHeaders); return (String) tokenResponse.getBody().get("access_token"); }
LinkedMultiValueMap<String, Part> result = new LinkedMultiValueMap<>(parts.size()); for (Part part : parts) { result.add(part.getName(), part);
private String getScimReadBearerToken() { HttpHeaders accessTokenHeaders = new HttpHeaders(); String basicDigestHeaderValue = "Basic " + new String(Base64.encodeBase64((testAccounts.getAdminClientId() + ":" + testAccounts.getAdminClientSecret()).getBytes())); accessTokenHeaders.add("Authorization", basicDigestHeaderValue); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("grant_type", "client_credentials"); params.add("client_id", testAccounts.getAdminClientId()); params.add("scope", "scim.read"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, accessTokenHeaders); return (String) tokenResponse.getBody().get("access_token"); }
@Test public void testRefreshTokenWithNonExistingZone() { LinkedMultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("grant_type", "refresh_token"); formData.add("refresh_token", "dummyrefreshtoken-r"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap(serverRunning.getAccessTokenUri().replace("localhost", "testzonedoesnotexist.localhost"), formData, new HttpHeaders()); assertEquals(HttpStatus.NOT_FOUND, tokenResponse.getStatusCode()); }
@Test public void testUserLoginViaPasswordGrantLoginHintUaaDoubleEncoded() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.add("Authorization", ((UaaTestAccounts) testAccounts).getAuthorizationHeader("cf", "")); LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>(); postBody.add("grant_type", "password"); postBody.add("username", testAccounts.getUserName()); postBody.add("password", testAccounts.getPassword()); postBody.add("login_hint", URLEncoder.encode("{\"origin\":\"uaa\"}", "utf-8")); ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/token", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); }
@Test public void testUserLoginViaPasswordGrantLoginHintUaa() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.add("Authorization", ((UaaTestAccounts) testAccounts).getAuthorizationHeader("cf", "")); LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>(); postBody.add("grant_type", "password"); postBody.add("username", testAccounts.getUserName()); postBody.add("password", testAccounts.getPassword()); postBody.add("login_hint", "{\"origin\":\"uaa\"}"); ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/token", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); }
@Test public void testUserLoginViaPasswordGrant() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.add("Authorization", ((UaaTestAccounts) testAccounts).getAuthorizationHeader("cf", "")); LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>(); postBody.add("grant_type", "password"); postBody.add("username", testAccounts.getUserName()); postBody.add("password", testAccounts.getPassword()); ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/token", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); }
@Test public void testRefreshTokenWithInactiveZone() { RestTemplate identityClient = IntegrationTestUtils .getClientCredentialsTemplate(IntegrationTestUtils.getClientCredentialsResource(serverRunning.getBaseUrl(), new String[]{"zones.write", "zones.read", "scim.zones"}, "identity", "identitysecret")); IntegrationTestUtils.createInactiveIdentityZone(identityClient, "http://localhost:8080/uaa"); LinkedMultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("grant_type", "refresh_token"); formData.add("refresh_token", "dummyrefreshtoken-r"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap(serverRunning.getAccessTokenUri().replace("localhost", "testzoneinactive.localhost"), formData, new HttpHeaders()); assertEquals(HttpStatus.NOT_FOUND, tokenResponse.getStatusCode()); } }
@Before @After public void logout_and_clear_cookies() { map.add("username", testAccounts.getUserName()); map.add("password", testAccounts.getPassword()); try { webDriver.get(baseUrl + "/logout.do"); }catch (org.openqa.selenium.TimeoutException x) { //try again - this should not be happening - 20 second timeouts webDriver.get(baseUrl + "/logout.do"); } webDriver.manage().deleteAllCookies(); webDriver.get(appUrl+"/j_spring_security_logout"); webDriver.manage().deleteAllCookies(); }