diff --git a/.gitignore b/.gitignore index d00a46b7..fa8abca7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules/ dist/ target/ +logs/ npm-debug.log* yarn-debug.log* yarn-error.log* diff --git a/deploy/mysql/fateboard.sql b/deploy/mysql/fateboard.sql deleted file mode 100644 index 9cc8ef66..00000000 --- a/deploy/mysql/fateboard.sql +++ /dev/null @@ -1,9 +0,0 @@ -create table IF NOT EXISTS `t_fateboard_user`( - `user_id` bigint(20) not null auto_increment COMMENT 'primary key', - `name` varchar(128) NOT NULL UNIQUE COMMENT 'user name for cloud manager', - `password` varchar(256) NOT NULL COMMENT 'password for user', - `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '1 vaild, 2 deleted', - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Create Time', - `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON update CURRENT_TIMESTAMP COMMENT 'Update Time', - PRIMARY KEY(`user_id`) -)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE='utf8_general_ci' COMMENT='fateboard user information'; diff --git a/src/main/java/com/webank/ai/fate/board/dao/UserMapper.java b/src/main/java/com/webank/ai/fate/board/dao/UserMapper.java deleted file mode 100644 index c27b53a4..00000000 --- a/src/main/java/com/webank/ai/fate/board/dao/UserMapper.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 The FATE Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.webank.ai.fate.board.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.webank.ai.fate.board.pojo.UserDO; -import com.webank.ai.fate.board.pojo.UserDTO; - -import java.util.List; - -public interface UserMapper extends BaseMapper { - - List find(UserDTO userDTO); -} diff --git a/src/main/java/com/webank/ai/fate/board/intercept/UserInterceptor.java b/src/main/java/com/webank/ai/fate/board/intercept/UserInterceptor.java index e76fff97..6ecbfc63 100644 --- a/src/main/java/com/webank/ai/fate/board/intercept/UserInterceptor.java +++ b/src/main/java/com/webank/ai/fate/board/intercept/UserInterceptor.java @@ -18,8 +18,6 @@ import com.alibaba.fastjson.JSON; import com.webank.ai.fate.board.global.ErrorCode; import com.webank.ai.fate.board.global.ResponseResult; -import com.webank.ai.fate.board.pojo.UserDO; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; diff --git a/src/main/java/com/webank/ai/fate/board/pojo/UserDO.java b/src/main/java/com/webank/ai/fate/board/pojo/UserDO.java deleted file mode 100644 index f405c522..00000000 --- a/src/main/java/com/webank/ai/fate/board/pojo/UserDO.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2019 The FATE Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.webank.ai.fate.board.pojo; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import java.io.Serializable; -import java.util.Date; - -@Data -@TableName("t_fateboard_user") -public class UserDO implements Serializable { - - @ApiModelProperty(value = "primary key") - @TableId(value = "user_id", type = IdType.AUTO) - private Long userId; - - @ApiModelProperty(value = "user name") - @TableField(value = "name") - private String name; - - @ApiModelProperty(value = "user password") - @TableField(value = "password") - private String password; - - - @ApiModelProperty(value = "user status") - @TableField(value = "status") - private Integer status; - - @ApiModelProperty(value = "create time") - @TableField(value = "create_time") - private Date createTime; - - @ApiModelProperty(value = "update time") - @TableField(value = "update_time") - private Date updateTime; - -} diff --git a/src/main/java/com/webank/ai/fate/board/pojo/UserDTO.java b/src/main/java/com/webank/ai/fate/board/pojo/UserDTO.java index 855bb731..7c535d96 100644 --- a/src/main/java/com/webank/ai/fate/board/pojo/UserDTO.java +++ b/src/main/java/com/webank/ai/fate/board/pojo/UserDTO.java @@ -15,7 +15,6 @@ */ package com.webank.ai.fate.board.pojo; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotNull; diff --git a/src/main/java/com/webank/ai/fate/board/services/UserService.java b/src/main/java/com/webank/ai/fate/board/services/UserService.java index 3991a3a2..d29ea388 100644 --- a/src/main/java/com/webank/ai/fate/board/services/UserService.java +++ b/src/main/java/com/webank/ai/fate/board/services/UserService.java @@ -15,35 +15,39 @@ */ package com.webank.ai.fate.board.services; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.webank.ai.fate.board.dao.UserMapper; -import com.webank.ai.fate.board.pojo.UserDO; import com.webank.ai.fate.board.pojo.UserDTO; -import org.springframework.beans.factory.annotation.Autowired; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import org.springframework.util.DigestUtils; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import java.util.List; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; @Service public class UserService { + private final static Properties config = new Properties(); + private static final Logger logger = LoggerFactory.getLogger(UserService.class); - @Autowired - UserMapper userMapper; - + //@Autowired + //UserMapper userMapper; public boolean login(UserDTO userDTO, HttpServletRequest httpServletRequest) { + String username = userDTO.getName(); String password = userDTO.getPassword(); - String md5Password = DigestUtils.md5DigestAsHex(password.getBytes()); - userDTO.setPassword(md5Password); - List userDOS = userMapper.find(userDTO); - if (userDOS.size() <= 0) { + + //String md5Password = DigestUtils.md5DigestAsHex(password.getBytes()); + //userDTO.setPassword(md5Password); + //List userDOS = userMapper.find(userDTO); + if (!checkUser(username, password)) { return false; } else { HttpSession session = httpServletRequest.getSession(); - session.setAttribute("USER", userDOS.get(0)); + session.setAttribute("USER", userDTO); return true; } @@ -53,4 +57,31 @@ public void logout(HttpServletRequest httpServletRequest) { HttpSession session = httpServletRequest.getSession(); session.invalidate(); } + + public boolean checkUser(String username, String password) { + updateConfig(); + String usernameValue = getValue("server.board.login.username"); + String passwordValue = getValue("server.board.login.password"); + return username.equals(usernameValue) && password.equals(passwordValue); + } + + public static void updateConfig() { + try { + String confP = "conf/application.properties"; + String configP = "config/application.properties"; + File configFile = new File(confP); + if (configFile.exists() || (configFile = new File(configP)).exists()) { + BufferedReader bufferedReader = new BufferedReader(new FileReader(configFile)); + config.load(bufferedReader); + } else { + config.load(UserService.class.getClassLoader().getResourceAsStream("application.properties")); + } + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + + public static String getValue(String key){ + return config.getProperty(key); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3b89a1a7..d59e944e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -15,4 +15,6 @@ spring.datasource.druid.filter.config.enabled=false spring.datasource.druid.web-stat-filter.enabled=false spring.datasource.druid.stat-view-servlet.enabled=false server.compression.enabled=true -server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain \ No newline at end of file +server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain +server.board.login.username=admin +server.board.login.password=admin \ No newline at end of file diff --git a/src/main/resources/fate/fateboard/mapping/UserMapper.xml b/src/main/resources/fate/fateboard/mapping/UserMapper.xml deleted file mode 100644 index 88043e79..00000000 --- a/src/main/resources/fate/fateboard/mapping/UserMapper.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 0e5bc566..f619f8fd 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -4,23 +4,26 @@ xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd" debug="false" scan="true" scanPeriod="30 second"> - + + + DEBUG + - [%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n - + + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n - [%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n - + + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n ERROR @@ -30,17 +33,16 @@ ${ROOT}%d/error.%d.log ${MAXHISTORY} - - - - + + + + - [%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n - + [%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n WARN @@ -50,16 +52,16 @@ ${ROOT}%d/warn.%d.log ${MAXHISTORY} - - - + + + - [%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n - + + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n INFO @@ -69,15 +71,15 @@ ${ROOT}%d/info.%d.log ${MAXHISTORY} - - - + + + - [%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n - + + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) [%thread] (%file:%line\) - %m%n DEBUG @@ -87,10 +89,10 @@ ${ROOT}%d/debug.%d.log ${MAXHISTORY} - - - - + + + + @@ -108,10 +110,10 @@ class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> ${ROOT}%d/httpclient.%d.log ${MAXHISTORY} - - - - + + + + @@ -120,14 +122,14 @@ - + - + - + \ No newline at end of file