ShiroFilter配置中加入
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
return authorizationAttributeSourceAdvisor;
}
@Bean
@ConditionalOnMissingBean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
defaultAAP.setProxyTargetClass(true);
return defaultAAP;
}
/**
* 处理未授权的异常,返回自定义的错误页面(403)
* @return
*/
@Bean
public SimpleMappingExceptionResolver simpleMappingExceptionResolver() {
SimpleMappingExceptionResolver resolver = new SimpleMappingExceptionResolver();
Properties properties = new Properties();
/*未授权处理页*/
properties.setProperty("UnauthorizedException", "main/unauthorized");
resolver.setExceptionMappings(properties);
return resolver;
}
相関注解
@RequiresAuthentication
@RequiresUser
@RequiresGuest
@RequiresRoles("admin")
@RequiresRoles(value={"admin","sAdmin"},logical = Logical.OR)
@RequiresPermissions("user:query")
@RequiresPermissions(value={"add","update"},logical = Logical.AND)