Added checkstyle

This commit is contained in:
Marcin Grzejszczak
2019-02-05 15:21:41 +01:00
parent 7867256b90
commit 004e83b1e8
45 changed files with 848 additions and 620 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.cloudfoundry.environment;
import java.util.Collections;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.cloudfoundry.session;
import java.lang.annotation.Documented;
@@ -33,4 +34,4 @@ import org.springframework.context.annotation.Import;
@Import(StickyFilterConfiguration.class)
public @interface EnableStickyFilter {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.cloudfoundry.session;
import java.io.IOException;
@@ -52,7 +53,8 @@ public class StickyFilterConfiguration {
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
if (!response.containsHeader("Set-Cookie")) {
response.addCookie(new Cookie("JSESSIONID", cookie));
response.addCookie(new Cookie("JSESSIONID",
StickyFilterConfiguration.this.cookie));
}
filterChain.doFilter(request, response);
}

View File

@@ -1,2 +1,2 @@
spring.cloud.cloudfoundry.web.cookie=${random}
eureka.instance.metadata-map.cookie=${spring.cloud.cloudfoundry.web.cookie}
eureka.instance.metadata-map.cookie=${spring.cloud.cloudfoundry.web.cookie}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,20 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.cloudfoundry.environment;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.cloudfoundry.environment.VcapServiceCredentialsEnvironmentPostProcessor.STRING_OBJECT_MAP;
/**
@@ -42,66 +43,85 @@ public class VcapServiceCredentialsEnvironmentPostProcessorTests {
@Test
public void noop() {
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
Map<String, Object> properties = Binder.get(environment)
.bind("security.oauth2", STRING_OBJECT_MAP).orElseGet(Collections::emptyMap);
assertTrue(properties.isEmpty());
Map<String, Object> properties = Binder.get(this.environment)
.bind("security.oauth2", STRING_OBJECT_MAP)
.orElseGet(Collections::emptyMap);
assertThat(properties.isEmpty()).isTrue();
}
@Test
public void addClientId() {
TestPropertyValues.of("vcap.services.sso.credentials.clientId:foo").applyTo(this.environment);
TestPropertyValues.of("vcap.services.sso.credentials.clientId:foo")
.applyTo(this.environment);
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
assertEquals("foo", this.environment
.resolvePlaceholders("${security.oauth2.client.client-id}"));
assertThat(this.environment
.resolvePlaceholders("${security.oauth2.client.client-id}"))
.isEqualTo("foo");
}
@Test
public void addClientIdUnderscores() {
TestPropertyValues.of("vcap.services.sso.credentials.client-id:foo").applyTo(this.environment);
TestPropertyValues.of("vcap.services.sso.credentials.client-id:foo")
.applyTo(this.environment);
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
assertEquals("foo", this.environment
.resolvePlaceholders("${security.oauth2.client.client-id}"));
assertThat(this.environment
.resolvePlaceholders("${security.oauth2.client.client-id}"))
.isEqualTo("foo");
}
@Test
public void addTokenUri() {
TestPropertyValues.of( "vcap.services.sso.credentials.accessTokenUri:http://example.com").applyTo(this.environment);
TestPropertyValues
.of("vcap.services.sso.credentials.accessTokenUri:http://example.com")
.applyTo(this.environment);
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
assertEquals("http://example.com", this.environment
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
assertThat(this.environment
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
.isEqualTo("http://example.com");
}
@Test
public void addTokenUriAuthDomain() {
TestPropertyValues.of("vcap.services.sso.credentials.auth-domain:http://example.com").applyTo(this.environment);
TestPropertyValues
.of("vcap.services.sso.credentials.auth-domain:http://example.com")
.applyTo(this.environment);
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
assertEquals("http://example.com/oauth/token", this.environment
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
assertThat(this.environment
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
.isEqualTo("http://example.com/oauth/token");
}
@Test
public void addUserInfoUri() {
TestPropertyValues.of( "vcap.services.sso.credentials.userInfoUri:http://example.com").applyTo(this.environment);
TestPropertyValues
.of("vcap.services.sso.credentials.userInfoUri:http://example.com")
.applyTo(this.environment);
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
assertEquals("http://example.com", this.environment
.resolvePlaceholders("${security.oauth2.resource.user-info-uri}"));
assertThat(this.environment
.resolvePlaceholders("${security.oauth2.resource.user-info-uri}"))
.isEqualTo("http://example.com");
}
@Test
public void addServiceId() {
TestPropertyValues.of("vcap.services.my.credentials.accessTokenUri:http://example.com",
"security.oauth2.sso.serviceId:my").applyTo(this.environment);
TestPropertyValues
.of("vcap.services.my.credentials.accessTokenUri:http://example.com",
"security.oauth2.sso.serviceId:my")
.applyTo(this.environment);
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
assertEquals("http://example.com", this.environment
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
assertThat(this.environment
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
.isEqualTo("http://example.com");
}
@Test
public void addJwtKeyUri() {
TestPropertyValues.of("vcap.services.sso.credentials.keyUri:http://example.com").applyTo(this.environment);
TestPropertyValues.of("vcap.services.sso.credentials.keyUri:http://example.com")
.applyTo(this.environment);
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
assertEquals("http://example.com", this.environment
.resolvePlaceholders("${security.oauth2.resource.jwt.key-uri}"));
assertThat(this.environment
.resolvePlaceholders("${security.oauth2.resource.jwt.key-uri}"))
.isEqualTo("http://example.com");
}
}