Skip to content

Instantly share code, notes, and snippets.

@itzg
Created March 10, 2024 17:56
Show Gist options
  • Save itzg/ca95a163fa9155c570bbeca773c922bf to your computer and use it in GitHub Desktop.
Save itzg/ca95a163fa9155c570bbeca773c922bf to your computer and use it in GitHub Desktop.
Spring Security register a custom PermissionEvaluator for @EnableMethodSecurity
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