Created
March 10, 2024 17:56
-
-
Save itzg/ca95a163fa9155c570bbeca773c922bf to your computer and use it in GitHub Desktop.
Spring Security register a custom PermissionEvaluator for @EnableMethodSecurity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; | |
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; | |
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; | |
@Configuration | |
@EnableMethodSecurity | |
public class SecurityConfig { | |
@Bean | |
MethodSecurityExpressionHandler handlerWithCustomPermissionEvaluator( | |
CustomPermissionEvaluator customPermissionEvaluator | |
) { | |
DefaultMethodSecurityExpressionHandler expressionHandler = new DefaultMethodSecurityExpressionHandler(); | |
expressionHandler.setPermissionEvaluator(customPermissionEvaluator); | |
return expressionHandler; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment