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

Commit a01b460

Browse files
authored
Merge pull request #1215 from stormpath/1123_spring_security_4.2.0_remove_apply
1123 spring security 4.2.0 remove apply
2 parents 9cf48e3 + 96882e0 commit a01b460

File tree

36 files changed

+957
-390
lines changed

36 files changed

+957
-390
lines changed

docs/source/quickstart.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,29 +123,24 @@ Spring Security
123123
^^^^^^^^^^^^^^^
124124

125125
The |project| assumes Spring Security will be used to secure your ${apptype} by default. To ensure this
126-
works correctly, you will need a Spring Security configuration class and apply the ``stormpath()`` hook:
126+
works correctly, you will need a Spring Security configuration class:
127127

128128
.. code-block:: java
129129
:emphasize-lines: 7
130130
131-
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
132-
133131
@Configuration
134132
public class SpringSecurityWebAppConfig extends WebSecurityConfigurerAdapter {
135133
@Override
136134
protected void configure(HttpSecurity http) throws Exception {
137-
http.apply(stormpath());
138135
}
139136
}
140137
141-
Without this, you will see a browser popup prompting for authentication, which is the default basic authentication behavior for Spring Security.
142-
143-
Also, by default, all paths are locked down with Spring Security. Stormpath's Spring Security integration follows this idiomatic behavior.
138+
By default, all paths are locked down with Spring Security. Stormpath's Spring Security integration follows this idiomatic behavior.
144139

145140
Disabling Spring Security
146141
"""""""""""""""""""""""""
147142

148-
If you do not want to use Spring Security, do not add the ``SpringSecurityWebAppConfig`` class shown above (or just comment out the ``http.apply(stormpath())`` line if you do not want to remove the class). Also set the following two config properties:
143+
If you do not want to use our Spring Security integration, set the following two config properties:
149144

150145
.. code-block:: yaml
151146

docs/source/tutorial.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,18 @@
211211
:linenos:
212212
:emphasize-lines: 8
213213
214-
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
215-
216214
@Configuration
217215
public class SpringSecurityWebAppConfig extends WebSecurityConfigurerAdapter {
218216
@Override
219217
protected void doConfigure(HttpSecurity http) throws Exception {
220218
http
221-
.apply(stormpath()).and()
222219
.authorizeRequests()
223220
.antMatchers("/").permitAll();
224221
}
225222
}
226223
227-
Why have this configuration? Spring Security expects things to be, well - secured. If there is not a class that extends
228-
``WebSecurityConfigurerAdapter`` in the application, Spring Security will protect *every* pathway and will provide a default
229-
basic authentication popup to your browser. In order to easily hook into the Stormpath Spring Security integration, simply
230-
``apply`` stormpath! The call to ``stormpath()`` sets up all of the default views and hooks the Stormpath ``AuthenticationManager``
224+
In order to easily hook into the Stormpath Spring Security integration, simply add a ``WebSecurityConfigurerAdapter`` in the application.
225+
Doing that just sets up all of the default views and hooks the Stormpath ``AuthenticationManager``
231226
into your application.
232227
233228
Based on the ``SpringSecurityWebAppConfig`` above, we will permit access to the homepage. Any other paths will fall back

examples/spring-boot-default/src/main/java/com/stormpath/spring/boot/examples/SpringSecurityWebAppConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2020
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
2121

