Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit 74eaa05

Browse files
author
Mario
committed
1204 - Stormpath Enabled and Spring Security property switches
1 parent c8b112d commit 74eaa05

File tree

28 files changed

+729
-23
lines changed

28 files changed

+729
-23
lines changed

extensions/spring/boot/stormpath-spring-security-spring-boot-starter/src/main/java/com/stormpath/spring/boot/autoconfigure/StormpathSpringSecurityAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*/
4040
@SuppressWarnings("SpringFacetCodeInspection")
4141
@Configuration
42-
@ConditionalOnProperty(name = { "stormpath.enabled", "stormpath.spring.security.enabled" }, matchIfMissing = true)
42+
@ConditionalOnProperty(name = { "stormpath.enabled", "stormpath.spring.security.enabled", "security.basic.enabled"}, matchIfMissing = true)
4343
@AutoConfigureAfter({ StormpathAutoConfiguration.class, SecurityAutoConfiguration.class })
4444
public class StormpathSpringSecurityAutoConfiguration extends AbstractStormpathSpringSecurityConfiguration {
4545

extensions/spring/boot/stormpath-spring-security-webmvc-spring-boot-starter/src/main/java/com/stormpath/spring/boot/autoconfigure/StormpathWebSecurityAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*/
5151
@SuppressWarnings("SpringFacetCodeInspection")
5252
@Configuration
53-
@ConditionalOnProperty(name = {"stormpath.enabled", "stormpath.web.enabled", "stormpath.spring.security.enabled"}, matchIfMissing = true)
53+
@ConditionalOnProperty(name = {"stormpath.enabled", "stormpath.web.enabled", "stormpath.spring.security.enabled", "security.basic.enabled"}, matchIfMissing = true)
5454
@ConditionalOnClass({Servlet.class, Filter.class, DispatcherServlet.class})
5555
@ConditionalOnWebApplication
5656
@AutoConfigureBefore(StormpathWebMvcAutoConfiguration.class)

extensions/spring/boot/stormpath-spring-security-webmvc-spring-boot-starter/src/main/java/com/stormpath/spring/boot/autoconfigure/StormpathWebSecurityDisabledAutoConfiguration.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.stormpath.spring.config.AbstractStormpathWebSecurityDisabledConfiguration;
1919
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2020
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
21+
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
2122
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
@@ -39,20 +40,22 @@
3940
@ConditionalOnClass({Servlet.class, Filter.class, DispatcherServlet.class})
4041
@ConditionalOnWebApplication
4142
@AutoConfigureAfter(StormpathWebSecurityAutoConfiguration.class)
43+
@ConditionalOnExpression("'${stormpath.spring.security.enabled}'=='false' || '${security.basic.enabled}'=='false'")
4244
public class StormpathWebSecurityDisabledAutoConfiguration extends AbstractStormpathWebSecurityDisabledConfiguration {
4345

4446
@Bean
4547
@ConditionalOnMissingBean(name="stormpathSecurityConfigurerAdapter")
46-
@ConditionalOnProperty(name = "stormpath.spring.security.enabled", havingValue = "false")
48+
@ConditionalOnProperty(name = "security.basic.enabled", havingValue = "true") //we only need our Disabled Configurer Adapter if Spring Security is enabled
4749
public SecurityConfigurerAdapter stormpathSecurityConfigurerAdapter() {
48-
//This bean will only be created if `stormpath.spring.security.enabled` is false
50+
//This bean will only be created if our Spring Security integration is disabled but Spring Security is enabled
4951
return super.stormpathSecurityConfigurerAdapter();
5052
}
5153

5254
@Bean
5355
@ConditionalOnMissingBean(name="stormpathLogoutHandler")
54-
@ConditionalOnProperty(name = "stormpath.spring.security.enabled", havingValue = "false")
56+
@ConditionalOnProperty(name = "security.basic.enabled", havingValue = "true") //we only need our logout handler if Spring Security is enabled
5557
public LogoutHandler stormpathLogoutHandler() {
58+
//This bean will only be created if our Spring Security integration is disabled but Spring Security is enabled
5659
return super.stormpathLogoutHandler();
5760
}
5861

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright 2017 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.stormpath.spring.boot.autoconfigure
17+
18+
import autoconfigure.DisabledSpringSecurityDisablesStormpathSSAutoConfigurationTestApplication
19+
import com.stormpath.sdk.api.ApiKey
20+
import com.stormpath.sdk.application.Application
21+
import com.stormpath.sdk.cache.CacheManager
22+
import com.stormpath.sdk.client.Client
23+
import com.stormpath.sdk.servlet.csrf.CsrfTokenManager
24+
import com.stormpath.sdk.servlet.csrf.DefaultCsrfTokenManager
25+
import com.stormpath.sdk.servlet.event.RequestEventListener
26+
import com.stormpath.sdk.servlet.http.authc.HeaderAuthenticator
27+
import com.stormpath.sdk.servlet.mvc.Controller
28+
import com.stormpath.spring.config.TwoAppTenantStormpathTestConfiguration
29+
import com.stormpath.spring.security.provider.GroupPermissionResolver
30+
import com.stormpath.spring.security.provider.StormpathAuthenticationProvider
31+
import org.springframework.beans.factory.annotation.Autowired
32+
import org.springframework.boot.test.context.SpringBootTest
33+
import org.springframework.boot.web.servlet.FilterRegistrationBean
34+
import org.springframework.security.config.annotation.SecurityConfigurerAdapter
35+
import org.springframework.security.web.FilterChainProxy
36+
import org.springframework.security.web.authentication.logout.LogoutHandler
37+
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests
38+
import org.springframework.test.context.web.WebAppConfiguration
39+
import org.testng.annotations.Test
40+
41+
import static org.testng.Assert.assertNotNull
42+
import static org.testng.Assert.assertNull
43+
import static org.testng.Assert.assertTrue
44+
45+
/**
46+
* Disabling Spring Security must also disable Stormpath's Spring Security integration
47+
*
48+
* @since 1.3.2
49+
*/
50+
@SpringBootTest(classes = [DisabledSpringSecurityDisablesStormpathSSAutoConfigurationTestApplication.class, TwoAppTenantStormpathTestConfiguration.class])
51+
@WebAppConfiguration
52+
class DisabledSpringSecurityDisablesStormpathSSAutoConfigurationIT extends AbstractTestNGSpringContextTests {
53+
54+
@Autowired
55+
Client client
56+
57+
@Autowired
58+
ApiKey apiKey;
59+
60+
@Autowired
61+
CacheManager stormpathCacheManager;
62+
63+
@Autowired
64+
Application application;
65+
66+
@Autowired
67+
FilterRegistrationBean stormpathFilter
68+
69+
@Autowired(required = false)
70+
SecurityConfigurerAdapter stormpathSecurityConfigurerAdapter
71+
72+
@Autowired
73+
FilterChainProxy springSecurityFilterChain
74+
75+
@Autowired
76+
HeaderAuthenticator stormpathAuthorizationHeaderAuthenticator
77+
78+
@Autowired(required = false)
79+
Controller stormpathForgotPasswordController
80+
81+
//Spring Security Beans
82+
@Autowired(required = false)
83+
StormpathAuthenticationProvider stormpathAuthenticationProvider
84+
85+
@Autowired(required = false)
86+
GroupPermissionResolver stormpathGroupPermissionResolver
87+
88+
@Autowired
89+
RequestEventListener stormpathRequestEventListener
90+
91+
@Autowired
92+
CsrfTokenManager stormpathCsrfTokenManager
93+
94+
@Autowired(required = false)
95+
LogoutHandler stormpathLogoutHandler
96+
97+
@Test
98+
void test() {
99+
assertNotNull client
100+
assertNotNull apiKey
101+
assertNotNull stormpathCacheManager
102+
assertNotNull stormpathFilter
103+
assertNull stormpathSecurityConfigurerAdapter
104+
assertNotNull application
105+
assertNotNull springSecurityFilterChain
106+
assertNull stormpathAuthenticationProvider
107+
assertNull stormpathGroupPermissionResolver
108+
assertNotNull stormpathRequestEventListener
109+
assertTrue stormpathCsrfTokenManager instanceof DefaultCsrfTokenManager
110+
assertNotNull stormpathAuthorizationHeaderAuthenticator
111+
assertNotNull stormpathForgotPasswordController
112+
assertNull stormpathLogoutHandler //when Spring Security is disabled we do not need our logout handler
113+
}
114+
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2017 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.stormpath.spring.boot.autoconfigure
17+
18+
import autoconfigure.DisabledStormpathAutoConfigurationTestApplication
19+
import com.stormpath.sdk.api.ApiKey
20+
import com.stormpath.sdk.application.Application
21+
import com.stormpath.sdk.cache.CacheManager
22+
import com.stormpath.sdk.client.Client
23+
import com.stormpath.sdk.servlet.csrf.CsrfTokenManager
24+
import com.stormpath.sdk.servlet.event.RequestEventListener
25+
import com.stormpath.sdk.servlet.filter.StormpathFilter
26+
import com.stormpath.sdk.servlet.http.authc.HeaderAuthenticator
27+
import com.stormpath.sdk.servlet.mvc.Controller
28+
import com.stormpath.spring.security.provider.*
29+
import org.springframework.beans.factory.annotation.Autowired
30+
import org.springframework.boot.test.context.SpringBootTest
31+
import org.springframework.security.config.annotation.SecurityConfigurerAdapter
32+
import org.springframework.security.web.FilterChainProxy
33+
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests
34+
import org.springframework.test.context.web.WebAppConfiguration
35+
import org.testng.annotations.Test
36+
37+
import static org.testng.Assert.assertNull
38+
import static org.testng.Assert.assertTrue
39+
40+
/**
41+
* @since 1.3.2
42+
*/
43+
@SpringBootTest(classes = [DisabledStormpathAutoConfigurationTestApplication.class])
44+
@WebAppConfiguration
45+
class DisabledStormpathAutoConfigurationIT extends AbstractTestNGSpringContextTests {
46+
47+
@Autowired(required = false)
48+
Client client
49+
50+
@Autowired(required = false)
51+
ApiKey apiKey;
52+
53+
@Autowired(required = false)
54+
CacheManager stormpathCacheManager;
55+
56+
@Autowired(required = false)
57+
Application application;
58+
59+
@Autowired(required = false)
60+
StormpathFilter stormpathFilter
61+
62+
@Autowired(required = false)
63+
SecurityConfigurerAdapter stormpathSecurityConfigurerAdapter;
64+
65+
@Autowired
66+
FilterChainProxy springSecurityFilterChain;
67+
68+
@Autowired(required = false)
69+
HeaderAuthenticator stormpathAuthorizationHeaderAuthenticator
70+
71+
@Autowired(required = false)
72+
Controller stormpathForgotPasswordController
73+
74+
//Spring Security Beans
75+
@Autowired(required = false)
76+
StormpathAuthenticationProvider stormpathAuthenticationProvider
77+
78+
@Autowired(required = false)
79+
GroupPermissionResolver stormpathGroupPermissionResolver
80+
81+
@Autowired(required = false)
82+
RequestEventListener stormpathRequestEventListener
83+
84+
@Autowired(required = false)
85+
CsrfTokenManager stormpathCsrfTokenManager
86+
87+
@Test
88+
void test() {
89+
assertNull client
90+
assertNull apiKey
91+
assertNull stormpathCacheManager
92+
assertNull stormpathFilter
93+
assertNull stormpathSecurityConfigurerAdapter
94+
assertNull application;
95+
assertTrue springSecurityFilterChain instanceof FilterChainProxy //let's assert Spring Security's Filter is present
96+
assertNull stormpathAuthenticationProvider
97+
assertNull stormpathGroupPermissionResolver
98+
assertNull stormpathRequestEventListener
99+
assertNull stormpathCsrfTokenManager
100+
assertNull stormpathAuthorizationHeaderAuthenticator
101+
assertNull stormpathForgotPasswordController
102+
}
103+
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2017 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package autoconfigure;
17+
18+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
19+
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.context.annotation.PropertySource;
21+
22+
/**
23+
* Disabling Spring Security must also disable Stormpath's Spring Security integration
24+
*
25+
* @since 1.3.2
26+
*/
27+
@Configuration
28+
@PropertySource({"classpath:disabledspringsecuritydisablesstormpathss.application.properties"})
29+
@EnableAutoConfiguration
30+
public class DisabledSpringSecurityDisablesStormpathSSAutoConfigurationTestApplication {
31+
32+
}
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2017 Stormpath, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package autoconfigure;
17+
18+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
19+
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.context.annotation.PropertySource;
21+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
22+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
23+
24+
/**
25+
* @since 1.3.2
26+
*/
27+
@Configuration
28+
@EnableAutoConfiguration
29+
@PropertySource({"classpath:disabledstormpath.application.properties"})
30+
public class DisabledStormpathAutoConfigurationTestApplication extends WebSecurityConfigurerAdapter {
31+
32+
@Override
33+
protected void configure(HttpSecurity http) throws Exception {
34+
}
35+
36+
}
37+

extensions/spring/boot/stormpath-spring-security-webmvc-spring-boot-starter/src/test/java/autoconfigure/StormpathWebSecurityAutoConfigurationTestApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020
import org.springframework.boot.SpringApplication;
21-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2221
import org.springframework.context.ApplicationContext;
2322
import org.springframework.context.annotation.Configuration;
2423

@@ -28,7 +27,6 @@
2827
* @since 1.0.RC5
2928
*/
3029
@Configuration
31-
@EnableAutoConfiguration
3230
public class StormpathWebSecurityAutoConfigurationTestApplication {
3331

3432
private static final Logger log = LoggerFactory.getLogger(StormpathWebSecurityAutoConfigurationTestApplication.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright 2017 Stormpath, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
security.basic.enabled = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright 2017 Stormpath, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
stormpath.enabled = false

0 commit comments

Comments
 (0)