Skip to content

Commit

Permalink
Fix Add @configuration to @enable*Security Usage
Browse files Browse the repository at this point in the history
Issue gh-6613
  • Loading branch information
rwinch committed Aug 9, 2022
1 parent 040111a commit a5069d7
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {

}

@Configuration
@EnableWebSecurity
static class GroupSearchConfig extends BaseLdapProviderConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* A minimal example can be found below:
*
* <pre class="code">
* &#064;Configuration
* &#064;EnableRSocketSecurity
* public class SecurityConfig {
* &#064;Bean
Expand Down Expand Up @@ -82,6 +83,7 @@
* A more advanced configuration can be seen below:
*
* <pre class="code">
* &#064;Configuration
* &#064;EnableRSocketSecurity
* public class SecurityConfig {
* &#064;Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;

Expand All @@ -39,7 +38,6 @@
@Documented
@Import(WebMvcSecurityConfiguration.class)
@EnableGlobalAuthentication
@Configuration
@Deprecated
public @interface EnableWebMvcSecurity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
* @author Rob Winch
*
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ Authz authz() {

}

@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public static class RoleHierarchyConfig {

@Bean
Expand Down Expand Up @@ -607,8 +607,8 @@ void emptyPrefixRoleUser() {

}

@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public static class CustomMetadataSourceBeanProxyEnabledConfig extends GlobalMethodSecurityConfiguration {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ protected AuthenticationManager authenticationManager() {

}

@EnableGlobalMethodSecurity(jsr250Enabled = true)
@Configuration
@EnableGlobalMethodSecurity(jsr250Enabled = true)
public static class Jsr250Config {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected void configure(HttpSecurity http) throws Exception {

}

@Configuration
@EnableWebSecurity
static class AnonymousDisabledInLambdaConfig extends WebSecurityConfigurerAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected void configure(HttpSecurity http) throws Exception {

}

@Configuration
@EnableWebSecurity
static class FormLoginCustomConfig extends WebSecurityConfigurerAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.SecurityContextChangedListenerConfig;
Expand Down Expand Up @@ -151,6 +152,7 @@ private <T extends Certificate> T loadCert(String location) {
}
}

@Configuration
@EnableWebSecurity
static class ObjectPostProcessorConfig extends WebSecurityConfigurerAdapter {

Expand Down Expand Up @@ -180,6 +182,7 @@ public <O> O postProcess(O object) {

}

@Configuration
@EnableWebSecurity
static class DuplicateDoesNotOverrideConfig extends WebSecurityConfigurerAdapter {

Expand All @@ -205,6 +208,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {

}

@Configuration
@EnableWebSecurity
static class DefaultsInLambdaConfig extends WebSecurityConfigurerAdapter {

Expand All @@ -227,6 +231,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {

}

@Configuration
@EnableWebSecurity
static class SubjectPrincipalRegexInLambdaConfig extends WebSecurityConfigurerAdapter {

Expand All @@ -252,6 +257,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {

}

@Configuration
@EnableWebSecurity
static class UserDetailsServiceBeanConfig {

Expand Down Expand Up @@ -279,6 +285,7 @@ UserDetailsService userDetailsService() {

}

@Configuration
@EnableWebSecurity
static class UserDetailsServiceAndBeanConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ class KotlinEnableReactiveMethodSecurityTests {
verify { delegate wasNot Called }
}

@EnableReactiveMethodSecurity
@Configuration
@EnableReactiveMethodSecurity
open class Config {
var delegate = mockk<KotlinReactiveMessageService>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.reactive.config.EnableWebFlux
import java.util.*
import java.util.Base64

/**
* Tests for [AuthorizeExchangeDsl]
Expand Down
23 changes: 23 additions & 0 deletions docs/modules/ROOT/pages/servlet/authorization/method-security.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

[[jc-method]]
= Method Security

Expand Down Expand Up @@ -32,6 +33,7 @@ For example, the following would enable Spring Security's `@PreAuthorize` annota
.Java
[source,java,role="primary"]
----
@Configuration
@EnableMethodSecurity
public class MethodSecurityConfig {
// ...
Expand All @@ -41,6 +43,7 @@ public class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableMethodSecurity
class MethodSecurityConfig {
// ...
Expand Down Expand Up @@ -98,6 +101,7 @@ You can enable support for Spring Security's `@Secured` annotation using:
.Java
[source,java,role="primary"]
----
@Configuration
@EnableMethodSecurity(securedEnabled = true)
public class MethodSecurityConfig {
// ...
Expand All @@ -107,6 +111,7 @@ public class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableMethodSecurity(securedEnabled = true)
class MethodSecurityConfig {
// ...
Expand All @@ -127,6 +132,7 @@ or JSR-250 using:
.Java
[source,java,role="primary"]
----
@Configuration
@EnableMethodSecurity(jsr250Enabled = true)
public class MethodSecurityConfig {
// ...
Expand All @@ -136,6 +142,7 @@ public class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableMethodSecurity(jsr250Enabled = true)
class MethodSecurityConfig {
// ...
Expand Down Expand Up @@ -264,6 +271,7 @@ To recreate what adding `@EnableMethodSecurity` does by default, you would publi
.Java
[source,java,role="primary"]
----
@Configuration
@EnableMethodSecurity(prePostEnabled = false)
class MethodSecurityConfig {
@Bean
Expand Down Expand Up @@ -295,6 +303,7 @@ class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableMethodSecurity(prePostEnabled = false)
class MethodSecurityConfig {
@Bean
Expand Down Expand Up @@ -392,6 +401,7 @@ You may want to only support `@PreAuthorize` in your application, in which case
.Java
[source,java,role="primary"]
----
@Configuration
@EnableMethodSecurity(prePostEnabled = false)
class MethodSecurityConfig {
@Bean
Expand All @@ -405,6 +415,7 @@ class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableMethodSecurity(prePostEnabled = false)
class MethodSecurityConfig {
@Bean
Expand Down Expand Up @@ -440,6 +451,7 @@ Thus, you can configure Spring Security to invoke your `AuthorizationManager` in
.Java
[source,java,role="primary"]
----
@Configuration
@EnableMethodSecurity
class MethodSecurityConfig {
@Bean
Expand All @@ -458,6 +470,7 @@ class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableMethodSecurity
class MethodSecurityConfig {
@Bean
Expand Down Expand Up @@ -542,6 +555,7 @@ For example, if you have your own custom annotation, you can configure it like s
.Java
[source,java,role="primary"]
----
@Configuration
@EnableMethodSecurity
class MethodSecurityConfig {
@Bean
Expand All @@ -558,6 +572,7 @@ class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableMethodSecurity
class MethodSecurityConfig {
@Bean
Expand Down Expand Up @@ -607,6 +622,7 @@ The following example enables Spring Security's `@Secured` annotation:
.Java
[source,java,role="primary"]
----
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class MethodSecurityConfig {
// ...
Expand All @@ -616,6 +632,7 @@ public class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
open class MethodSecurityConfig {
// ...
Expand Down Expand Up @@ -666,6 +683,7 @@ Support for JSR-250 annotations can be enabled by using:
.Java
[source,java,role="primary"]
----
@Configuration
@EnableGlobalMethodSecurity(jsr250Enabled = true)
public class MethodSecurityConfig {
// ...
Expand All @@ -675,6 +693,7 @@ public class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableGlobalMethodSecurity(jsr250Enabled = true)
open class MethodSecurityConfig {
// ...
Expand All @@ -689,6 +708,7 @@ To use the new expression-based syntax, you would use:
.Java
[source,java,role="primary"]
----
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig {
// ...
Expand All @@ -698,6 +718,7 @@ public class MethodSecurityConfig {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
open class MethodSecurityConfig {
// ...
Expand Down Expand Up @@ -750,6 +771,7 @@ For example, if you wanted to provide a custom `MethodSecurityExpressionHandler`
.Java
[source,java,role="primary"]
----
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Override
Expand All @@ -763,6 +785,7 @@ public class MethodSecurityConfig extends GlobalMethodSecurityConfiguration {
.Kotlin
[source,kotlin,role="secondary"]
----
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
open class MethodSecurityConfig : GlobalMethodSecurityConfiguration() {
override fun createExpressionHandler(): MethodSecurityExpressionHandler {
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/servlet/configuration/java.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ You can also explicit disable the default:
====
[source,java]
----
@Configuration
@EnableWebSecurity
public class Config {
@Bean
Expand Down
Loading

0 comments on commit a5069d7

Please sign in to comment.