Category - IT技术

java shiro    2017-07-19 23:47:07    1397

关于shiro错误的分析
错误提示:

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code,either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.


错误原因:

在web.xml中配置shiro filter的时候,shiro filter放置位置放到了struts2 filter后面


原因分析:

如果使用struts2,那么在struts2加载静态资源的时候,需要将静态资源SecurityUtils也加载进去,如果将shiro filter放置位置放到了struts2 filter后面,那么必将导致无法加载到struts2中去,而后使用SecurityUtils.getSubject();的时候,导致出错,


解决办法:

shiro的filter应该放在struts2的 filter的上面

还可以在使用之前使用这种方式:即在SecurityUtils.getSubject();之前加入如下代码

 

Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
// 创建SecurityManager (根据配置创建SecurityManager实例)
SecurityManager security = factory.getInstance();
SecurityUtils.setSecurityManager(security);

这个想必不用解释了吧

 

 


 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

Extjs 前端    2017-07-19 23:46:18    837

话不多说,贴上代码

html代码:

 

	





	.my_row_class{ background:gray;}

	
	
	
	


js代码,其中应-----隔开的代码即为关键代码,自己分析吧:

Ext.onReady(function(){
    Ext.QuickTips.init();  
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

    // sample static data for the store
    var myData = [
        ['3m Co',                               71.72, 0.02,  0.03,  '9/1 12:00am'],
        ['3m Co',                               71.72, 0.02,  0.03,  '9/1 12:00am'],
        ['Alcoa Inc',                           29.01, 0.42,  1.47,  '9/1 12:00am'],
        ['Altria Group Inc',                    83.81, 0.28,  0.34,  '9/1 12:00am'],
        ['Altria Group Inc',                    83.81, 0.28,  0.34,  '9/1 12:00am'],
        ['Altria Group Inc',                    83.81, 0.28,  0.34,  '9/1 12:00am'],          
        ['Wal-Mart Stores, Inc.',               45.45, 0.73,  1.63,  '9/1 12:00am']
    ];

    /**
     * Custom function used for column renderer
     * @param {Object} val
     */
    function chang
java shiro    2017-07-19 23:45:15    1099

org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - **, rememberMe=false] did not match the expected credentials.

shiro在实现登陆认证的时候,一般从前端传来的是明文密码,而我们库中存放的是hash值,于是我们就需要转换下user的密码,

当然,我们有可能会在使用验证查询的时候,将user的密码转换成hash,然而在loginAction中,存放的user中的密码仍为明文,此时会出现错误

解决办法,在loginAction获取到pwd后,将其替换为hash,然后认证成功后存放到session中就ok了

 

user.setPwd(MD5Util.md5(user.getPwd())); 

 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

SqlServer    2017-07-19 23:44:11    804
--查看当前的存放位置
select database_id,name,physical_name AS CurrentLocation,state_desc,size from sys.master_files  
where database_id=db_id(N'数据库名');

--修改文件的存放位置下次启动生效
--testDb为数据库名,
alter database 数据库名 modify file ( name = 文件名(不包含后缀), filename = '文件存储路径');
alter database 数据库名 modify file ( name = 文件名(不包含后缀), filename = '文件存储路径');
eg.
	alter database testDb modify file ( name = testDb, filename = 'G:\SQL_DATA\testDb\testDb.mdf');
	alter database testDb modify file ( name = testDb_log, filename = 'G:\SQL_DATA\testDb\testdb_log.ldf');

--修改默认的数据库文件存放位置(即时生效)
EXEC xp_instance_regwrite  
@rootkey='HKEY_LOCAL_MACHINE',  
@key='Software\Microsoft\MSSQLServer\MSSQLServer',  
@value_name='DefaultData',  
@type=REG_SZ,  
@value='E:\MSSQL_MDF\data'  
GO  
--修改默认的日志文件存放位置(即时生效)
EXEC master..xp_instance_regwrite  
@rootkey='HKEY_LOCAL_MACHINE',  
@key='Software\Microsoft\MSSQLServer\MSSQLServer',  
@value_name='DefaultLog',  
@type=REG_SZ,  
@value='E:\MSSQL_MDF\log'  
GO  

 

 


 

by 刘迎光@萤火虫工作室
OpenBI交流群:49

sqlserver    2017-07-19 23:43:08    793
--创建测试表  
CREATE TABLE [dbo].[testtab](  
 [id] [nchar](10) NULL,  
 [name] [nchar](10) NULL  
) ;  
--向测试表插入测试数据  
insert into testtab values('1','1');  
insert into testtab values('1','1');  
insert into testtab values('2','2');  
insert into testtab values('2','2');  
insert into testtab values('3','3');  
insert into testtab values('3','3');  
  
--创建临时表并向临时表中插入测试表testtab中数据以及添加自增id:autoID  
select identity(int,1,1) as autoID, * into #Tmp from testtab  
--根据autoID删除临时表#tmp中的重复数据,只保留每组重复数据中的第一条  
delete #Tmp where autoID in(select max(autoID) from #Tmp group by id);  
--清除testtab表中的所有数据  
delete testtab;  
--向testtab表中插入#Tmp表中被处理过的数据  
insert into testtab select id,name from #Tmp;  
--删除临时表#Tmp  
drop table #Tmp;  

 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

3/26