From b0e3a3454ea9e3c3bbf74c0f3e6f48d6ba05f649 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Mon, 1 Aug 2022 23:50:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../neutrino/core/bean/SimpleBeanFactory.java | 1 + .../config/AbstractConfigurationParser.java | 37 +++++++---- .../core/config/ConfigurationParser.java | 7 ++ .../core/db/mapper/SqlMapperInterceptor.java | 3 +- .../asgc/neutrino/core/util/ConfigUtil.java | 4 ++ .../asgc/neutrino/core/db/mapper/Test1.java | 4 -- .../base/rest/config/SystemConfiguration.java | 55 ++++++++++++++++ .../server/controller/IndexController.java | 32 ++++++++- .../neutrino/proxy/server/dal/UserMapper.java | 45 +++++++++++++ .../proxy/server/dal/UserTokenMapper.java | 43 ++++++++++++ .../proxy/server/dal/entity/UserDO.java | 62 +++++++++++++++++ .../proxy/server/dal/entity/UserTokenDO.java | 66 +++++++++++++++++++ .../proxy/server/service/UserService.java | 18 +++++ .../neutrino/proxy/server/util/Md5Util.java | 50 ++++++++++++++ .../src/main/resources/sql/user.data.sql | 2 +- 15 files changed, 408 insertions(+), 21 deletions(-) create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/SystemConfiguration.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserMapper.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserDO.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserTokenDO.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/Md5Util.java diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/bean/SimpleBeanFactory.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/bean/SimpleBeanFactory.java index 8770b9d4..c5cdf753 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/bean/SimpleBeanFactory.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/bean/SimpleBeanFactory.java @@ -213,6 +213,7 @@ public class SimpleBeanFactory extends AbstractBeanFactory { BeanWrapper factoryBean = bean.getFactoryBean(); if (!factoryBean.hasInstance()) { newInstance(factoryBean); + inject(factoryBean); } if (bean.getInstantiationMethod().getParameters().length == 0) { bean.setInstance(bean.getInstantiationMethod().invoke(factoryBean.getInstance())); diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/AbstractConfigurationParser.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/AbstractConfigurationParser.java index 07652ebc..e04de74e 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/AbstractConfigurationParser.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/AbstractConfigurationParser.java @@ -26,10 +26,7 @@ import fun.asgc.neutrino.core.annotation.Configuration; import fun.asgc.neutrino.core.annotation.Value; import fun.asgc.neutrino.core.constant.MetaDataConstant; import fun.asgc.neutrino.core.exception.ConfigurationParserException; -import fun.asgc.neutrino.core.util.CollectionUtil; -import fun.asgc.neutrino.core.util.FileUtil; -import fun.asgc.neutrino.core.util.ReflectUtil; -import fun.asgc.neutrino.core.util.StringUtil; +import fun.asgc.neutrino.core.util.*; import org.apache.commons.lang3.StringUtils; import java.io.FileNotFoundException; @@ -50,12 +47,20 @@ public abstract class AbstractConfigurationParser implements ConfigurationParser @Override public T parse(InputStream in, Class clazz) throws ConfigurationParserException { + return parse(in, clazz, null); + } + + public T parse(InputStream in, Class clazz, Object obj) throws ConfigurationParserException { Map config = parse2Map(in); - return parse(config, clazz); + return parse(config, clazz, obj); } @Override public T parse(Class clazz) throws ConfigurationParserException { + return parse(clazz, null); + } + + public T parse(Class clazz, Object obj) throws ConfigurationParserException { String fileName = defaultFileName(); Configuration configuration = clazz.getAnnotation(Configuration.class); if (null != configuration && StringUtils.isNotEmpty(configuration.file())) { @@ -64,21 +69,31 @@ public abstract class AbstractConfigurationParser implements ConfigurationParser try { InputStream in = FileUtil.getInputStream(MetaDataConstant.CLASSPATH_RESOURCE_IDENTIFIER.concat("/").concat(fileName)); - return parse(in, clazz); + return parse(in, clazz, obj); } catch (FileNotFoundException e) { throw new ConfigurationParserException(String.format("配置文件[%s]不存在", fileName)); } } @Override - public T parse(Map config, Class clazz) throws ConfigurationParserException { - return parseProxy(config, clazz); + public void parse(Object obj) throws ConfigurationParserException { + Assert.notNull(obj, "对象不能为空"); + parse(obj.getClass(), obj); } - private T parseProxy(Map config, Class clazz) throws ConfigurationParserException { + @Override + public T parse(Map config, Class clazz) throws ConfigurationParserException { + return parse(config, clazz, null); + } + + public T parse(Map config, Class clazz, Object obj) throws ConfigurationParserException { + return parseProxy(config, clazz, obj); + } + + private T parseProxy(Map config, Class clazz, Object obj) throws ConfigurationParserException { T instance = null; try { - instance = (T)clazz.newInstance(); + instance = (null != obj) ? (T)obj : (T)clazz.newInstance(); } catch (InstantiationException e) { throw new ConfigurationParserException(String.format("无法实例化类:%s", clazz.getName())); } catch (IllegalAccessException e) { @@ -129,7 +144,7 @@ public abstract class AbstractConfigurationParser implements ConfigurationParser boolean success = ReflectUtil.setFieldValue(field, instance, fieldValue); if (!success) { try { - Object o = parseProxy((Map)config.get(key), field.getType()); + Object o = parseProxy((Map)config.get(key), field.getType(), null); if (null != o) { ReflectUtil.setFieldValue(field, instance, o); } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/ConfigurationParser.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/ConfigurationParser.java index 344259b1..2adc672e 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/ConfigurationParser.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/config/ConfigurationParser.java @@ -51,6 +51,13 @@ public interface ConfigurationParser { */ T parse(Class clazz) throws ConfigurationParserException; + /** + * 解析 + * @param obj + * @throws ConfigurationParserException + */ + void parse(Object obj) throws ConfigurationParserException; + /** * 解析 * @param config diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java index a86dbdf8..f3c51fad 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java @@ -49,8 +49,6 @@ import java.util.Map; @Component public class SqlMapperInterceptor implements Interceptor { - @Autowired - private JdbcTemplate jdbcTemplate; private static final Cache paramsCache = new MemoryCache<>(); @Init @@ -60,6 +58,7 @@ public class SqlMapperInterceptor implements Interceptor { @Override public void intercept(Invocation inv) throws Exception { + JdbcTemplate jdbcTemplate = BeanManager.getBean(JdbcTemplate.class); Assert.notNull(jdbcTemplate, "JdbcTemplate未注入,调用失败!"); Params params = getParams(inv.getTargetMethod()); if (null == params) { diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/ConfigUtil.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/ConfigUtil.java index cec459ae..62a45770 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/ConfigUtil.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/util/ConfigUtil.java @@ -38,4 +38,8 @@ public class ConfigUtil { return ymlParser.parse(clazz); } + public static T getYmlConfig(Object obj) { + ymlParser.parse(obj); + return (T)obj; + } } diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java index d3b244eb..c04e13ea 100644 --- a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/mapper/Test1.java @@ -36,10 +36,6 @@ public class Test1 implements ApplicationRunner { @Autowired private TestGlobalExceptionHandler testGlobalExceptionHandler; - public Test1() { - System.out.println("aaa"); - } - @Init public void init() { log.info("初始化,注册全局异常拦截器{}...", testGlobalExceptionHandler.hashCode()); diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/SystemConfiguration.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/SystemConfiguration.java new file mode 100644 index 00000000..1ef5ab3a --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/SystemConfiguration.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.base.rest.config; + +import com.alibaba.druid.pool.DruidDataSource; +import fun.asgc.neutrino.core.annotation.*; +import fun.asgc.neutrino.core.base.Ordered; +import fun.asgc.neutrino.core.db.template.JdbcTemplate; + +import javax.sql.DataSource; + +/** + * 系统配置 + *author: aoshiguchen + * @date: 2022/8/1 + */ +@Order(Ordered.HIGHEST_PRECEDENCE) +@Component +public class SystemConfiguration { + @Autowired + private SqliteConfig sqliteConfig; + + @Bean + public DataSource dataSource() { + DruidDataSource dataSource = new DruidDataSource(); + dataSource.setUrl(sqliteConfig.getUrl()); + dataSource.setDriverClassName(sqliteConfig.getDriverClass()); + return dataSource; + } + + @Bean + public JdbcTemplate jdbcTemplate() { + return new JdbcTemplate(dataSource()); + } + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java index 4811be6a..399eea75 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/IndexController.java @@ -21,6 +21,7 @@ */ package fun.asgc.neutrino.proxy.server.controller; +import fun.asgc.neutrino.core.annotation.Autowired; import fun.asgc.neutrino.core.annotation.NonIntercept; import fun.asgc.neutrino.core.web.annotation.PostMapping; import fun.asgc.neutrino.core.web.annotation.RequestBody; @@ -28,8 +29,15 @@ import fun.asgc.neutrino.core.web.annotation.RequestMapping; import fun.asgc.neutrino.core.web.annotation.RestController; import fun.asgc.neutrino.proxy.server.controller.req.LoginReq; import fun.asgc.neutrino.proxy.server.controller.res.LoginRes; +import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; +import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO; +import fun.asgc.neutrino.proxy.server.service.UserService; +import fun.asgc.neutrino.proxy.server.util.Md5Util; import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil; +import java.util.Date; +import java.util.UUID; + /** * * @author: aoshiguchen @@ -39,16 +47,34 @@ import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil; @RequestMapping @RestController public class IndexController { + @Autowired + private UserService userService; @PostMapping("login") public LoginRes login(@RequestBody LoginReq req) { ParamCheckUtil.checkNotEmpty(req.getLoginName(), "loginName"); ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword"); + UserDO userDO = userService.findByLoginName(req.getLoginName()); + if (null == userDO || !Md5Util.encode(req.getLoginPassword()).equals(userDO.getLoginPassword())) { + // TODO 抛出异常 + } + String token = UUID.randomUUID().toString().replaceAll("-", ""); + + Date now = new Date(); + // TODO 计算过期时间 + userService.addUserToken(new UserTokenDO() + .setToken(token) + .setUserId(userDO.getId()) + .setExpirationTime(now) + .setCreateTime(now) + .setUpdateTime(now) + ); + return new LoginRes() - .setToken("1111") - .setUserId(1) - .setUserName("张三"); + .setToken(token) + .setUserId(userDO.getId()) + .setUserName(userDO.getName()); } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserMapper.java new file mode 100644 index 00000000..70eebe7e --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserMapper.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal; + +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.db.annotation.Select; +import fun.asgc.neutrino.core.db.mapper.SqlMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/1 + */ +@Component +public interface UserMapper extends SqlMapper { + + /** + * 根据登录名查询用户记录 + * @param loginName + * @return + */ + @Select("select * from user where login_name = ?") + UserDO findByLoginName(String loginName); + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java new file mode 100644 index 00000000..a2dea54d --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserTokenMapper.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal; + +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.db.annotation.Insert; +import fun.asgc.neutrino.core.db.mapper.SqlMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/1 + */ +@Component +public interface UserTokenMapper extends SqlMapper { + /** + * 新增用户token + * @param userToken + * @return + */ + @Insert("insert into `user_token`(`token`,`user_id`,`expiration_time`,`create_time`,`update_time`) values (:token,:userId,:expirationTime,:createTime,:updateTime)") + int add(UserTokenDO userToken); +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserDO.java new file mode 100644 index 00000000..c8d1795c --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserDO.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal.entity; + +import fun.asgc.neutrino.core.db.annotation.Id; +import fun.asgc.neutrino.core.db.annotation.Table; +import lombok.Data; +import lombok.ToString; + +import java.util.Date; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/1 + */ +@ToString +@Data +@Table("user") +public class UserDO { + @Id + private Integer id; + /** + * 用户名 + */ + private String name; + /** + * 登录名 + */ + private String loginName; + /** + * 登录密码 + */ + private String loginPassword; + /** + * 创建时间 + */ + private Date createTime; + /** + * 更新时间 + */ + private Date updateTime; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserTokenDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserTokenDO.java new file mode 100644 index 00000000..00a3385e --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/UserTokenDO.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.dal.entity; + +import fun.asgc.neutrino.core.db.annotation.Id; +import fun.asgc.neutrino.core.db.annotation.Table; +import lombok.Data; +import lombok.ToString; +import lombok.experimental.Accessors; + +import java.util.Date; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/1 + */ +@ToString +@Accessors(chain = true) +@Data +@Table("user_token") +public class UserTokenDO { + + @Id + private Integer id; + /** + * token + */ + private String token; + /** + * 用户ID + */ + private Integer userId; + /** + * 过期时间 + */ + private Date expirationTime; + /** + * 创建时间 + */ + private Date createTime; + /** + * 更新时间 + */ + private Date updateTime; + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java index 42c28d48..e047fda9 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserService.java @@ -21,7 +21,12 @@ */ package fun.asgc.neutrino.proxy.server.service; +import fun.asgc.neutrino.core.annotation.Autowired; import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.proxy.server.dal.UserMapper; +import fun.asgc.neutrino.proxy.server.dal.UserTokenMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; +import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO; /** * @@ -30,5 +35,18 @@ import fun.asgc.neutrino.core.annotation.Component; */ @Component public class UserService { + @Autowired + private UserMapper userMapper; + @Autowired + private UserTokenMapper userTokenMapper; + + + public UserDO findByLoginName(String loginName) { + return userMapper.findByLoginName(loginName); + } + + public void addUserToken(UserTokenDO userTokenDO) { + userTokenMapper.add(userTokenDO); + } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/Md5Util.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/Md5Util.java new file mode 100644 index 00000000..020dddc4 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/Md5Util.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.proxy.server.util; + +import java.math.BigInteger; +import java.security.MessageDigest; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/1 + */ +public class Md5Util { + + /** + * md5加密 + * @param data + * @return + */ + public static String encode(String data) { + byte[] digest = null; + try { + MessageDigest md5 = MessageDigest.getInstance("md5"); + digest = md5.digest(data.getBytes("utf-8")); + return new BigInteger(1, digest).toString(16); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/neutrino-proxy-server/src/main/resources/sql/user.data.sql b/neutrino-proxy-server/src/main/resources/sql/user.data.sql index 12f63503..f2094e02 100644 --- a/neutrino-proxy-server/src/main/resources/sql/user.data.sql +++ b/neutrino-proxy-server/src/main/resources/sql/user.data.sql @@ -1,3 +1,3 @@ #用户表 insert into `user`(`id`, `name`,`login_name`,`login_password`,`create_time`, `update_time`) values -(1, '管理员', 'admin', '123456', datetime('now', 'localtime'), datetime('now', 'localtime')); +(1, '管理员', 'admin', 'e10adc3949ba59abbe56e057f20f883e', datetime('now', 'localtime'), datetime('now', 'localtime'));