No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util....
spring boot shiroフレームワークを構築してエラーを報告する
コンフィギュレーションが間違っていて、shiroのコンフィギュレーションが次のように書かれている場合:
私は注釈を1つ漏らした. @Configuration ....
問題解決~
コンフィギュレーションが間違っていて、shiroのコンフィギュレーションが次のように書かれている場合:
public class ShiroConfiguration {
/**
* Shiro Web Factory :shiroFilter
*/
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//Shiro ,
shiroFilterFactoryBean.setSecurityManager(securityManager);
Map filterMap = new LinkedHashMap<>();
filterMap.put("authc", new AjaxPermissionsAuthorizationFilter());
shiroFilterFactoryBean.setFilters(filterMap);
/* shiro Map
* Map key(xml value ) '/' HttpServletRequest.getContextPath()
* anon: , , .do .jsp * , login.jsp?main
* authc: , Shiro org.apache.shiro.web.filter.authc.FormAuthenticationFilter
*/
Map filterChainDefinitionMap = new LinkedHashMap<>();
/* , , / ** : , ;
authc: url ; anon: url */
filterChainDefinitionMap.put("/", "anon");
filterChainDefinitionMap.put("/static/**", "anon");
filterChainDefinitionMap.put("/login/auth", "anon");
filterChainDefinitionMap.put("/login/logout", "anon");
filterChainDefinitionMap.put("/error", "anon");
filterChainDefinitionMap.put("/**", "authc");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
/**
* , bean
*/
@Bean(name = "securityManager")
public SecurityManager securityManager() {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(userRealm());
return securityManager;
}
/**
* Shiro Realm AuthorizingRealm Realm, Shiro
*/
@Bean
public UserRealm userRealm() {
UserRealm userRealm = new UserRealm();
return userRealm;
}
/**
*
* ( Shiro SimpleAuthenticationInfo
* doGetAuthenticationInfo ;
* )
* , ,
*/
@Bean(name = "credentialsMatcher")
public HashedCredentialsMatcher hashedCredentialsMatcher() {
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
// : MD5 ;
hashedCredentialsMatcher.setHashAlgorithmName("md5");
// , , md5(md5(""));
hashedCredentialsMatcher.setHashIterations(2);
//storedCredentialsHexEncoded true, Hex ;false Base64
hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);
return hashedCredentialsMatcher;
}
/**
* Shiro
*/
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
/**
* Shiro ( @RequiresRoles,@RequiresPermissions), SpringAOP Shiro ,
* bean(DefaultAdvisorAutoProxyCreator( ) AuthorizationAttributeSourceAdvisor)
*/
@Bean
@DependsOn({"lifecycleBeanPostProcessor"})
public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
advisorAutoProxyCreator.setProxyTargetClass(true);
return advisorAutoProxyCreator;
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor() {
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager());
return authorizationAttributeSourceAdvisor;
}
}
私は注釈を1つ漏らした. @Configuration ....
@Configuration
public class ShiroConfiguration {
問題解決~