Skip to content

Commit b18e916

Browse files
committed
prevent TokenStore from loading when required properties are not found
This is to enable local development while the SSO connector exists on the classpath
1 parent 979bb04 commit b18e916

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
/bin/
1313
.project
1414
.settings
15-
.classpath
15+
.classpath
16+
17+
out/

src/main/java/io/pivotal/spring/cloud/IssuerCheckConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.pivotal.spring.cloud;
22

33
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
45
import org.springframework.context.annotation.Bean;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.security.oauth2.client.discovery.ProviderConfiguration;
@@ -12,6 +13,7 @@
1213
import java.net.MalformedURLException;
1314

1415
@Configuration
16+
@ConditionalOnProperty({"ssoServiceUrl", "security.oauth2.resource.jwk.key-set-uri"})
1517
public class IssuerCheckConfiguration {
1618
@Value("${ssoServiceUrl}")
1719
private String ssoServiceUrl;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.pivotal.spring.cloud;
2+
3+
import org.junit.Rule;
4+
import org.junit.Test;
5+
import org.junit.rules.ExpectedException;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.context.ApplicationContext;
11+
import org.springframework.security.oauth2.provider.token.TokenStore;
12+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13+
14+
@RunWith(SpringJUnit4ClassRunner.class)
15+
@SpringBootTest(classes = IssuerCheckConfiguration.class)
16+
public class IssuerCheckConfigurationLocalTest {
17+
18+
@Rule
19+
public ExpectedException thrown = ExpectedException.none();
20+
21+
@Autowired
22+
private ApplicationContext applicationContext;
23+
24+
@Test
25+
public void testJwkTokenStoreNotFoundInContext() {
26+
thrown.expect(NoSuchBeanDefinitionException.class);
27+
thrown.expectMessage("No qualifying bean of type 'org.springframework.security.oauth2.provider.token.TokenStore' available");
28+
29+
applicationContext.getBean( TokenStore.class );
30+
31+
}
32+
33+
}

0 commit comments

Comments
 (0)