pull/5972/head
Phillip Webb 9 years ago
parent a1ac934bee
commit 6cdbdf9ad3

@ -45,7 +45,8 @@ import org.springframework.session.data.redis.config.annotation.web.http.RedisHt
@Conditional(SessionCondition.class) @Conditional(SessionCondition.class)
class RedisSessionConfiguration { class RedisSessionConfiguration {
private static final Logger logger = LoggerFactory.getLogger(RedisSessionConfiguration.class); private static final Logger logger = LoggerFactory
.getLogger(RedisSessionConfiguration.class);
@Configuration @Configuration
public static class SpringBootRedisHttpSessionConfiguration public static class SpringBootRedisHttpSessionConfiguration
@ -68,8 +69,8 @@ class RedisSessionConfiguration {
@PostConstruct @PostConstruct
public void validate() { public void validate() {
if (this.sessionProperties.getStoreType() == null) { if (this.sessionProperties.getStoreType() == null) {
logger.warn("Spring Session store type is mandatory: set " + logger.warn("Spring Session store type is mandatory: set "
"'spring.session.store-type=redis' in your configuration"); + "'spring.session.store-type=redis' in your configuration");
} }
} }

@ -55,7 +55,7 @@ import org.springframework.util.Assert;
@EnableConfigurationProperties(SessionProperties.class) @EnableConfigurationProperties(SessionProperties.class)
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HazelcastAutoConfiguration.class, @AutoConfigureAfter({ DataSourceAutoConfiguration.class, HazelcastAutoConfiguration.class,
MongoAutoConfiguration.class, RedisAutoConfiguration.class }) MongoAutoConfiguration.class, RedisAutoConfiguration.class })
@Import({ SessionConfigurationImportSelector.class, SessionRepositoryValidator.class}) @Import({ SessionConfigurationImportSelector.class, SessionRepositoryValidator.class })
public class SessionAutoConfiguration { public class SessionAutoConfiguration {
/** /**
@ -82,6 +82,7 @@ public class SessionAutoConfiguration {
static class SessionRepositoryValidator { static class SessionRepositoryValidator {
private SessionProperties sessionProperties; private SessionProperties sessionProperties;
private ObjectProvider<SessionRepository<?>> sessionRepositoryProvider; private ObjectProvider<SessionRepository<?>> sessionRepositoryProvider;
SessionRepositoryValidator(SessionProperties sessionProperties, SessionRepositoryValidator(SessionProperties sessionProperties,
@ -95,9 +96,9 @@ public class SessionAutoConfiguration {
StoreType storeType = this.sessionProperties.getStoreType(); StoreType storeType = this.sessionProperties.getStoreType();
if (storeType != StoreType.NONE) { if (storeType != StoreType.NONE) {
Assert.notNull(this.sessionRepositoryProvider.getIfAvailable(), Assert.notNull(this.sessionRepositoryProvider.getIfAvailable(),
"No session repository could " "No session repository could be auto-configured, check your "
+ "be auto-configured, check your configuration (session " + "configuration (session store type is '" + storeType
+ "store type is '" + storeType + "')"); + "')");
} }
} }

@ -32,7 +32,8 @@ import org.springframework.util.ClassUtils;
class SessionCondition extends SpringBootCondition { class SessionCondition extends SpringBootCondition {
private static final boolean redisPresent = ClassUtils.isPresent( private static final boolean redisPresent = ClassUtils.isPresent(
"org.springframework.data.redis.core.RedisTemplate", SessionCondition.class.getClassLoader()); "org.springframework.data.redis.core.RedisTemplate",
SessionCondition.class.getClassLoader());
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,
@ -43,11 +44,10 @@ class SessionCondition extends SpringBootCondition {
.getType(((AnnotationMetadata) metadata).getClassName()); .getType(((AnnotationMetadata) metadata).getClassName());
if (!resolver.containsProperty("store-type")) { if (!resolver.containsProperty("store-type")) {
if (sessionStoreType == StoreType.REDIS && redisPresent) { if (sessionStoreType == StoreType.REDIS && redisPresent) {
return ConditionOutcome.match("Session store type default to redis (deprecated)"); return ConditionOutcome
} .match("Session store type default to redis (deprecated)");
else {
return ConditionOutcome.noMatch("Session store type not set");
} }
return ConditionOutcome.noMatch("Session store type not set");
} }
String value = resolver.getProperty("store-type").replace("-", "_").toUpperCase(); String value = resolver.getProperty("store-type").replace("-", "_").toUpperCase();
if (value.equals(sessionStoreType.name())) { if (value.equals(sessionStoreType.name())) {

@ -39,19 +39,18 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
/** /**
* Test to validate that a custom {@link RestTemplate} can be defined * Test to validate that a custom {@link RestTemplate} can be defined with OAuth2 SSO.
* with OAuth2 SSO.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringBootTest @SpringBootTest
@TestPropertySource(properties = {"security.oauth2.client.clientId=client", @TestPropertySource(properties = { "security.oauth2.client.clientId=client",
"security.oauth2.client.clientSecret=secret", "security.oauth2.client.clientSecret=secret",
"security.oauth2.client.userAuthorizationUri=http://example.com/oauth/authorize", "security.oauth2.client.userAuthorizationUri=http://example.com/oauth/authorize",
"security.oauth2.client.accessTokenUri=http://example.com/oauth/token", "security.oauth2.client.accessTokenUri=http://example.com/oauth/token",
"security.oauth2.resource.jwt.keyValue=SSSSHHH"}) "security.oauth2.resource.jwt.keyValue=SSSSHHH" })
public class CustomRestTemplateBasicOAuth2SsoConfigurationTests { public class CustomRestTemplateBasicOAuth2SsoConfigurationTests {
@Autowired @Autowired
@ -82,5 +81,3 @@ public class CustomRestTemplateBasicOAuth2SsoConfigurationTests {
} }
} }

@ -64,7 +64,6 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
this.thrown.expect(BeanCreationException.class); this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("No session repository could be auto-configured"); this.thrown.expectMessage("No session repository could be auto-configured");
this.thrown.expectMessage("session store type is 'null'"); this.thrown.expectMessage("session store type is 'null'");
load(); load();
} }

@ -57,4 +57,10 @@ public class TriggerFileFilterTests {
assertThat(new TriggerFileFilter("thefile.txt").accept(file)).isFalse(); assertThat(new TriggerFileFilter("thefile.txt").accept(file)).isFalse();
} }
@Test
public void testName() throws Exception {
File file = this.temp.newFile(".triggerfile").getAbsoluteFile();
assertThat(new TriggerFileFilter(".triggerfile").accept(file)).isTrue();
}
} }

@ -51,7 +51,7 @@ public class Review implements Serializable {
@Enumerated(EnumType.ORDINAL) @Enumerated(EnumType.ORDINAL)
private Rating rating; private Rating rating;
@Column(name= "CHECK_IN_DATE", nullable = false) @Column(name = "CHECK_IN_DATE", nullable = false)
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
private Date checkInDate; private Date checkInDate;

@ -0,0 +1,73 @@
/*
* Copyright 2012-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.test;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Service;
public class SampleTest {
@Test
public void injection() throws Exception {
new AnnotationConfigApplicationContext(Config.class).close();
}
@Configuration
@Import(BeanC.class)
static class Config {
@Bean
public BeanA beanA() {
return new BeanA();
}
@Bean
public BeanB beanB() {
return new BeanB();
}
@Bean
public BeanC beanC() {
return new BeanC();
}
}
static class BeanA {
}
static class BeanB extends BeanA {
}
@Service
static class BeanC {
@Autowired
public void setBeanA(BeanA xxx) {
}
}
}
Loading…
Cancel
Save