public class CASValidation {
public static String CAS_VALIDATE_PATH = "";
public void createValidateInfo() throws Exception{
boolean flag = true;
File carPath = new File(this.getClass().getResource("").getPath()+"/nos.crt");
CertificateFactory cf=CertificateFactory.getInstance("X.509");
FileInputStream in=new FileInputStream(carPath);
Certificate c=cf.generateCertificate(in);
String s=c.toString();
X509Certificate t=(X509Certificate)c;
byte [] encod2=c.getEncoded();
X509CertImpl cimp2=new X509CertImpl(encod2); //用该编码创建X509CertImpl类型对象
X509CertInfo cinfo2=(X509CertInfo)cimp2.get(X509CertImpl.NAME+"."+X509CertImpl.INFO);//获取X509CertInfo
Date begindate=new Date(); //获取当前时间
Date enddate=new Date(begindate.getTime()+30*24*60*60*1000L); //有效期为30天
System.out.println("enddate======="+enddate.toLocaleString());
System.out.println("begin======="+t.getNotBefore().toLocaleString());
System.out.println("end======="+t.getNotAfter().toLocaleString());
CertificateValidity cv=new CertificateValidity(begindate,enddate); //创建对象
cinfo2.set(X509CertInfo.VALIDITY,cv); //设置有效期
// int sn=(int)(begindate.getTime()/1000); //以当前时间为序列号
// CertificateSerialNumber csn=new CertificateSerialNumber(sn);
// cinfo2.set(X509CertInfo.SERIAL_NUMBER,csn);
//FileOutputStream out=new FileOutputStream(carPath);
System.out.println(carPath.getPath());
System.out.println(s);
}
public boolean validationSecurity(){
boolean flag = true;
try{
CertificateFactory cf=CertificateFactory.getInstance("X.509");
File carPath = new File(this.getClass().getResource("").getPath()+"/nos.crt");
FileInputStream in1=new FileInputStream(carPath);
java.security.cert.Certificate c1=cf.generateCertificate(in1);
X509Certificate t=(X509Certificate)c1;
Date TimeNow=new Date();
try{
t.checkValidity(TimeNow);
if(!validationModifyDate()){
}else{
insertLoginDate();
}
}catch(CertificateExpiredException e){ //过期
flag = false;
System.out.println("Expired");
System.out.println(e.getMessage());
}catch(CertificateNotYetValidException e){ //尚未生效
flag = false;
System.out.println("Too early");
System.out.println(e.getMessage());
}
}catch(Exception e){
flag = false;
}
return flag;
}
public boolean validationModifyDate(){
boolean flag = true;
File file = new File(this.getClass().getResource("").getPath()+"/loginDate.txt");
//File file = new File(fileName);
BufferedReader reader = null;
try {
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
String todayStr = DateFormatUtils.format(new Date(), "yyyy-MM-dd"); //今天的日期
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
// System.out.println("line " + line + ": " + tempString);
// System.out.println("比较======="+todayStr.compareTo(tempString));
if(todayStr.compareTo(tempString)<0){
System.out.println("系统许可时间已过期,请重新申请。");
flag = false;
}
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
return flag;
}
public void insertLoginDate() {
try {
File file = new File(this.getClass().getResource("").getPath()+"/loginDate.txt");
String todayStr = DateFormatUtils.format(new Date(), "yyyy-MM-dd"); //今天的日期
//打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
FileWriter writer = new FileWriter(file, true);
writer.write(todayStr+"/n");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 以行为单位读取文件,常用于读面向行的格式化文件
*/
public static void readFileByLines(String fileName) {
File file = new File(fileName);
BufferedReader reader = null;
try {
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
String todayStr = DateFormatUtils.format(new Date(), "yyyy-MM-dd"); //今天的日期
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
System.out.println("line " + line + ": " + tempString);
System.out.println("比较======="+todayStr.compareTo(tempString));
line++;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
public static void main(String[] args){
CASValidation casValidation= new CASValidation();
String fileName = "D:/test/CoreFlow/WebRoot/WEB-INF/classes/com/nos/validation/cas/loginDate.txt";
//CASValidation.appendMethodA(fileName, "2010-12-03/n");
//CASValidation.readFileByLines(fileName);
//casValidation.validationModifyDate("2010-12-03");
casValidation.validationModifyDate();
casValidation.insertLoginDate();
}
}
分享到:
相关推荐
cas验证包--3.5.3版本文件
php cas: php版cas验证程序,支持php 5.
cas一般均放置在内网,加入cas验证则必须要求用户走vpn访问,提高安全性; cas可和域控等系统结合,密码定时过期; 基本认证统一走cas控制,减去开帐号等麻烦事; django 如何使用cas验证 django 的好处就是支持的包多,网上...
springboot(springboot + shiro + oracle) + vue 集成cas
单点登录(Single Sign On),简称为 SSO,是目前比较流行的企业业务整合的解决方案之一。SSO的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。
其中shiro.loginUrl 跟 shiro.logoutUrl的前面是cas验证的地址,后面的是我们应用系统的地址,这样配置的方式是为了在访问我们的应用系统的时候,先到cas进行验证,如果验证成功了,cas将重定向到shiro.successUrl ...
CAS验证客户端是否被授权,通常通过在数据库对用户名和密码进行检查(例如Kerberos、LDAP或Active Directory)。 如果身份验证成功,CAS令客户端返回到应用程序,并传递身份验证票(Security ticket)。然后,应用...
NULL 博文链接:https://ymhh.iteye.com/blog/678015
无https验证的CAS单点登录,统一认证
用的java语言后台连接CAS登陆验证的工具类 特点: 1、无需修改CAS服务端的代码 2、能够自动获取ticket等参数值 3、这是一个工具类调用非常方便,不光适用于java也适用于android, 其他语言也可以参考,注释写的非常...
提供了cas server 5.3.9 单点登录的资源整合,cas服务器,运行即可用 配置了spring srcurity 密码验证方式
包含cas源码、cas使用说明文档(包含配置信息)、连接数据库所需jar包、cas服务端自定义返回值等
CAS客户端跳过https验证
对应博客:https://blog.csdn.net/fancheng614/article/details/84038266
cas-server-webapp-4.0.0.war--cas server去掉https验证.下载后直接部署tomcat即可,建议下载后将名称改为cas.war
CAS的ASP.NET客户端配置及验证,实现SSO单点登录
本篇文章主要介绍了spring boot整合CAS Client实现单点登陆验证的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
cas连接数据库所需要的jar包 cas版本为5.3.14
CAS验证这是一个实用工具,可帮助您通过CAS服务器( )验证基于Connect或Express(可能还有其他框架,甚至根本没有)的Web服务。它允许单点登录和。换句话说,如果客户端已到CAS服务器以前记录的,该库将允许您服务...
CAS4.2.4 连接Liferay6.2以上版本数据库用户表验证用户 project代码