package com.hello.config;

import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.apache.shiro.mgt.SessionsSecurityManager;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ShiroConfig {
    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition() {
        DefaultShiroFilterChainDefinition chain = new DefaultShiroFilterChainDefinition();

        // logged in users with the 'admin' role
        chain.addPathDefinition("/admin/**", "authc, roles[admin]");

        // all other paths require a logged in user
        chain.addPathDefinition("/**", "authc");
        return chain;
    }

    @Bean
    public SessionsSecurityManager securityManager() {
        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
        securityManager.setRealm(userRealm());
        return securityManager;
    }

    @Bean
    public Realm userRealm() {
        UserRealm userRealm = new UserRealm();
        userRealm.setCredentialsMatcher(credentialsMatcher());
        return userRealm;
    }

    @Bean
    public HashedCredentialsMatcher credentialsMatcher() {
        HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
        credentialsMatcher.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);
        credentialsMatcher.setStoredCredentialsHexEncoded(false);
        credentialsMatcher.setHashIterations(1024);
        return credentialsMatcher;
    }
}

@@ -423,32 +423,115 @@
 ecurityManager;%0A
+import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;%0A
 import org.sprin
@@ -1899,11 +1899,448 @@
 r;%0A    %7D
+%0A%0A    /**%0A     * %E5%9C%A8%E5%BC%95%E5%85%A5spring aop%E7%9A%84%E6%83%85%E5%86%B5%E4%B8%8B%EF%BC%8C%E5%9C%A8%E6%96%B9%E6%B3%95%E4%B8%AD%E5%8A%A0%E5%85%A5@RequiresRole%E7%AD%89shiro%E6%B3%A8%E8%A7%A3%E6%97%B6%EF%BC%8C%E4%BC%9A%E5%AF%BC%E8%87%B4%E8%AF%A5%E6%96%B9%E6%B3%95%E6%97%A0%E6%B3%95%E6%98%A0%E5%B0%84%E8%AF%B7%E6%B1%82%E3%80%82%0A     * %E5%8A%A0%E5%85%A5setUsePrefix(true)%E8%A7%A3%E5%86%B3%E8%BF%99%E4%B8%AAbug%E3%80%82%0A     */%0A    @Bean%0A    public static DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator()%7B%0A        DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator=new DefaultAdvisorAutoProxyCreator();%0A        defaultAdvisorAutoProxyCreator.setUsePrefix(true);%0A        return defaultAdvisorAutoProxyCreator;%0A    %7D
 %0A%7D%0A

fix bug when aop and shiro conflicts