Home > Back-end >  SSH framework integrating shiro, shiro does not perform myrealm authentication method
SSH framework integrating shiro, shiro does not perform myrealm authentication method

Time:09-25

Phenomenon description: do a simple login page, use shiro,
The login page: login. JSP, login success: index. The JSP,

Configuration is as follows:
XML applicationContext - shiro.







Login_ *=-anon
/JSP/register JSP=-anon
/JSP/login. JSP=-anon

/JSP/index. The JSP=authc


/toPrivilege action=roles/admin - & gt;
* *=/system/roles/admin, HR, & gt;

/* *=authc









Depends on -="lifecycleBeanPostProcessor" & gt;




Myrealm class implementation is as follows:
@ Component
@ Transactional
Public class MyRealm extends AuthorizingRealm {

Private LoginService LoginService;

//authorization information (doGetAuthorizationInfo)
@ Override
Protected AuthorizationInfo doGetAuthorizationInfo PrincipalCollection (principals)
{
System. Out.println (" authorization information... ");
//derives from the principals on the user input the login name
String loginname=(String) principals. FromRealm (getName ()). The iterator (). The next ();//use the iterator
//from the database to determine whether a user is
User User=loginService. FindUserByName (loginname);
If (the user!=null)
{
SimpleAuthorizationInfo info=new SimpleAuthorizationInfo ();
Set Roles=user. GetRoles ();
For (Role Role: roles)
{
//add the name of the character to the authorization information
Info. AddRole (role. GetRole_name ());
//get the role of corresponding permissions
Set Permissions=role. GetPermissions ();
For (Permission Permission: permissions)
{
Info. AddStringPermission (permission. GetValidateurl ());
}
}
return info;
}
return null;
}


//get the authentication information (doGetAuthenticationInfo
@ Override
Protected AuthenticationInfo doGetAuthenticationInfo (AuthenticationToken token) throws AuthenticationException
{
System. Out.println (" authentication information... ");
//conversion become easier the UsernamePasswordToken object
The UsernamePasswordToken usertoken=(the UsernamePasswordToken) token;
User User=loginService. FindUserByName (usertoken getUsername ());
If (the user!=null)
{
SimpleAuthenticationInfo info=new SimpleAuthenticationInfo (user getUsername (), usertoken. GetPassword (), getName ());
return info;
}
return null;
}

Public LoginService getLoginService () {
Return loginService;
}

Public void setLoginService (LoginService LoginService) {
Enclosing loginService=loginService;
}

}

The login. The JSP:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "& gt;
The login page & lt;/title> <br/></head> <br/><body> <br/><The form action="${pageContext. Request. ContextPath}/login_login" method=post & gt; <br/><br/><Label> Please enter the account: & lt;/label> <Input type="text" name="user. The username"/& gt; <br/><Label> Please enter the password: & lt;/label> <Input type="password" name="user. The password"/& gt; <br/><br/>nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/Backend/29927.html" target="_blank" style="color:#999">https//www.codepudding.com/Backend/29927.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/Backend/29926.html'>Registration information input to mysql but appeared Unable to compile class for JSP:</a></div> <div class="detail-arr-right">Next:<a href='/Backend/29928.html'>The small white consult parameter assignment problem</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=Java+EE' target='_blank'>Java EE</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>