如何解决 org.apache.shiro.util.unknownclassexception

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何解决 org.apache.shiro.util.unknownclassexception相关的知识,希望对你有一定的参考价值。

参考技术A principals即主体的标识属性,可以是任何东西,如用户名、邮箱等,唯一即可。credentials是证明/凭证,即只有主体知道的安全值,如密码/数字证书等。最常见的principals和credentials组合就是用户/密码了。

下面我们来看一个认证的例子,由于我们是用maven构建的实例,所以需要在pom.xml中添加依赖:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11-20120805-1225</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.2.3</version>
</dependency>
另外,准备一些用户微分凭据,shiro.ini:

?
1
2
3
[users]
zhang=123
wang=123
测试用例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.shiro;

import junit.framework.Assert;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.junit.Test;

public class ShiroTest1
@Test
public void shiro_test1()
//获取SecurityManager工厂,此处使用ini配置文件初始化SecurityManager
Factory<org.apache.shiro.mgt.SecurityManager> factory =
new IniSecurityManagerFactory("classpath:shiro.ini");
//得到SecurityManager实例并绑定给SecurityUtils
org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
//得到Subject及创建用户名/密码身份验证Token(即用户身份/凭证)
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken("zhang","123");
try
subject.login(token);
catch (AuthenticationException e)
System.err.println(e.getMessage());

//断言用户已经登录
Assert.assertEquals(true, subject.isAuthenticated());
//退出
subject.logout();


从上例中,我们可以看到shiro的身份认证流程,如果还没有明白,可以看看下图:

首先调用Subject.login(token)进行登录,其会自动委托给SecurityManager,调用之前必须通过SecurityUtils.setSecurityManager()设置

2. SecurityManager负责真正的身份验证逻辑,它会委托给Authenticator进行身份验证

3. Authenticator才是真正的身份验证者,shiro API中核心的身份认证入口点,此处可以自定义插入自己的实现

4. Authenticator可能会委托给相应的AuthenticationStrategy进行多Realm身份验证,默认ModularRealmAuthenticator会调用AuthenticationStrategy进行多Realm身份验证。

5. Authenticator会把相应的token传入Realm,从Realm获取身份验证信息,如果没有返回/抛出异常表示身份验证失败了。此外可以配置多个Realm,将按照相应的顺序及策略进行访问。本回答被提问者和网友采纳

MySQL 的 10048问题,如何解决?

MySQL Server Error:
Can't connect to MySQL server on 'localhost' (10048) ( 2003 )

如何解决此问题,或者怎么有效的配置mysql
在“运行”里找到C:\mysql\bin\mysqld-opt.exe
我运行后,过一段时间后就会再出现此问题!只有从新起动计算机才可以连接成功mysql,也就1-2天数据库就无法连接了,以前用了1年都没有遇到此问题?这个问题和php代码有关系?

谁能给我一个治根的方法!谢谢
注:我已经从新或者升级过mysql了,但是没有起作用!

解决Can't connect to MySQL server on 'localhost' (10048), 一般见于使用mysql的windows 2003服务器.

错误的出现的原因:
应用程序需要快速释放和创建新连接, 但是由于 TIME_WAIT 中存在的连接超过默认值,导致较低吞吐量.

解决方案:
和本错误密切相关的两个windows的注册表项:TcpTimedWaitDelay和MaxUserPort的值.

TcpTimedWaitDelay 确定 TCP/IP 可释放已关闭连接并重用其资源前, 必须经过的时间. 关闭和释放之间的此时间间隔通称 TIME_WAIT 状态或两倍最大段生命周期(2MSL)状态. 此时间期间, 重新打开到客户机和服务器的连接的成本少于建立新连接. 减少此条目的值允许 TCP/IP 更快地释放已关闭的连接, 为新连接提供更多资源.

MaxUserPort 确定从系统请求任何可用用户端口时所用最大端口数,TCP/IP 可指定的最高端口号. 如果建立 TCP 连接最大端口连接大于 5000, 本地计算机响应以下错误信息WSAENOBUFS (10055): 因为系统缺乏足够缓冲区或者因为队列已满而无法执行套接字上操作, 从而导致应用程序的10048错误.
打开注册表编辑器regedit

TcpTimedWaitDelay 设置:
找到 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\TCPIP\Parameters 注册表子键
并创建名为 TcpTimedWaitDelay 的新 REG_DWORD 值
设置此值为十进制 30, 十六进制为 0×0000001e
该值等待时间将是 30 秒。
本项的默认值:0xF0(16进制), 等待时间设置为 240 秒

MaxUserPort 设置(增加最大值端口连接):
找到 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\TCPIP\Parameters 注册表子键
并创建名为 MaxUserPort 的新 REG_DWORD 值
设置此值为十进制最低 32768
该值等待时间将是 30 秒。
重启windows系统。
本项的默认值:5000(十进制)

关闭注册表编辑器, 重启windows系统
参考技术A 可能是你的MYSQL没有启动!

在“运行”里找到C:\mysql\bin\mysqld-opt.exe
运行就是了!
参考技术B Error: Can't connect to MySQL server on 'localhost' (10048)
他们网站的问题。和你机器没有关系。

以上是关于如何解决 org.apache.shiro.util.unknownclassexception的主要内容,如果未能解决你的问题,请参考以下文章

如何解决包冲突问题

如何解决包冲突问题

如何解决ajax跨域问题

MySQL 的 10048问题,如何解决?

如何解决smartgit的冲突问题

如何解决https传输图片的问题