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

Commit 54d6793

Browse files
author
Mario
committed
1123 fixed ITs and added new ones
1 parent ed6f8ce commit 54d6793

File tree

7 files changed

+180
-4
lines changed

7 files changed

+180
-4
lines changed

extensions/spring/stormpath-spring-security-webmvc/src/main/java/com/stormpath/spring/config/StormpathWebSecurityDisabledConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package com.stormpath.spring.config;
1717

1818
import org.springframework.context.annotation.Bean;
19+
import org.springframework.context.annotation.Conditional;
1920
import org.springframework.context.annotation.Configuration;
20-
import org.springframework.core.annotation.Order;
2121
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
2222
import org.springframework.security.web.authentication.logout.LogoutHandler;
2323

@@ -26,7 +26,7 @@
2626
*/
2727
@SuppressWarnings("SpringFacetCodeInspection")
2828
@Configuration
29-
@Order(100) //Must come after StormpathWebSecurityConfiguration
29+
@Conditional(StormpathSpringSecurityDisabled.class)
3030
public class StormpathWebSecurityDisabledConfiguration extends AbstractStormpathWebSecurityDisabledConfiguration {
3131

3232
@Bean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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.config
17+
18+
import com.stormpath.sdk.api.ApiKey
19+
import com.stormpath.sdk.cache.CacheManager
20+
import org.slf4j.Logger
21+
import org.slf4j.LoggerFactory
22+
import org.springframework.beans.factory.annotation.Autowired
23+
import org.springframework.security.config.annotation.SecurityConfigurerAdapter
24+
import org.springframework.security.web.FilterChainProxy
25+
import org.springframework.test.context.ContextConfiguration
26+
import org.springframework.test.context.web.WebAppConfiguration
27+
import org.springframework.test.web.servlet.MockMvc
28+
import org.springframework.test.web.servlet.setup.MockMvcBuilders
29+
import org.springframework.web.context.WebApplicationContext
30+
import org.testng.annotations.BeforeClass
31+
import org.testng.annotations.Test
32+
33+
import javax.servlet.Filter
34+
import static org.testng.Assert.*
35+
36+
/**
37+
* @since 1.3.0
38+
*/
39+
@ContextConfiguration(classes = [DisabledStormpathSpringSecurityWebMvcTestAppConfig.class, TwoAppTenantStormpathTestConfiguration.class])
40+
@WebAppConfiguration
41+
class DisabledStormpathSpringSecurityWebMvcConfigurationIT extends AbstractClientIT {
42+
43+
private static final Logger log = LoggerFactory.getLogger(DisabledStormpathSpringSecurityWebMvcConfigurationIT)
44+
45+
@Autowired
46+
SecurityConfigurerAdapter stormpathSecurityConfigurerAdapter;
47+
48+
@Autowired
49+
ApiKey apiKey;
50+
51+
@Autowired
52+
CacheManager stormpathCacheManager;
53+
54+
@Autowired
55+
Filter stormpathFilter
56+
57+
@Autowired
58+
WebApplicationContext context;
59+
60+
@Autowired
61+
protected FilterChainProxy springSecurityFilterChain;
62+
63+
@Autowired
64+
protected Filter stormpathFilter;
65+
66+
private MockMvc mvc;
67+
68+
@BeforeClass
69+
public void setUp() {
70+
71+
super.setUp()
72+
73+
mvc = MockMvcBuilders.webAppContextSetup(context)
74+
.addFilter(springSecurityFilterChain, "/*") //Spring security in front of Stormpath
75+
.addFilter(stormpathFilter, "/*")
76+
.build();
77+
}
78+
79+
@Test
80+
void testRequiredBeans() {
81+
assertTrue stormpathSecurityConfigurerAdapter instanceof DisabledStormpathSecurityConfigurerAdapter //let's assert Stormpath's Spring Security integration is disabled
82+
assertNotNull apiKey
83+
assertNotNull stormpathCacheManager
84+
assertNotNull client
85+
assertNotNull application
86+
assertNotNull stormpathFilter
87+
}
88+
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.config;
17+
18+
import org.springframework.context.annotation.Configuration;
19+
import org.springframework.context.annotation.PropertySource;
20+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
21+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
22+
23+
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
24+
25+
/**
26+
* @since 1.0.RC5
27+
*/
28+
@Configuration
29+
@EnableStormpathWebSecurity
30+
@PropertySource({"classpath:com/stormpath/spring/config/disabledspringsecurity.application.properties"})
31+
public class DisabledStormpathSpringSecurityWebMvcTestAppConfig extends WebSecurityConfigurerAdapter {
32+
33+
@Override
34+
protected void configure(HttpSecurity http) throws Exception {
35+
http.apply(stormpath());
36+
}
37+
38+
}

extensions/spring/stormpath-spring-security-webmvc/src/test/groovy/com/stormpath/spring/config/MinimalStormpathSpringSecurityWebMvcConfigurationIT.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import org.springframework.security.authentication.AuthenticationEventPublisher
4343
import org.springframework.security.authentication.AuthenticationManager
4444
import org.springframework.security.authentication.ProviderManager
4545
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
46+
import org.springframework.security.config.annotation.SecurityConfigurerAdapter
4647
import org.springframework.security.core.Authentication
4748
import org.springframework.security.core.GrantedAuthority
4849
import org.springframework.security.core.context.SecurityContextHolder
@@ -76,7 +77,7 @@ class MinimalStormpathSpringSecurityWebMvcConfigurationIT extends AbstractClient
7677
private static final Logger log = LoggerFactory.getLogger(MinimalStormpathSpringSecurityWebMvcConfigurationIT)
7778

7879
@Autowired
79-
StormpathWebSecurityConfigurer c;
80+
SecurityConfigurerAdapter stormpathSecurityConfigurerAdapter;
8081

8182
@Autowired
8283
ApiKey apiKey;
@@ -141,6 +142,7 @@ class MinimalStormpathSpringSecurityWebMvcConfigurationIT extends AbstractClient
141142

142143
@Test
143144
void testRequiredBeans() {
145+
assertTrue stormpathSecurityConfigurerAdapter instanceof StormpathSecurityConfigurerAdapter //let's assert Stormpath's Spring Security integration is not disabled
144146
assertNotNull apiKey
145147
assertNotNull stormpathCacheManager
146148
assertNotNull client

extensions/spring/stormpath-spring-security-webmvc/src/test/java/com/stormpath/spring/config/MinimalStormpathSpringSecurityWebMvcTestAppConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
@Configuration
3333
@EnableStormpathWebSecurity
34-
public class MinimalStormpathSpringSecurityWebMvcTestAppConfig extends WebSecurityConfigurerAdapter {
34+
public class MinimalStormpathSpringSecurityWebMvcTestAppConfig extends WebSecurityConfigurerAdapter {
3535

3636
@Override
3737
protected void configure(HttpSecurity http) throws Exception {
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.spring.security.enabled = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.config;
17+
18+
import org.springframework.context.annotation.Condition;
19+
import org.springframework.context.annotation.ConditionContext;
20+
import org.springframework.core.type.AnnotatedTypeMetadata;
21+
22+
/**
23+
* @since 1.3.0
24+
*/
25+
public class StormpathSpringSecurityDisabled implements Condition {
26+
27+
@Override
28+
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
29+
return context.getEnvironment().getProperty("stormpath.spring.security.enabled", Boolean.class).equals(Boolean.FALSE);
30+
}
31+
}

0 commit comments

Comments
 (0)