您现在的位置是:主页 > news > 做网站销售是干什么的/百度网盘客服

做网站销售是干什么的/百度网盘客服

admin2025/5/6 14:40:42news

简介做网站销售是干什么的,百度网盘客服,安徽基层党组织建设网站,网站域名解析时间一、前言 1.shiro是apache提供开源的安全管理框架。 2.可以实现认证,授权,会话管理,加密,缓存等。 3.Cryptoraphy 加密 提供常用的加密算法,很方便保证数据安全。MD5,SHA等 这里我主要介绍一下简单md5加密…

做网站销售是干什么的,百度网盘客服,安徽基层党组织建设网站,网站域名解析时间一、前言 1.shiro是apache提供开源的安全管理框架。 2.可以实现认证,授权,会话管理,加密,缓存等。 3.Cryptoraphy 加密 提供常用的加密算法,很方便保证数据安全。MD5,SHA等 这里我主要介绍一下简单md5加密…

一、前言

1.shiro是apache提供开源的安全管理框架。
2.可以实现认证,授权,会话管理,加密,缓存等。

3.Cryptoraphy 加密 提供常用的加密算法,很方便保证数据安全。MD5,SHA等
这里我主要介绍一下简单md5加密

二、shiro散列算法

1:散列算法(加密算法)
在身份认证过程中涉及到加密,密码时进行加密。保证密码安全。
shiro提供常用的加密算法:md5, sha 等。
不可逆的过程。

1.1:md5的测试代码(写在main方法就可以测试了)
//md5加密算法
Md5Hash md5=new Md5Hash(“1111”);
System.out.println(md5.toString());
//md5+加盐
md5=new Md5Hash(“1111”,“zs”);
System.out.println(md5.toString());
//md5+加盐+散列多次
md5=new Md5Hash(“1111”, “zs”,2);
System.out.println(md5.toString());
说明:这是个测试代码,相当于,你做添加用户的时候把加密后的密码存到数据库去,但是登陆验证的时候(相当于解密),还是需要配置如下文件:

1.2: 应用在UserRealm身份认证
1:shiro.ini配置 (在src下面写一个shiro.ini的配置文件,名字可以自己取,后缀必须是ini)
[main]
#设置凭证匹配器
credentialsMatcher=org.apache.shiro.authc.credential.HashedCredentialsMatcher
#加密算法md5
credentialsMatcher.hashAlgorithmName=md5
#散列次数
credentialsMatcher.hashIterations=2

#设置自定义Realm
userRealm=com.yl.realm.UserRealm (这里是你自己写的realm的权限定名也就是包名加类名)

#设置自定义Realm的凭证匹配器
userRealm.credentialsMatcher=$credentialsMatcher

#设置安全管理器使用的Realm
securityManager.realm=$userRealm

UserRealm类如下:

package com.yl.realm;import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;public class UserRealm extends AuthorizingRealm{@Overridepublic String getName() {return "UserRealm";}//获取认证信息方法@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {String username=token.getPrincipal().toString();//访问数据库的用户表,获取用户对应的密码(加密后的密码,我这里就没有访问数据库了,直接定义好加密好的密码和盐值)String pwd="02d91893d595a23e351d5873cb4c131f";String salt="zs";SimpleAuthenticationInfo info=new SimpleAuthenticationInfo(username,pwd,ByteSource.Util.bytes(salt), getName());return info;}//获取授权信息的方法@Overrideprotected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) {return null;}}

测试类如下:

package com.yl.shiro;import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.util.Factory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;public class AuthenticationDemo {public static void main(String[] args) {Factory<org.apache.shiro.mgt.SecurityManager> factory=new IniSecurityManagerFactory("classpath:shiro.ini");SecurityManager securityManager=factory.getInstance();SecurityUtils.setSecurityManager(securityManager);Subject subject=SecurityUtils.getSubject();UsernamePasswordToken token=new UsernamePasswordToken("zhangsan", "1111");subject.login(token);if (subject.isAuthenticated()) {System.out.println("认证成功");}}
}