会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题
JAVA 全系列/第九阶段:权限控制与安全认证/Spring Security(旧) 241楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro 242楼

在UserRealm3中写

while(rs.next()){
    SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(authenticationToken.getPrincipal(),rs.getString("pwd"),ByteSource.Util.bytes(rs.getString("salt")),"userRealm3");

    return simpleAuthenticationInfo;
}

运行TestC就会显示登入失败,并且报异常

把ByteSource.Util.bytes(rs.getString("salt")改为ByteSource.Util.bytes("lin")再运行TestC就登入成功


写ByteSource.Util.bytes(rs.getString("salt")出现的异常

log4j:WARN No appenders could be found for logger (org.apache.shiro.io.ResourceUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.sql.SQLException: Column 'salt' not found.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
	at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1162)
	at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5728)
	at com.bjsxt.shiro03.UserRealm3.doGetAuthenticationInfo(UserRealm3.java:40)
	at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:568)
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:180)
	at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
	at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
	at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
	at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
	at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
	at com.bjsxt.shiro03.TestC.main(TestC.java:25)
登入失败

Process finished with exit code 0


image.png


数据库

image.png



shiro01.rar


JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 243楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro 245楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 248楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 249楼
JAVA 全系列/第九阶段:权限控制与安全认证/Spring Security(旧) 250楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro 251楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro 254楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637