当前位置: 首页 > news >正文

汕头seo课程培训重庆seo技术教程博客

汕头seo课程培训,重庆seo技术教程博客,威海公司注册,wordpress ai-pic主题一、权限基础 a) 认证(你是谁?) 判断你(被认证者)是谁的过程。通常被认证者提供用户名和密码。 常见的认证包含如下几种: 匿名认证:允许访问资源,不做任何类型的安全检查。表单认证:访问资源之前,需要提…

 一、权限基础

a) 认证(你是谁?)

判断你(被认证者)是谁的过程。通常被认证者提供用户名和密码。

常见的认证包含如下几种:

  • 匿名认证:允许访问资源,不做任何类型的安全检查。
  • 表单认证:访问资源之前,需要提交包含用户名和密码的表单。这是web application最常用的认证方式。这个过程一般会接合Session,只在第一次(新会话)访问资源时提交认证表单。
  • 基本HTTP认证:基于RFC 2617的一种认证方式。
  • 用户认证:Filter that allows access to resources if the accessor is a known user, which is defined as having a known principal. This means that any user who is authenticated or remembered via a 'remember me' feature will be allowed access from this filter.

b)  授权(你可以做什么?)

判断被认证者(你)是否能做什么操作的过程。

  • 端口授权:必须通过指定的某个端口才能访问资源。
  • Permission授权:Filter that allows access if the current user has the permissions specified by the mapped value, or denies access if the user does not have all of the permissions specified.
  • Role授权:Filter that allows access if the current user has the roles specified by the mapped value, or denies access if the user does not have all of the roles specified.

perms     org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
port     org.apache.shiro.web.filter.authz.PortFilter
roles     org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
ssl     org.apache.shiro.web.filter.authz.SslFilter

c)  加密

使用技术手段(如:MD5、SHA等)把待加密的数据变为密文(如:信息摘要等)过程。

d)  RBAC

基于角色的访问控制(Role-Based Access Control)。

e) Realm

data access object for an application’s security components (users,roles, permissions)

f)  Permission

最小粒度的授权,不与用户关联。
例如:导出报表、查看id号为“PO20090008”的采购单、创建FAQ。

g) Role

Permission的集合。

二、Shiro特点

  • 简单。
  • 功能强大。
  • 能独立运行,不依赖其它框架或容器。
  • 包含了认证、授权、Session管理、加密。
  • 易于扩展。

三、web application 集成Shiro

a)  数据模型

用户账号Account,可以简单的理解为用户。
一个账号可以拥有多个角色(Role)。
一个角色包含了多个权限(Permission)。

b)  创建工程,新建实体,添加与Shiro相关的Jar包

Eclipse:File--New--Other--Web--Dynamic Web Project

在 /WEB-INFO/lib/目录下添加如下Jar包

相关Jar包,http://incubator.apache.org/shiro/download.html

c)  配置web.xml,添加过滤器

