最近几天在学习Apache Shiro......看了一些大神们的教程.....感觉收获不少.....但是毕竟教程也只是指引一下方向....即使是精辟教程,仍然有很多东西都没有说明....所以自己也稍微研究了一下...记录了一下我的研究发现....教程点这里 这篇教程的最后提到 ...
最近几天在学习Apache Shiro......看了一些大神们的教程.....感觉收获不少.....但是毕竟教程也只是指引一下方向....即使是精辟教程,仍然有很多东西都没有说明....所以自己也稍微研究了一下...记录了一下我的研究发现....教程点这里
这篇教程的最后提到了自己去写Realm.....然后给出了4个方法.....但是并没有怎么详细说明.....我想说说我的理解.....(我的理解可能会有很多错误)
我想先说说登陆验证的大致流程....大致......
从用户那里收集完用户名密码以后我们会调用subject.login(token)这个方法去登陆.....Subject是一个接口,没有定义login的具体实现.....Shiro里只有一个类实现了这个接口,是DelegatingSubject这个类.这个类里的方法login方法如下:
1 public void login(AuthenticationToken token) throws AuthenticationException { 2 clearRunAsIdentitiesInternal(); 3 Subject subject = securityManager.login(this, token); 4 5 PrincipalCollection principals; 6 7 String host = null; 8 9 if (subject instanceof DelegatingSubject) {10 DelegatingSubject delegating = (DelegatingSubject) subject;11 //we have to do this in case there are assumed identities - we don't want to lose the 'real' principals:12 principals = delegating.principals;13 host = delegating.host;14 } else {15 principals = subject.getPrincipals();16 }17 18 if (principals == null || principals.isEmpty()) {19 String msg = "Principals returned from securityManager.login( token ) returned a null or " +20 "empty value. This value must be non null and populated with one or more elements.";21 throw new IllegalStateException(msg);22 }23 this.principals = principals;24 this.authenticated = true;25 if (token instanceof HostAuthenticationToken) {26 host = ((HostAuthenticationToken) token).getHost();27 }28 if (host != null) {29 this.host = host;30 }31 Session session = subject.getSession(false);32 if (session != null) {33 this.session = decorate(session);34 } else {35 this.session = null;36 }37 }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:Apache Shiro 学习记录1
关键词:Apache
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。