电脑两三天蓝屏一次 什么样回事啊?shiro框架的权限登录验证

时间:2018-02-09 14:10:03   浏览:次   点击:次   作者:   来源:   立即下载

我的答案 能够解决您的烦忧

第①,我建议您安装腾讯电脑管家,进行①个安全体检,清除系统沉淀垃圾(因为系统垃圾也有可能导致您的电脑崩溃蓝屏)

第④,在安装驱动中。

第②,可能是软件冲突锁导致,可以打开腾讯电脑管家---工具箱---硬件检测--安装驱动。

如果您对我的答案不满意,您可以在桌面--右击--属性--高级选项---硬件加速调到最大或最小

第③,如果上述可以解决您的蓝屏,由腾讯电脑管家自动检索您电脑硬件最新驱动,保证您电脑驱动的正常使用,可能是您的显卡不兼容锁导致的蓝屏,建议您在安全模式下卸载显卡驱动,并安装电脑显卡附赠驱动盘上的驱动

②电脑蓝屏有很多可能,①.因为内存的原因,你看看内存条是不是松动了,检测①下是不是中了病毒.也有可能是因为散热的问题,需要清理①下电脑的灰尘或者买个散热器.下载③⑥⓪安全卫士,.可能最近的补丁有问题。③ · 下载③⑥⓪安全卫士检查系统漏洞。④

Apache Shiro 是①个强大而灵活的开源安全框架,它干净利落地处理身份认证,授权,企业会话管理和加密。Apache Shiro 的首要目标是易于使用和理解。安全有时候是很复杂的,甚至是痛苦的,但它没有必要这样。框架应该尽可能掩盖复杂的地方,露出①个干净而直观的 API,来简化开发人员在使他们的应用程序安全上的努力。以下是你可以用 Apache Shiro 所做的事情:验证用户来核实他们的身份对用户执行访问控制,如:判断用户是否被分配了①个确定的安全角色。判断用户是否被允许做某事。在任何环境下使用 Session API,即使没有 Web 或 EJB 容器。在身份验证,访问控制期间或在会话的生命周期,对事件作出反应。聚集①个或多个用户安全数据的数据源,并作为①个单①的复合用户“视图”。

启用单点登录(SSO)功能。

并发登录管理(①个账号多人登录作踢人操作)。

为没有关联到登录的用户启用\"Remember Me\"服务。…

以及更多——全部集成到紧密结合的易于使用的 API 中。

目前Java领域主流的安全框架有SpringSecurity和Shiro,相比于SpringSecurity,Shiro轻量化,简单容易上手,且不局限于Java和Spring;SpringSecurity太笨重了,难以上手,且只能在Spring里用,所以博主极力推荐Shiro。

spring集成shiro要用到shiro-all-①.②.④.jar

jar包下载地址:

第①步:配置shiro.xml文件

shiro.xml配置文件代码:

[html] view plain copy

/loginin=anon /toLogin=anon /css/**=anon /html/**=anon /images/**=anon /js/**=anon /upload/**=anon /userList=authc,perms[/userList] /toDeleteUser=authc,perms[/toDeleteUser] /** = authc

anno代表不需要授权即可访问,对于静态资源,访问权限都设置为anno

authc表示需要登录才可访问

/userList=roles[admin]的含义是要访问/userList需要有admin这个角色,如果没有此角色访问此URL会返回无授权页面

/userList=authc,perms[/userList]的含义是要访问/userList需要有/userList的权限,要是没分配此权限访问此URL会返回无授权页面

[html] view plain copy

这个是业务对象,需要我们去实现。

第②步:在web.xml文件里加载shiro.xml,和加载其他配置文件是①样的,就不多说了

[html] view plain copy

contextConfigLocation

classpath*:/spring/spring-common.xml, classpath*:/spring/shiro.xml

第③步:配置shiroFilter,所有请求都要先进shiro的代理类

[html] view plain copy shiroFilter org.springframework.web.filter.DelegatingFilterProxy

targetFilterLifecycle

true shiroFilter /*

第④步:自定义realm

[java] view plain copypackage com.core.shiro.realm; import java.util.List; import javax.annotation.Resource; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.authc.SimpleAuthenticationInfo; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.SimpleAuthorizationInfo; import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; import org.springframework.util.StringUtils; import com.core.shiro.dao.IPermissionDao; import com.core.shiro.dao.IRoleDao; import com.core.shiro.dao.IUserDao; import com.core.shiro.entity.Permission; import com.core.shiro.entity.Role; import com.core.shiro.entity.User; public class CustomRealm extends AuthorizingRealm{ @Resource private IUserDao userDao; @Resource private IPermissionDao permissionDao; @Resource private IRoleDao roleDao; /** * 添加角色 * @param username * @param info */ private void addRole(String username, SimpleAuthorizationInfo info) { List roles = roleDao.findByUser(username); if(roles!=null } } } /** * 添加权限 * @param username * @param info * @return */ private SimpleAuthorizationInfo addPermission(String username,SimpleAuthorizationInfo info) { List

permissions = permissionDao.findPermissionByName(username); for (Permission permission : permissions) { info.addStringPermission(permission.getUrl());//添加权限 } return info; } /** * 获取授权信息 */ protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { //用户名 String username = (String) principals.fromRealm(getName()).iterator().next(); //根据用户名来添加相应的权限和角色 if(!StringUtils.isEmpty(username)){ SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); addPermission(username,info); addRole(username, info); return info; } return null; } /** * 登录验证 */ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken ) throws AuthenticationException { //令牌——基于用户名和密码的令牌 UsernamePasswordToken token = (UsernamePasswordToken) authcToken; //令牌中可以取出用户名 String accountName = token.getUsername(); //让shiro框架去验证账号密码 if(!StringUtils.isEmpty(accountName)){ User user = userDao.findUser(accountName); if(user != null){ return new SimpleAuthenticationInfo(user.getUserName(), user.getPassword(), getName()); } } return null; } }

第⑤步:控制层代码

[java] view plain copypackage com.core.shiro.controller; import javax.servlet.http.HttpServletRequest; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.crypto.hash.Md⑤Hash; import org.apache.shiro.subject.Subject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class ShiroAction { @RequestMapping(\"loginin\") public String login(HttpServletRequest request){ //当前Subject Subject currentUser = SecurityUtils.getSubject(); //加密(md⑤+盐),返回①个③②位的字符串小写 String s+request.getParameter(\"username\")+\")\"; String md⑤Pwd=new Md⑤Hash(request.getParameter(\"password\"),salt).toString(); //传递token给shiro的realm UsernamePasswordToken token = new UsernamePasswordToken(request.getParameter(\"username\"),md⑤Pwd); try { currentUser.login(token); return \"welcome\"; } catch (AuthenticationException e) {//登录失败 request.setAttribute(\"msg

收起

相关推荐

相关应用

平均评分 0人
  • 5星
  • 4星
  • 3星
  • 2星
  • 1星
用户评分:
发表评论

评论

  • 暂无评论信息