Merge branch 'master' of gitee.com:willfree/min-dev-java

This commit is contained in:
free will committed 2021-04-07 16:37:20 +08:00
commit f727a5c505
2 files changed
+93 -2

No files matched your search

@@ -0,0 +1,91 @@
package minsecurity.identity.persist;
import minsecurity.Common;
import minsecurity.identity.Identity;
import minsecurity.identity.persist.sqlite.Sqlite;
import minsecurity.identity.persist.sqlite.db.Db;
import java.util.List;
public class Persist {
private static int persistPlugin = Common.SQLITE; // 默认使用Sqlite
/**
* 存储一个Identity,生成identity结构体和存储分开
* @param identity
* @throws Exception
*/
public static void persistIdentity(Identity identity) throws Exception{
switch (persistPlugin){
case Common.SQLITE:
Db.persistIdentity(identity);
}
}
/**
* 通过Identity的名称,删除一个Identity对象
* @param name
* @throws Exception
*/
public static void deleteIdentityByNameFromStorage(String name) throws Exception{
switch (persistPlugin){
case Common.SQLITE:
Db.deleteIdentityByName(name);
}
}
/**
* 通过Identity的名称,获得一个Identity对象
* @param name
* @param passwd
* @return
* @throws Exception
*/
public static Identity getIdentityByNameFromStorage(String name, String passwd) throws Exception{
switch (persistPlugin){
case Common.SQLITE:
return Db.getIdentityByNameFromStorage(name);
}
return null;
}
/**
* 获得所有的身份实例
* @param passwd
* @return
* @throws Exception
*/
public static List<Identity> getAllIdentityFromStorage(String passwd) throws Exception{
switch (persistPlugin){
case Common.SQLITE:
return Db.getAllIdentityFromStorage();
}
return null;
}
/**
* 通过Identity的名称,设置默认的Identity
* @param name
* @throws Exception
*/
public static void setDefaultIdentityByNameInStorage(String name) throws Exception{
switch (persistPlugin){
case Common.SQLITE:
Db.SetDefaultIdentityByNameInStorage(name);
}
}
/**
* 获得当前系统默认使用的Identity对象
* @param passwd
* @return
* @throws Exception
*/
public static Identity getDefaultIdentityFromStorage(String passwd) throws Exception{
switch (persistPlugin){
case Common.SQLITE:
return Db.getDefaultIdentityFromStorage();
}
return null;
}
}
@@ -132,7 +132,7 @@ public final class Db {
stmt.close();
}
public static List<Identity> getAllIdentityFromStorage(String name) throws Exception {
public static List<Identity> getAllIdentityFromStorage() throws Exception {
Connection c = Sqlite.getInstance().getConn();
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from identityinfo");
@@ -243,7 +243,7 @@ public final class Db {
c.close();
}
public Identity getDefaultIdentityFromStorage() throws Exception{
public static Identity getDefaultIdentityFromStorage() throws Exception{
Connection c = Sqlite.getInstance().getConn();
PreparedStatement pstmt = c.prepareStatement("SELECT * from identityinfo where is_default= ? LIMIT 1");
pstmt.setInt(1, 1);