22-
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
23-
2422
/**
2523
* @since 1.0.RC6
2624
*/
@@ -34,8 +32,9 @@ public class SpringSecurityWebAppConfig extends WebSecurityConfigurerAdapter {
3432
protected void configure(HttpSecurity http) throws Exception {
3533
// Access to all paths is restricted by default.
3634
// We want to restrict access to one path and leave all other paths open.
35+
// Starting with Spring Security 4.2 we do not need to explicitly apply the Stormpath configuration in Spring Boot
36+
// any more (note that it is still required in regular Spring)
3737
http
38-
.apply(stormpath()).and()
3938
.authorizeRequests()
4039
.antMatchers("/restricted").fullyAuthenticated()
4140
.antMatchers("/**").permitAll();

examples/spring-security-spring-boot-webmvc-bare-bones/src/main/java/com/stormpath/spring/boot/examples/SpringSecurityWebAppConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2020
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
2121

22-
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
23-
2422
/**
2523
* @since 1.0.RC8.1
2624
*/
@@ -32,6 +30,7 @@ public class SpringSecurityWebAppConfig extends WebSecurityConfigurerAdapter {
3230
*/
3331
@Override
3432
protected void configure(HttpSecurity http) throws Exception {
35-
http.apply(stormpath());
33+
// Starting with Spring Security 4.2 we do not need to explicitly apply the Stormpath configuration in Spring Boot
34+
// any more (note that it is still required in regular Spring)
3635
}
3736
}

examples/spring-security-spring-boot-webmvc/src/main/java/com/stormpath/spring/boot/examples/SpringSecurityWebAppConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2020
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
2121

22-
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
23-
2422
/**
2523
* @since 1.0.RC6
2624
*/
@@ -32,8 +30,9 @@ public class SpringSecurityWebAppConfig extends WebSecurityConfigurerAdapter {
3230
*/
3331
@Override
3432
protected void configure(HttpSecurity http) throws Exception {
33+
// Starting with Spring Security 4.2 we do not need to explicitly apply the Stormpath configuration in Spring Boot
34+
// any more (note that it is still required in regular Spring)
3535
http
36-
.apply(stormpath()).and()
3736
.authorizeRequests()
3837
.antMatchers("/restricted").fullyAuthenticated()
3938
.antMatchers("/**").permitAll();

examples/spring-security-webmvc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<servlet.version>3.1.0</servlet.version>
4141
<slf4j.version>1.7.21</slf4j.version>
4242
<spring.version>4.3.2.RELEASE</spring.version>
43-
<spring.security.version>4.1.2.RELEASE</spring.security.version>
43+
<spring.security.version>4.2.0.RELEASE</spring.security.version>
4444
<tomcat.version>8.5.9</tomcat.version>
4545
</properties>
4646

examples/spring-security-webmvc/src/main/java/com/stormpath/spring/examples/SpringSecurityWebAppConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public boolean handle(HttpServletRequest request, HttpServletResponse response,
9393
protected void configure(HttpSecurity http) throws Exception {
9494

9595
http
96-
.apply(stormpath()).and()
96+
.apply(stormpath()).and() // Starting with Spring Security 4.2 we do not need to explicitly apply the Stormpath configuration in Spring Boot but it is still required in Spring
9797
.authorizeRequests()
9898
.antMatchers("/restricted").fullyAuthenticated()
9999
.antMatchers("/**").permitAll();

examples/zuul-spring-cloud-starter/src/main/java/com/stormpath/spring/cloud/examples/SecurityConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
2020
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
2121

22-
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.*;
23-
2422
@Configuration
2523
public class SecurityConfig extends WebSecurityConfigurerAdapter {
2624

2725
@Override
2826
protected void configure(HttpSecurity http) throws Exception {
29-
http.apply(stormpath()).and()
27+
http
3028
.authorizeRequests().antMatchers("/").permitAll();
3129
}
3230
}

extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/application/ApplicationIT.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,9 @@ class ApplicationIT extends ClientIT {
681681
} catch (com.stormpath.sdk.resource.ResourceException e) {
682682
assertEquals(e.getStatus(), 400)
683683
assertEquals(e.getCode(), 7200)
684-
assertTrue(e.getDeveloperMessage().contains("Stormpath was not able to complete the request to"))
685-
assertTrue(e.getDeveloperMessage().contains("Google") || e.getDeveloperMessage().contains("google"))
684+
//asserting this error message has caused problems, we are just reducing it to be sure that the error message
685+
//refers to a google directory
686+
assertTrue(e.getDeveloperMessage().toUpperCase().contains("GOOGLE"))
686687
}
687688
}
688689

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.stormpath.sdk.servlet.filter.account.AccountResolverFilter;
2222
import com.stormpath.sdk.servlet.mvc.ErrorModelFactory;
2323
import com.stormpath.spring.config.AbstractStormpathWebSecurityConfiguration;
24-
import com.stormpath.spring.config.StormpathWebSecurityConfigurer;
2524
import com.stormpath.spring.filter.ContentNegotiationSpringSecurityAuthenticationFilter;
2625
import com.stormpath.spring.filter.StormpathSecurityContextPersistenceFilter;
2726
import com.stormpath.spring.filter.StormpathWrapperFilter;
@@ -34,6 +33,7 @@
3433
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
3534
import org.springframework.context.annotation.Bean;
3635
import org.springframework.context.annotation.Configuration;
36+
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
3737
import org.springframework.security.web.AuthenticationEntryPoint;
3838
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
3939
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
@@ -72,9 +72,10 @@ public AuthenticationFailureHandler stormpathAuthenticationFailureHandler() {
7272
}
7373

7474
@Bean
75-
@ConditionalOnMissingBean(name="stormpathWebSecurityConfigurer")
76-
public StormpathWebSecurityConfigurer stormpathWebSecurityConfigurer() {
77-
return super.stormpathWebSecurityConfigurer();
75+
@Override
76+
@ConditionalOnMissingBean(name="stormpathSecurityConfigurerAdapter")
77+
public SecurityConfigurerAdapter stormpathSecurityConfigurerAdapter() {
78+
return super.stormpathSecurityConfigurerAdapter();
7879
}
7980

8081
@Bean

0 commit comments

Comments
 (0)