package com.test.demo2.config;
import com.test.demo2.realm.UserRealm;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.util.ThreadContext;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.LinkedHashMap;
@Configuration
public class ShiroConfig {
@Bean
public UserRealm getRealm(){
UserRealm userRealm = new UserRealm();
return userRealm;
}
@Bean
public DefaultWebSecurityManager securityManager(UserRealm userRealm)
{
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
// 设置realm.
securityManager.setRealm(userRealm);
ThreadContext.bind(securityManager);//加上这句代码手动绑定
// session管理器
//securityManager.setSessionManager(sessionManager());
// 记住我
//securityManager.setRememberMeManager(rememberMe ? rememberMeManager() : null);
// 缓存管理器;
//securityManager.setCacheManager(getEhCacheManager());
return securityManager;
}
@Bean
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager)
{
ShiroFilterFactoryBean filter=new ShiroFilterFactoryBean();
filter.setSecurityManager(securityManager);
//设置shiro的拦截规则
//anon 匿名用户可访问 authc 认证用户可访问
//user 使用RemeberMe的用户可访问 perms 对应权限可访问
//role 对应的角色可访问
LinkedHashMap<String,String> filterMap=new LinkedHashMap<>();
filterMap.put("/","anon");
filterMap.put("/login.html","anon");
filterMap.put("/login","anon");
filterMap.put("/static/**","anon");
filterMap.put("/**","authc");
filter.setFilterChainDefinitionMap(filterMap);
filter.setLoginUrl("/login.html");
//设置未授权页面跳转到登录页面
filter.setUnauthorizedUrl("/login.html");
return filter;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
demo2.rar (40个子文件)
demo2
HELP.md 862B
mvnw.cmd 7KB
pom.xml 3KB
src
test
java
com
test
demo2
Demo2ApplicationTests.java 214B
main
resources
mapper
UserMapper.xml 774B
application.properties 380B
templates
a
login.html 398B
index.html 137B
static
java
com
test
demo2
mapper
UserMapper.java 215B
controller
UserController.java 1KB
HelloController.java 408B
Demo2Application.java 430B
service
UserService.java 164B
impl
UserServiceImpl.java 556B
realm
UserRealm.java 1KB
domain
User.java 224B
config
ShiroConfig.java 2KB
.mvn
wrapper
maven-wrapper.properties 1019B
maven-wrapper.jar 59KB
.idea
jarRepositories.xml 2KB
workspace.xml 5KB
misc.xml 541B
compiler.xml 707B
.gitignore 184B
encodings.xml 191B
target
classes
mapper
UserMapper.xml 774B
application.properties 380B
templates
login.html 398B
index.html 137B
com
test
demo2
mapper
UserMapper.class 267B
controller
HelloController.class 800B
UserController.class 2KB
service
UserService.class 269B
impl
UserServiceImpl.class 947B
Demo2Application.class 848B
realm
UserRealm.class 2KB
domain
User.class 3KB
config
ShiroConfig.class 2KB
generated-sources
annotations
mvnw 10KB
.gitignore 395B
共 40 条
- 1
资源评论
jiajia佳佳
- 粉丝: 1143
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功