package com.auth.module.security.config;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler;

@Configuration
// @EnableMethodSecurity(prePostEnabled = false)
public class AuthorizationManagerConfiguration {
    
    @Bean
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public MethodSecurityExpressionHandler methodSecurityExpressionHandler() {
        DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();
        // 可选配置---移除 ROLE_ 前缀
        // handler.setDefaultRolePrefix("");
        return handler;
    }

    // @Bean
    // @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    // Advisor preAuthorize(PreAuthorizationManager manager) {
    //     return AuthorizationManagerBeforeMethodInterceptor.preAuthorize(manager);
    // }
    //
    // @Bean
    // @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    // Advisor postAuthorize(PostAuthorizationManager manager) {
    //     return AuthorizationManagerAfterMethodInterceptor.postAuthorize(manager);
    // }

}