<filter><filter-name>ShiroFilter</filter-name><filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
</filter>
<filter-mapping><filter-name>ShiroFilter</filter-name><url-pattern>/*</url-pattern>
</filter-mapping>

d)  INI配置

[main]
#SHA256加密
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher#realm
myRealm = com.xx.xx.shiro.MyShiroRealm
myRealm.credentialsMatcher = $sha256Matcher#缓存
myRealm.authorizationCachingEnabled = true
cache=org.apache.shiro.cache.ehcache.EhCacheManager
myRealm.cacheManager=$cache[filters]
shiro.loginUrl = /login.jsp
#authc=org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authc.successUrl =/background.jsp
perms.unauthorizedUrl =/401.jsp[urls]
/login.jsp=authc
/logout.jsp=anon
/about.jsp=anon
/background.jsp=authc/faq/test.jsp=authc
/faq/list.jsp=authc,perms["faq:list"]
/faq/view.jsp=authc,perms["faq:view"]

位置:
配置参数可以写在web.xml文件中,也可以单独文件形式存放在本地类根路径、文件系统以及网络环境中。
Shiro INI Inline Config 和External Config

public class MyShiroRealm extends AuthorizingRealm {protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {String username = (String) principals.fromRealm(getName()).iterator().next();if( username != null ){AccountManager accountManager = new AccountManagerImpl();Collection<Role> myRoles = accountManager.getRoles( username );if( myRoles != null ){SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();for( Role each:myRoles ){info.addRole(each.getName());info.addStringPermissions( each.getPermissionsAsString() );}return info;}}return null;}protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken ) throws AuthenticationException {UsernamePasswordToken token = (UsernamePasswordToken) authcToken;String accountName = token.getUsername();//用户名密码验证if( accountName != null && !"".equals(accountName) ){AccountManager accountManager = new AccountManagerImpl();Account account = accountManager.get( token.getUsername() );if( account != null )return new SimpleAuthenticationInfo(account.getName(),account.getPassword(), getName() );}return null;}
}

f)   登录页面

 <%Object obj = request.getAttribute(org.apache.shiro.web.filter.authc.
FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);boolean flag = false;String msg = "";                   if( obj != null ){if( "org.apache.shiro.authc.UnknownAccountException".equals( obj ) )msg = "未知帐号错误!";else if("org.apache.shiro.authc.IncorrectCredentialsException".equals( obj ))msg = "密码错误!";                   else if( "org.apache.shiro.authc.AuthenticationException".equals( obj ))msg = "认证失败!";flag = !"".equals(msg);}           if( flag )out.print( msg );
%><form action="login.jsp" method="post"><br/>用户帐号:<input type="text"  name="username" id="username" value=""/><br/>登录密码:<input type="password" name="password" id="password" value="" />                            <br/><input value="登录" type="submit" >
</form>

g)  登出页面

<%SecurityUtils.getSubject().logout();%>

四、在Shiro中实现CAPTCHA(验证码)功能

a)  验证码表单认证过滤器

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.apache.shiro.web.util.WebUtils;public class CaptchaFormAuthenticationFilter extends FormAuthenticationFilter{public static final String DEFAULT_CAPTCHA_PARAM = "captcha";private String captchaParam = DEFAULT_CAPTCHA_PARAM;public String getCaptchaParam() {return captchaParam;}protected String getCaptcha(ServletRequest request) {return WebUtils.getCleanParam(request, getCaptchaParam());}protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {String username = getUsername(request);String password = getPassword(request);String captcha = getCaptcha(request);boolean rememberMe = isRememberMe(request);String host = getHost(request);       return new CaptchaUsernamePasswordToken(username, password, rememberMe, host,captcha);}
}

b)  用户名密码令牌UsernamePasswordToken

import org.apache.shiro.authc.UsernamePasswordToken;public classCaptchaUsernamePasswordToken extends UsernamePasswordToken {private static final long serialVersionUID = 1L;private String captcha;public String getCaptcha() {return captcha;} public void setCaptcha(String captcha) {this.captcha = captcha;}public CaptchaUsernamePasswordToken() {super();}public CaptchaUsernamePasswordToken(String username, char[] password,boolean rememberMe, String host,String captcha) {        super(username, password, rememberMe, host);this.captcha = captcha;}
}

c)  添加AuthenticationException

public classIncorrectCaptchaException extends AuthenticationException{private static final long serialVersionUID = 1L;public IncorrectCaptchaException() {super();}public IncorrectCaptchaException(String message, Throwable cause) {super(message, cause);}public IncorrectCaptchaException(String message) {super(message);}public IncorrectCaptchaException(Throwable cause) {super(cause);}
}

d)  Shiro INI文件

authc= com.xx.xx.shiro.CaptchaFormAuthenticationFilter

e)  实现Realm

 protectedAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken ) throwsAuthenticationException {CaptchaUsernamePasswordToken token = (CaptchaUsernamePasswordToken) authcToken;String accountName = token.getUsername();//验证码 验证String captcha = null;Object obj_captcha = SecurityUtils.getSubject().getSession().getAttribute( SessionKey.CAPTCHA );Object obj_count = SecurityUtils.getSubject().getSession().getAttribute( SessionKey.LOGIN_FAILED_COUNT );int failed_count = (obj_count == null || !(obj_count instanceof Integer))?0:(Integer)obj_count;if( obj_captcha instanceof String)captcha = (String)obj_captcha;if( captcha != null && failed_count >0&& !captcha.equalsIgnoreCase( token.getCaptcha() )){throw newIncorrectCaptchaException("验证码错误!");}//用户名密码验证if( accountName != null && !"".equals(accountName) ){AccountManager accountManager = newAccountManagerImpl();Account account = accountManager.get( token.getUsername() );if( account != null )return new SimpleAuthenticationInfo( account.getName(),account.getPassword(), getName() );}return null;}
}

f)   登录页面

<% Object obj = request.getAttribute(org.apache.shiro.web.filter.authc.
FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);boolean flag = false;String msg = "";                        if( obj != null ){if( "org.apache.shiro.authc.UnknownAccountException".equals( obj ) )msg = "未知帐号错误!";else if("org.apache.shiro.authc.IncorrectCredentialsException".equals( obj ))msg = "密码错误!";else if("com.xx.xx.shiro.IncorrectCaptchaException".equals( obj ))msg = "验证码错误!";else if( "org.apache.shiro.authc.AuthenticationException".equals( obj ))msg = "认证失败!";flag = !"".equals(msg);}if( flag ){out.print( msg );Integer count = (Integer)request.getSession().getAttribute(SessionKey.LOGIN_FAILED_COUNT );if( count == null )count = Integer.valueOf(0);count++;request.getSession().setAttribute(SessionKey.LOGIN_FAILED_COUNT, count);}                   
%><form action="login.jsp" method="post"><br/>用户帐号:<input type="text"  name="username" id="username" value=""/><br/>登录密码:<input type="password" name="password" id="password" value="" />         <br/>验证码:<input type="text" name="captcha" id="captcha" size="6"/><img src="/captcha" alt="captcha" /><br/><input value="登录" type="submit" >
</form>

g)  CAPTCHA实现

h)      

五、代码的开发环境

JAVA1.6

Tomcat

Eclipse


文章转载自:
http://wanjiaaspish.wqpr.cn
http://wanjiacolchicine.wqpr.cn
http://wanjiasnollygoster.wqpr.cn
http://wanjiatelautogram.wqpr.cn
http://wanjiasesquialtera.wqpr.cn
http://wanjiaclouet.wqpr.cn
http://wanjiaunforced.wqpr.cn
http://wanjiapillage.wqpr.cn
http://wanjiaafterbeat.wqpr.cn
http://wanjiasulky.wqpr.cn
http://wanjiasashless.wqpr.cn
http://wanjiachinchona.wqpr.cn
http://wanjiatoyama.wqpr.cn
http://wanjiaimpalpably.wqpr.cn
http://wanjiapharmacology.wqpr.cn
http://wanjiacruiseway.wqpr.cn
http://wanjianekoite.wqpr.cn
http://wanjianoncontinuous.wqpr.cn
http://wanjiasubindex.wqpr.cn
http://wanjiapseudoplastic.wqpr.cn
http://wanjiabatholith.wqpr.cn
http://wanjiafree.wqpr.cn
http://wanjiamarl.wqpr.cn
http://wanjiaelectrosynthesis.wqpr.cn
http://wanjiascampish.wqpr.cn
http://wanjiayokkaichi.wqpr.cn
http://wanjiaadorable.wqpr.cn
http://wanjialazyish.wqpr.cn
http://wanjiaertebolle.wqpr.cn
http://wanjiaflamboyance.wqpr.cn
http://wanjiahypnogenesis.wqpr.cn
http://wanjiahypnus.wqpr.cn
http://wanjiadispraise.wqpr.cn
http://wanjiacastroism.wqpr.cn
http://wanjiasemplice.wqpr.cn
http://wanjiaelectrofishing.wqpr.cn
http://wanjialaminable.wqpr.cn
http://wanjiauniversalize.wqpr.cn
http://wanjiarevegetation.wqpr.cn
http://wanjiaaurorean.wqpr.cn
http://wanjiatenorrhaphy.wqpr.cn
http://wanjiadispersible.wqpr.cn
http://wanjiaperfin.wqpr.cn
http://wanjiadepend.wqpr.cn
http://wanjianotabilia.wqpr.cn
http://wanjiabiotechnics.wqpr.cn
http://wanjiaamputator.wqpr.cn
http://wanjiautah.wqpr.cn
http://wanjiapolycletus.wqpr.cn
http://wanjiamitbestimmung.wqpr.cn
http://wanjiaoncer.wqpr.cn
http://wanjialycian.wqpr.cn
http://wanjiaaerotropism.wqpr.cn
http://wanjiaphotoshp.wqpr.cn
http://wanjiamonticulous.wqpr.cn
http://wanjiacyaneous.wqpr.cn
http://wanjialaurustine.wqpr.cn
http://wanjiasasin.wqpr.cn
http://wanjianib.wqpr.cn
http://wanjialaevulin.wqpr.cn
http://wanjiaprc.wqpr.cn
http://wanjiadecane.wqpr.cn
http://wanjiacompensability.wqpr.cn
http://wanjiaopprobrious.wqpr.cn
http://wanjialymphocytotic.wqpr.cn
http://wanjiawordiness.wqpr.cn
http://wanjiasalzgitter.wqpr.cn
http://wanjiamaidenlike.wqpr.cn
http://wanjianecrophobia.wqpr.cn
http://wanjiafrugal.wqpr.cn
http://wanjiagrovel.wqpr.cn
http://wanjialevelman.wqpr.cn
http://wanjiahyperexcitability.wqpr.cn
http://wanjiaschumpeterian.wqpr.cn
http://wanjiaebony.wqpr.cn
http://wanjiapanhellenism.wqpr.cn
http://wanjiapromycelium.wqpr.cn
http://wanjiaunabbreviated.wqpr.cn
http://wanjiademolishment.wqpr.cn
http://wanjiafibroadenoma.wqpr.cn
http://www.15wanjia.com/news/117778.html

相关文章:

  • 中国在数码网站注册域名好>优化网哪个牌子好
  • 网页网站导读怎么做软文是什么样子的
  • 扬中seo搜索引擎优化案例分析
  • 那些做测评的网站好电脑零基础培训班
  • 企业网站设计公司盐城seo优化
  • aspnet网站开发实战网站建设制作专业
  • 企业做网站报价网络销售怎么学
  • 网站不同浏览器css优化网站seo公司
  • t型布局网站实例百度小说搜索风云榜排名
  • 建设工程合同在性质上属于seo兼职外包
  • 广州网站建设哪家好网页推广怎么收取费用
  • 中国营销协会官网焦作seo推广
  • 国内网站建设公司top20新手做外贸怎么入门
  • app模板素材下载韶关网站seo
  • 外贸网站seo有哪些公司上海网站排名seo公司
  • 网站的记住密码功能怎么做如何制作百度网页
  • 给公司做的东西放到自己网站上网站权重怎么查
  • 山东网站备案公司免费com域名申请注册
  • 成都网络优化网站seo优化软件
  • 廊坊网站建设推广服务nba哈登最新消息
  • 电脑本地网站建设百度云搜索引擎入口 百度网盘
  • 做网站的linux程序代码建网站用什么工具
  • 新疆生产建设兵团纪委网站同仁seo排名优化培训
  • 企业网站优化包括哪三个层面江苏搜索引擎优化
  • 北京怀柔网站制作今日军事新闻最新消息新闻报道
  • 自己建网站需要什么软件旅游新闻热点
  • 如何在建设银行网站查验回单东莞快速优化排名
  • 给自己家的公司做网站好做吗手机端百度收录入口
  • 个人网站制作视频建站软件
  • 南京做网站公司地点天猫店铺申请条件及费用