shiro认证策略,授权
有具体问题的可以参考之前的关于shiro的博文,关于shiro的博文均是一次工程的内容 !
认证策略:

<!-- 认证器 -->
<bean id="autheniicator"
class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
<property name="realms">
<list>
<ref bean="jdbcRealm"/>
<ref bean="SecondRealm"/>
</list>
</property> <!-- 认证策略 -->
<property name="authenticationStrategy">
<bean class="org.apache.shiro.authc.pam.AllSuccessfulStrategy"></bean>
</property>
</bean>

授权:
授权之前的小说明:

此时的访问并没有问题:

注:在做授权的时候需要在securityManager 中读取realms
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="cacheManager"/>
<property name="authenticator" ref="autheniicator"></property> <property name="realms">
<list>
<ref bean="jdbcRealm"/>
<ref bean="SecondRealm"/>
</list>
</property>
</bean>






list.sjp页面中
<body>
list.
<br>
<a href="admin.jsp">TO Admin</a>
<br>
<a href="user.jsp">TO User</a>
<br>
<a href="shiro/logout">Logout</a>
</body>
applicationContext.jsp
<!--
配置那些页面需要受保护,以及访问这些页面需要的的权限
)anon 可以被匿名访问
)authc 必须认证即登陆后才可以访问的页面
).logout登出
4)roles 角色过滤器
-->
<property name="filterChainDefinitions">
<value>
/login.jsp = anon
/shiro/login = anon
/shiro/logout = logout /user.jsp = roles[user]
/admin.jsp = roles[admin] # everything else requires authentication:
/** = authc
</value>
</property>
此时点击访问user.jsp/admin.jsp的超链接都会去没有权限访问的页面
授权流程:
public abstract class AuthorizingRealm extends AuthenticatingRealm
implements Authorizer, Initializable, PermissionResolverAware, RolePermissionResolverAware
public class ShiroReamlTest extends AuthorizingRealm{
//授权
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// TODO Auto-generated method stub
return null;
}
//加密
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
// TODO Auto-generated method stub
return null;
}
}
授权需要继承的类以及实现的方法

实现:
public class ShiroRealm extends AuthorizingRealm {
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken arg0) throws AuthenticationException {
。。。。。。。
}
//授权
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
System.out.println(principals);
//1.PrincipalCollection获取登陆的用户信息
Object principal = principals.getPrimaryPrincipal();
System.out.println(principal);
//2.利用登陆的用户信息获取当前用户角色的权限
Set<String> roles = new HashSet<String>();
roles.add("user");
if("admin".equals(principal)){
roles.add("admin");
}
//3.创建SimpleAuthorizationInfo,并且设置其reles属性
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roles);
//4.
return info;
}
}

此时的设置之后 是可以成功访问的!
shiro认证策略,授权的更多相关文章
- 【shiro】(4)---Shiro认证、授权案例讲解
Shiro认证.授权案例讲解 一.认证 1. 认证流程 2.用户密码已经加密.加盐的用户认证 (1)测试类 // 用户登陆和退出,这里我自定了一个realm(开发肯定需要自定义realm获取 ...
- shiro认证和授权
一.shiro基础概念 Authentication:身份认证 / 登录,验证用户是不是拥有相应的身份: Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某个权限:即判断用户 ...
- shiro源码篇 - shiro认证与授权,你值得拥有
前言 开心一刻 我和儿子有个共同的心愿,出国旅游.昨天儿子考试得了全班第一,我跟媳妇合计着带他出国见见世面,吃晚饭的时候,一家人开始了讨论这个.我:“儿子,你的心愿是什么?”,儿子:“吃汉堡包”,我: ...
- shiro框架学习-2-springboot整合shiro及Shiro认证授权流程
1. 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- 在web项目中使用shiro(认证、授权)
一.在web项目中实现认证 第一步,在web项目中导入shiro依赖的包 第二步,在web.xml中声明shiro拦截权限的过滤器 <filter> <filter-name> ...
- shiro认证授权
一.shiro基础概念 Authentication:身份认证 / 登录,验证用户是不是拥有相应的身份: Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某个权限:即判断用户 ...
- 源码分析shiro认证授权流程
1. shiro介绍 Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能: 认证 - 用户身份识别,常被称为用户“登录”: 授权 - 访问控制: 密码加密 ...
- 用户登录安全框架shiro—用户的认证和授权(一)
ssm整合shiro框架,对用户的登录操作进行认证和授权,目的很纯粹就是为了增加系统的安全线,至少不要输在门槛上嘛. 这几天在公司独立开发一个供公司内部人员使用的小管理系统,客户不多但是登录一直都是 ...
- Shiro集成web环境[Springboot]-认证与授权
Shiro集成web环境[Springboot]--认证与授权 在登录页面提交登陆数据后,发起请求也被ShiroFilter拦截,状态码为302 <form action="${pag ...
随机推荐
- .Net Core GB2312编码问题
1.今天抓取了一个网页的源代码.发现中文是乱码的,马上第一反应是编码问题..... 2.仔细一看基于WebClient写的代码,还真的是没有设置编码... /// <summary> // ...
- 开源解决方案一:快速搭建单机版 LAMP 网站
LAMP 通常表示 Linux + Apache + MySQL/MariaDB + Perl/PHP/Python,LAMP 的各个组件不是一成不变的,并不局限于它最初的选择.作为一个解决方案套件, ...
- Java - 谨慎覆盖clone
覆盖clone时需要实现Cloneable接口,Cloneable并没有定义任何方法. 那Cloneable的意义是什么? 如果一个类实现了Clonable,Object的clone方法就可以返回该对 ...
- java 并发(六) --- 锁
阅读前阅读以下参考资料,文章图片或代码部分来自与参考资料 概览 一张图了解一下java锁. 注 : 阻塞将会切换线程,切换内核态和用户态,是比较大的性能开销 各种锁 为什么要设置锁的等级 ...
- CSS实现响应式布局(自动拆分几列)
1.css代码 <style type="text/css"> .container{ margin-top: 10px; } .outerDiv{ float:lef ...
- java 断点续传(springMvc),可支持html5 vedio在线播放 posted @ 2017年3月11日 16:15:44
Controller @RequestMapping(value = "/getVedio") public void getVedio(HttpServletRequest re ...
- 学习笔记2_Day09_servlet的细节
Servlet细节 l 不要在Servlet中创建成员!创建局部变量即可! l 可以创建无状态成员! l 可以创建有状态的成员,但状态必须为只读的! 1 Servlet与线程安全 因为一个类型的 ...
- elastic job 动态设置定时任务
1. 版本 <!-- import elastic-job lite core --> <dependency> <groupId>com.dangdang< ...
- Repeat Number(数论)
Repeat Number 题目描述: Definition: a+b = c, if all the digits of c are same ( c is more than ten), then ...
- Python爬虫教程-24-数据提取-BeautifulSoup4(二)
Python爬虫教程-24-数据提取-BeautifulSoup4(二) 本篇介绍 bs 如何遍历一个文档对象 遍历文档对象 contents:tag 的子节点以列表的方式输出 children:子节 ...