forked from fanruan/finekit
richie
5 years ago
7 changed files with 437 additions and 1 deletions
@ -0,0 +1,54 @@
|
||||
package com.fanruan.api.decision; |
||||
|
||||
import com.fanruan.api.log.LogKit; |
||||
import com.fanruan.api.util.StringKit; |
||||
import com.fr.base.Base64; |
||||
import com.fr.base.ServerConfig; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-19 |
||||
* 常规工具类 |
||||
*/ |
||||
public class CommonKit { |
||||
|
||||
/** |
||||
* 这个方法用于判断从前端返回服务器端的密码是否有被修改过 |
||||
* |
||||
* @param password 从前端返回的密码文本 |
||||
* @return 如果密码没有被修改过就返回true,否则就返回false |
||||
*/ |
||||
public static boolean isDefaultPasswordHolderString(String password) { |
||||
return DecisionServiceConstants.DEFAULT_PASSWORD.equals(password); |
||||
} |
||||
|
||||
/** |
||||
* 获取默认密码占位符 |
||||
* |
||||
* @return 默认密码占位符 |
||||
*/ |
||||
public static String fetchDefaultPasswordHolderString() { |
||||
return DecisionServiceConstants.DEFAULT_PASSWORD; |
||||
} |
||||
|
||||
/** |
||||
* 将base64编码的字符串转为常规的字符串 |
||||
* |
||||
* @param encodeStr base64编码的字符串 |
||||
* @return 常规字符串 |
||||
*/ |
||||
public static String getBase64DecodeStr(String encodeStr) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(encodeStr)) { |
||||
return new String(Base64.decode(encodeStr), ServerConfig.getInstance().getServerCharset()); |
||||
} |
||||
} catch (Exception e) { |
||||
LogKit.error(e.getMessage(), e); |
||||
} |
||||
|
||||
return StringKit.EMPTY; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fanruan.api.decision; |
||||
|
||||
import com.fanruan.api.decision.middle.ReadOnlyUser; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||
import com.fr.decision.webservice.utils.user.source.UserSource; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-19 |
||||
*/ |
||||
public class UserKit { |
||||
|
||||
/** |
||||
* 根据用户名获取这个用户的来源 |
||||
* |
||||
* @param username 用户名 |
||||
* @return 用户来源 |
||||
* @throws Exception 如果在获取用户的过程中出错了,则抛出此异常 |
||||
*/ |
||||
public static UserSource fetchUserSource(String username) throws Exception { |
||||
User user = UserService.getInstance().getUserByUserName(username); |
||||
return UserSourceFactory.getInstance().getUserSource(user); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户信息 |
||||
* |
||||
* @param username 用户名 |
||||
* @return 用户信息 |
||||
* @throws Exception 如果获取用户出错,则抛出此异常 |
||||
*/ |
||||
public static ReadOnlyUser getReadOnlyUser(String username) throws Exception { |
||||
User user = UserService.getInstance().getUserByUserName(username); |
||||
return ReadOnlyUser.build(user.getUserName(), user.getPassword(), user.getRealName()); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fanruan.api.decision.auth; |
||||
|
||||
import com.fr.decision.authorize.impl.AbstractPassport; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-19 |
||||
* 认证方式 |
||||
*/ |
||||
public abstract class BasePassport extends AbstractPassport { |
||||
|
||||
/** |
||||
* 检查登录信息是否有效 |
||||
* |
||||
* @param username 用户名 |
||||
* @param inputPassword 输入的密码 |
||||
* @param savedPassword 配置文件中保存的密码 |
||||
* @param hashPassword 哈希后的密码 |
||||
* @return 登录凭证是有效的则返回true,否则返回false |
||||
*/ |
||||
public boolean checkTicket(String username, String inputPassword, String savedPassword, String hashPassword) { |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.fanruan.api.decision.auth.bean; |
||||
|
||||
import com.fr.decision.authorize.Passport; |
||||
import com.fr.decision.webservice.bean.authentication.PassportBean; |
||||
import com.fr.third.fasterxml.jackson.annotation.JsonTypeInfo; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-19 |
||||
* 用于表示不同认证方式的接口 |
||||
*/ |
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class") |
||||
public abstract class BasePassportBean<T extends Passport> extends PassportBean<T> { |
||||
|
||||
/** |
||||
* 用于标记认证类型的字符串 |
||||
* |
||||
* @return 字符串 |
||||
*/ |
||||
@Override |
||||
public abstract String markType(); |
||||
|
||||
/** |
||||
* 根据配置对象生成认证配置数据层对象 |
||||
* |
||||
* @param t 配置对象 |
||||
* @return 配属数据层 |
||||
*/ |
||||
@Override |
||||
public abstract BasePassportBean<T> createPassportBean(T t); |
||||
|
||||
/** |
||||
* 生成配置对象 |
||||
* |
||||
* @return 配置 |
||||
*/ |
||||
@Override |
||||
public abstract Passport createPassport(); |
||||
} |
@ -0,0 +1,45 @@
|
||||
package com.fanruan.api.decision.middle; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-19 |
||||
*/ |
||||
public class ReadOnlyUser { |
||||
|
||||
/** |
||||
* 非空项,无默认值 |
||||
*/ |
||||
private String userName = null; |
||||
/** |
||||
* 非空项,无默认值 |
||||
*/ |
||||
private String password = null; |
||||
|
||||
/** |
||||
* 姓名 |
||||
*/ |
||||
private String realName = null; |
||||
|
||||
public static ReadOnlyUser build(String userName, String password, String realName) { |
||||
return new ReadOnlyUser(userName, password, realName); |
||||
} |
||||
|
||||
private ReadOnlyUser(String userName, String password, String realName) { |
||||
this.userName = userName; |
||||
this.password = password; |
||||
this.realName = realName; |
||||
} |
||||
|
||||
public String getUserName() { |
||||
return userName; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public String getRealName() { |
||||
return realName; |
||||
} |
||||
} |
@ -0,0 +1,219 @@
|
||||
package com.fanruan.api.runtime; |
||||
|
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.stable.Filter; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-19 |
||||
* 操作运行环境下文件的工具方法 |
||||
*/ |
||||
public class ResourceKit { |
||||
|
||||
/** |
||||
* 路径是否存在 |
||||
* |
||||
* @param target 路径 |
||||
* @return 是否存在 |
||||
*/ |
||||
public static boolean exist(String target) { |
||||
return ResourceIOUtils.exist(target); |
||||
} |
||||
|
||||
/** |
||||
* 创建文件 |
||||
* |
||||
* @param file 文件路径 |
||||
* @return 是否存在 |
||||
*/ |
||||
public static boolean createFile(String file) { |
||||
return ResourceIOUtils.createFile(file); |
||||
} |
||||
|
||||
/** |
||||
* 创建文件夹 |
||||
* |
||||
* @param dir 文件夹路径 |
||||
* @return 是否成功 |
||||
*/ |
||||
public static boolean createDirectory(String dir) { |
||||
return ResourceIOUtils.createDirectory(dir); |
||||
} |
||||
|
||||
/** |
||||
* 是否为文件夹 |
||||
* |
||||
* @param path 路径 |
||||
* @return 是否是文件夹 |
||||
*/ |
||||
public static boolean isDirectory(String path) { |
||||
return ResourceIOUtils.isDirectory(path); |
||||
} |
||||
|
||||
/** |
||||
* 获取文件或者文件夹的名称 |
||||
* |
||||
* @param path 路径 |
||||
* @return 名称 |
||||
*/ |
||||
public static String getName(String path) { |
||||
return ResourceIOUtils.getName(path); |
||||
} |
||||
|
||||
/** |
||||
* 列出路径下的所有内容的名称 |
||||
* |
||||
* @param dir 路径 |
||||
* @return 所有内容名称List |
||||
*/ |
||||
public static String[] list(String dir) { |
||||
return ResourceIOUtils.list(dir); |
||||
} |
||||
|
||||
/** |
||||
* 列出路径下的所有符合要求的内容的名称 |
||||
* |
||||
* @param dir 路径 |
||||
* @param filter 过滤器 |
||||
* @return 所有内容名称List |
||||
*/ |
||||
public static String[] list(String dir, Filter<String> filter) { |
||||
return ResourceIOUtils.list(dir, filter); |
||||
} |
||||
|
||||
/** |
||||
* 文件夹是否存在 |
||||
* |
||||
* @param dir 文件夹 |
||||
* @return 是否存在 |
||||
*/ |
||||
public static boolean isDirectoryExist(String dir) { |
||||
return ResourceIOUtils.isDirectoryExist(dir); |
||||
} |
||||
|
||||
|
||||
public static String getRealPath(String relativePath) { |
||||
return ResourceIOUtils.getRealPath(relativePath); |
||||
} |
||||
|
||||
/** |
||||
* 读取文件到流 |
||||
* <p> |
||||
* 相对路径下如果是仓库资源从仓库读取,其它从本地读取 |
||||
* <p> |
||||
* 据对路径按绝对路径读 |
||||
* |
||||
* @param path 路径 |
||||
* @return 流 |
||||
*/ |
||||
public static InputStream read(String path) { |
||||
return ResourceIOUtils.read(path); |
||||
} |
||||
|
||||
/** |
||||
* 读取文件到bytes |
||||
* |
||||
* @param path 文件路径 |
||||
* @return bytes |
||||
*/ |
||||
public static byte[] readBytes(String path) { |
||||
return ResourceIOUtils.readBytes(path); |
||||
} |
||||
|
||||
/** |
||||
* 写入数据流到文件 |
||||
* |
||||
* @param path 文件路径 |
||||
* @param data 数据 |
||||
*/ |
||||
public static void write(String path, InputStream data) { |
||||
ResourceIOUtils.write(path, data); |
||||
} |
||||
|
||||
/** |
||||
* 写入字符串数据到文件 |
||||
* |
||||
* @param path 文件路径 |
||||
* @param data 数据 |
||||
*/ |
||||
public static void write(String path, String data) { |
||||
ResourceIOUtils.write(path, data); |
||||
} |
||||
|
||||
/** |
||||
* 写入字节数组数据到文件 |
||||
* |
||||
* @param path 文件路径 |
||||
* @param data 数据 |
||||
*/ |
||||
public static void write(String path, byte[] data) { |
||||
ResourceIOUtils.write(path, data); |
||||
} |
||||
|
||||
/** |
||||
* 获取父路径 |
||||
* |
||||
* @param path 路径 |
||||
* @return 父路径 |
||||
*/ |
||||
public static String getParent(String path) { |
||||
return ResourceIOUtils.getParent(path); |
||||
} |
||||
|
||||
/** |
||||
* 从仓库删除 |
||||
* |
||||
* @param path 路径 |
||||
* @return 是否删除成功 |
||||
*/ |
||||
public static boolean delete(String path) { |
||||
return ResourceIOUtils.delete(path); |
||||
} |
||||
|
||||
/** |
||||
* 文件的最后修改时间 |
||||
* |
||||
* @param path 文件路径 |
||||
* @return 修改的时间戳 |
||||
*/ |
||||
public static long lastModified(String path) { |
||||
return ResourceIOUtils.lastModified(path); |
||||
} |
||||
|
||||
/** |
||||
* 文件大小 |
||||
* |
||||
* @param path 文件路径 |
||||
* @return 文件字节数 |
||||
*/ |
||||
public static long getLength(String path) { |
||||
return ResourceIOUtils.getLength(path); |
||||
} |
||||
|
||||
/** |
||||
* 重命名 |
||||
* <p> |
||||
* 文件位置根据oldFile来确定 |
||||
* |
||||
* @param oldFile 原文件path |
||||
* @param newFile 新文件path |
||||
* @return 是否成功 |
||||
*/ |
||||
public static boolean renameTo(String oldFile, String newFile) { |
||||
return ResourceIOUtils.renameTo(oldFile, newFile); |
||||
} |
||||
|
||||
/** |
||||
* 拷贝文件到某目录下 |
||||
* |
||||
* @param src 源文件 |
||||
* @param dir 目标文件 |
||||
*/ |
||||
public static void copy(String src, String dir) throws IOException { |
||||
ResourceIOUtils.copy(src, dir); |
||||
} |
||||
} |
Loading…
Reference in new issue