Merge remote-tracking branch 'origin/master'

# Conflicts:
#	.gitignore
#	dq-framework-common/target/classes/com/daqing/framework/model/response/CommonCode.class
#	dq-govern-gateway/src/main/resources/application.yml
master
river 4 years ago
commit 827f6ee24d
  1. 95
      .gitignore
  2. 6
      .idea/compiler.xml
  3. 26
      dq-financial-crms-auth/src/test/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.java
  4. 72
      dq-financial-crms/src/test/java/com/daqing/financial/crms/DqFinancialCrmsApplicationTests.java
  5. 76
      dq-financial-guarantee/pom.xml
  6. 13
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplication.java
  7. 1
      dq-financial-guarantee/src/main/resources/application.properties
  8. 47
      dq-financial-guarantee/src/main/resources/logback-spring.xml
  9. 13
      dq-financial-guarantee/src/test/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplicationTests.java
  10. 43
      dq-financial-hrms-auth/pom.xml
  11. 6
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplication.java
  12. 64
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/SpringContextHolder.java
  13. 109
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/AuthorizationServer.java
  14. 67
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/SecurityConfig.java
  15. 22
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/TokenConfig.java
  16. 61
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java
  17. 22
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/UserLoginDao.java
  18. 18
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java
  19. 118
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java
  20. 71
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java
  21. 298
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/RedisUtil.java
  22. 1
      dq-financial-hrms-auth/src/main/resources/application.properties
  23. 19
      dq-financial-hrms-auth/src/main/resources/bootstrap.properties
  24. 41
      dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml
  25. 26
      dq-financial-hrms-auth/src/test/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplicationTests.java
  26. 7
      dq-financial-hrms/pom.xml
  27. 47
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/config/ResourceServerConfig.java
  28. 18
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java
  29. 76
      dq-financial-hrms/src/test/java/com/daqing/financial/hrms/DqFinancialHrmsApplicationTests.java
  30. BIN
      dq-financial-hrms/target/classes/com/daqing/financial/hrms/controller/UserController.class
  31. 76
      dq-financial-workflow/pom.xml
  32. 13
      dq-financial-workflow/src/main/java/com/daqing/financial/workflow/DqFinancialWorkflowApplication.java
  33. 1
      dq-financial-workflow/src/main/resources/application.properties
  34. 47
      dq-financial-workflow/src/main/resources/logback-spring.xml
  35. 13
      dq-financial-workflow/src/test/java/com/daqing/financial/workflow/DqFinancialWorkflowApplicationTests.java
  36. 30
      dq-framework-common/pom.xml
  37. 13
      dq-framework-common/src/main/java/com/daqing/framework/exception/ExceptionCatch.java
  38. 2
      dq-framework-common/src/main/java/com/daqing/framework/model/response/CommonCode.java
  39. 6
      dq-framework-common/src/main/java/com/daqing/framework/model/response/ResponseResult.java
  40. 24
      dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java
  41. 2
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/UserEntity.java
  42. 25
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java
  43. 33
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java
  44. 9
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/HrmsCode.java
  45. 12
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/LoginResponse.java
  46. BIN
      dq-framework-model/target/classes/com/daqing/framework/domain/hrms/response/HrmsCode.class
  47. 12
      dq-framework-utils/pom.xml
  48. 11
      dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java
  49. 25
      dq-govern-gateway/src/main/java/com/daqing/financial/gateway/exception/DqException.java
  50. 16
      dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java
  51. 62
      dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/ResultCodeEnum.java
  52. 25
      dq-govern-gateway/src/main/resources/application.yml
  53. 2
      dq-govern-gateway/src/main/resources/jwt.properties
  54. 30
      dq-govern-gateway/src/test/java/com/daqing/financial/gateway/DqGovernGatewayApplicationTests.java
  55. 4
      pom.xml

95
.gitignore vendored

@ -0,0 +1,95 @@
### Java template
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Windows template
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# ignore eclipse files
.project
.classpath
.settings
.metadata
.svn

@ -12,13 +12,15 @@
<module name="dq-framework-model" /> <module name="dq-framework-model" />
<module name="dq-financial-hrms" /> <module name="dq-financial-hrms" />
<module name="dq-framework-common" /> <module name="dq-framework-common" />
<module name="dq-financial-workflow" />
<module name="dq-govern-gateway" /> <module name="dq-govern-gateway" />
<module name="dq-financial-crms-auth" /> <module name="dq-financial-crms-auth" />
<module name="dq-financial-guarantee" />
<module name="dq-financial-hrms-auth" /> <module name="dq-financial-hrms-auth" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel>
<module name="dq-financial-guarantee" target="1.8" />
<module name="dq-financial-workflow" target="1.8" />
</bytecodeTargetLevel>
</component> </component>
<component name="JavacSettings"> <component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE"> <option name="ADDITIONAL_OPTIONS_OVERRIDE">

@ -1,13 +1,13 @@
package com.daqing.financial.crauth; //package com.daqing.financial.crauth;
//
import org.junit.Test; //import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest; //import org.springframework.boot.test.context.SpringBootTest;
//
@SpringBootTest //@SpringBootTest
class DqFinancialCrmsAuthApplicationTests { //class DqFinancialCrmsAuthApplicationTests {
//
@Test // @Test
void contextLoads() { // void contextLoads() {
} // }
//
} //}

@ -1,36 +1,36 @@
package com.daqing.financial.crms; //package com.daqing.financial.crms;
//
import com.daqing.financial.crms.service.impl.CustomerServiceImpl; //import com.daqing.financial.crms.service.impl.CustomerServiceImpl;
import com.daqing.framework.domain.crms.CustomerEntity; //import com.daqing.framework.domain.crms.CustomerEntity;
import com.daqing.framework.domain.crms.ext.CustomerTO; //import com.daqing.framework.domain.crms.ext.CustomerTO;
import com.daqing.framework.domain.crms.request.CustomerRequest; //import com.daqing.framework.domain.crms.request.CustomerRequest;
import com.daqing.framework.utils.PageUtils; //import com.daqing.framework.utils.PageUtils;
import org.junit.Test; //import org.junit.Test;
import org.junit.runner.RunWith; //import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; //import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; //import org.springframework.test.context.junit4.SpringRunner;
//
import java.util.List; //import java.util.List;
//
@SpringBootTest //@SpringBootTest
@RunWith(SpringRunner.class) //@RunWith(SpringRunner.class)
public class DqFinancialCrmsApplicationTests { //public class DqFinancialCrmsApplicationTests {
//
@Autowired // @Autowired
private CustomerServiceImpl customerServiceimpl; // private CustomerServiceImpl customerServiceimpl;
//
CustomerRequest customerRequest = new CustomerRequest(); // CustomerRequest customerRequest = new CustomerRequest();
//
@Test // @Test
public void queryListTest(){ // public void queryListTest(){
customerRequest.setCodeOrName("20200909"); // customerRequest.setCodeOrName("20200909");
/* customerRequest.setStartTime("2020-09-07"); // /* customerRequest.setStartTime("2020-09-07");
customerRequest.setEndTime("2020-09-10");*/ // customerRequest.setEndTime("2020-09-10");*/
customerRequest.setCustomerType(1); // customerRequest.setCustomerType(1);
customerRequest.setCreateTime(12); // customerRequest.setCreateTime(12);
PageUtils list = customerServiceimpl.queryList(1, 10, customerRequest); // PageUtils list = customerServiceimpl.queryList(1, 10, customerRequest);
List<CustomerTO> list1 = (List<CustomerTO>) list.getList(); // List<CustomerTO> list1 = (List<CustomerTO>) list.getList();
list1.forEach(customerEntity -> System.out.println(customerEntity)); // list1.forEach(customerEntity -> System.out.println(customerEntity));
} // }
} //}

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.daqing.financial</groupId>
<artifactId>dq-financial-guarantee</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dq-financial-guarantee</name>
<description>大庆智慧金融平台-担保业务服务</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<!-- <dependency>
<groupId>com.daqing.framework</groupId>
<artifactId>dq-framework-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>-->
<dependency>
<groupId>com.daqing.framework</groupId>
<artifactId>dq-framework-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -1,13 +0,0 @@
package com.daqing.financial.guarantee;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DqFinancialGuaranteeApplication {
public static void main(String[] args) {
SpringApplication.run(DqFinancialGuaranteeApplication.class, args);
}
}

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--定义日志文件的存储地址,使用绝对路径-->
<property name="LOG_HOME" value="d:/logs/daqing/guarantee"/>
<!-- Console 输出设置 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<fileNamePattern>${LOG_HOME}/guarantee.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- 异步输出 -->
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>512</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="FILE"/>
</appender>
<logger name="org.apache.ibatis.cache.decorators.LoggingCache" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.springframework.boot" level="DEBUG"/>
<root level="info">
<!--<appender-ref ref="ASYNC"/>-->
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/>
</root>
</configuration>

@ -1,13 +0,0 @@
package com.daqing.financial.guarantee;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DqFinancialGuaranteeApplicationTests {
@Test
void contextLoads() {
}
}

@ -30,16 +30,27 @@
<artifactId>dq-framework-model</artifactId> <artifactId>dq-framework-model</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> </dependency>
<!--<dependency>
<groupId>com.daqing.financial</groupId>
<artifactId>dq-govern-gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>-->
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>-->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency> </dependency>
<dependency> <!-- <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
@ -49,7 +60,35 @@
<artifactId>junit-vintage-engine</artifactId> <artifactId>junit-vintage-engine</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency>-->
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>-->
<!-- <dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
&lt;!&ndash; 指明版本,解决redis存储出现的问题:java.lang.NoSuchMethodError: org.springframework.data.redis.connection.RedisConnection.set([B[B)V问题 &ndash;&gt;
<version>2.3.3.RELEASE</version>
</dependency>-->
<!-- <dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>-->
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>

@ -2,8 +2,14 @@ package com.daqing.financial.hrauth;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@EnableFeignClients(basePackages = "com.daqing.financial.hrauth.feign")
@EnableDiscoveryClient
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = "com.daqing")
public class DqFinancialHrmsAuthApplication { public class DqFinancialHrmsAuthApplication {
public static void main(String[] args) { public static void main(String[] args) {

@ -0,0 +1,64 @@
package com.daqing.financial.hrauth;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Component
@Lazy(false)
public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
private static ApplicationContext applicationContext = null;
/**
* 取得存储在静态变量中的ApplicationContext.
*/
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) {
return (T) applicationContext.getBean(name);
}
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
public static <T> T getBean(Class<T> requiredType) {
return applicationContext.getBean(requiredType);
}
public static <T> T getBean(String name, Class<T> clazz) {
return getApplicationContext().getBean(name, clazz);
}
/**
* 清除SpringContextHolder中的ApplicationContext为Null.
*/
public static void clearHolder() {
applicationContext = null;
}
/**
* 实现ApplicationContextAware接口, 注入Context到静态变量中.
*/
@Override
public void setApplicationContext(ApplicationContext appContext) {
applicationContext = appContext;
}
/**
* 实现DisposableBean接口, 在Context关闭时清理静态变量.
*/
@Override
public void destroy() {
SpringContextHolder.clearHolder();
}
}

@ -0,0 +1,109 @@
//package com.daqing.financial.hrauth.config;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpMethod;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
//import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
//import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
//import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
//import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
//import org.springframework.security.oauth2.provider.ClientDetailsService;
//import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices;
//import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices;
//import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
//import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
//import org.springframework.security.oauth2.provider.token.TokenStore;
//
///**
// * 配置OAuth2.0授权服务器
// *
// * @auther River
// * @date 2020/9/21 17:49
// */
//@Configuration
//@EnableAuthorizationServer
//public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {
//
// @Autowired
// private TokenStore tokenStore;
//
// @Autowired
// private ClientDetailsService clientDetailsService;
//
// @Autowired
// private AuthenticationManager authenticationManager;
//
// @Autowired
// private AuthorizationCodeServices authorizationCodeServices;
// @Autowired
// public PasswordEncoder passwordEncoder;
//
// /**
// * 配置令牌的安全约束(允许哪些请求访问)
// */
// @Override
// public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
// security
// .tokenKeyAccess("permitAll()") // 公开提供公钥加密的端点(就是使用jwt令牌的时候需要的)
// .checkTokenAccess("permitAll()") // 校验令牌
// .allowFormAuthenticationForClients(); //允许表单提交,允许客户端访问 OAuth2 授权接口,否则请求 token 会返回 401。
// }
//
// /**
// * 配置支持哪些客户端访问
// */
// @Override
// public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
// clients.inMemory()
// .withClient("order-client")
// .secret(passwordEncoder.encode("order-secret-8888"))
// .authorizedGrantTypes("refresh_token", "authorization_code", "password")
// .accessTokenValiditySeconds(3600)
// .scopes("all")
// .and()
// .withClient("user-client")
// .secret(passwordEncoder.encode("user-secret-8888"))
// .authorizedGrantTypes("refresh_token", "authorization_code", "password")
// .accessTokenValiditySeconds(3600)
// .scopes("all");
// }
//
// /**
// * 配置令牌(token)的访问端点
// */
// @Override
// public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
// endpoints
// .authenticationManager(authenticationManager) // 密码模式需要
// .authorizationCodeServices(authorizationCodeServices) // 授权码模式需要
// .tokenServices(tokenServices()) // 令牌的管理方式
// .allowedTokenEndpointRequestMethods(HttpMethod.POST); // 允许的请求方式
// }
//
// /**
// * 令牌服务
// */
// @Bean
// public AuthorizationServerTokenServices tokenServices(){
// DefaultTokenServices service = new DefaultTokenServices();
// service.setClientDetailsService(clientDetailsService); // 客户端信息的服务
// service.setSupportRefreshToken(true); // 是否产生刷新令牌
// service.setTokenStore(tokenStore); // 令牌的存储策略
// service.setAccessTokenValiditySeconds(7200); // 令牌有效期
// service.setRefreshTokenValiditySeconds(259200); // 刷新令牌有效期
// return service;
// }
//
// /**
// * 授权码服务(设置授权码模式的授权码如何存取,暂时在内存,后期在数据库)
// */
// @Bean
// public AuthorizationCodeServices authorizationCodeServices(){
//
// return new InMemoryAuthorizationCodeServices();
// }
//}

@ -0,0 +1,67 @@
//package com.daqing.financial.hrauth.config;
//
//import com.daqing.financial.hrauth.service.impl.UserLoginServiceImpl;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
///**
// * @auther River
// * @date 2020/9/22 10:26
// */
//@Configuration
//@EnableWebSecurity // 开启security
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//
// /**
// * 不能直接new对象,否则会在注入之前被拦截器拦截
// */
// @Bean
// public UserLoginServiceImpl customerLoginService(){
//
// return new UserLoginServiceImpl();
// }
//
// // 定义用户信息(查询用户信息),security帮助我们查询,但是需要告诉他如何去查询
// @Override
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//
// auth.userDetailsService(customerLoginService());
// }
//
//
// // 密码编码器,比对密码的方式
// @Bean
// public PasswordEncoder passwordEncoder(){
//
// return new BCryptPasswordEncoder();
// }
//
// /**
// * 认证管理器
// */
// @Override
// @Bean
// public AuthenticationManager authenticationManagerBean() throws Exception {
//
// return super.authenticationManagerBean();
// }
//
// // 安全拦截机制
// @Override
// protected void configure(HttpSecurity http) throws Exception {
// http.authorizeRequests()
// .antMatchers("/*").authenticated() // 该路径下所有请求都会被拦截
// .anyRequest().permitAll() // 其余的请求可以通过
// .and()
// .formLogin() // 允许表单认证
// .successForwardUrl("/customerLogin/loginSuccess"); // 登录成功跳转路径
// }
//}
//

@ -0,0 +1,22 @@
//package com.daqing.financial.hrauth.config;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.oauth2.provider.token.TokenStore;
//import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
//
///**
// * 令牌配置类
// *
// * @auther River
// * @date 2020/9/22 9:54
// */
//@Configuration
//public class TokenConfig {
//
// @Bean
// public TokenStore tokenStore(){
// // 内存生成,普通令牌
// return new InMemoryTokenStore();
// }
//}

@ -0,0 +1,61 @@
package com.daqing.financial.hrauth.controller;
import com.daqing.financial.hrauth.service.UserLoginService;
import com.daqing.framework.domain.hrms.request.LoginRequest;
import com.daqing.framework.domain.hrms.request.UserLoginRequest;
import com.daqing.framework.model.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
/**
* @auther River
* @date 2020/9/22 15:27
*/
@RestController
@RequestMapping("/hrms/auth/userlogin")
@Api(tags = {"登录"})
public class UserLoginController {
@Autowired
private UserLoginService userLoginService;
@PostMapping("/loginSuccess")
public String loginSuccess(){
return "success";
}
@GetMapping("/test")
public String test(){
return "Hello";
}
@PostMapping("/getBackPwd")
public ResponseResult getBackPwd(@RequestBody @Valid UserLoginRequest user){
boolean result = userLoginService.getBackPwd(user);
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
}
@PostMapping(value = "/login")
@ApiOperation(value = "用户登录")
public ResponseResult login(
@RequestBody LoginRequest loginRequest
/* @RequestParam("password") String password, @RequestParam("phone") String phone,
@RequestParam("type")int type, @RequestParam("wechatId") String wechatId,
@RequestParam("tenDayEffective") int tenDayEffective*/
){
/* LoginRequest loginRequest = new LoginRequest();
loginRequest.setTenDayEffective(tenDayEffective);
loginRequest.setType(type);
loginRequest.setWechatId(wechatId);
loginRequest.setPassword(password);
loginRequest.setPhone(phone);*/
return userLoginService.login(loginRequest);
}
}

@ -0,0 +1,22 @@
package com.daqing.financial.hrauth.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.domain.hrms.request.LoginRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @auther River
* @date 2020/9/22 14:55
*/
@Mapper
public interface UserLoginDao extends BaseMapper<UserEntity> {
UserEntity getUser(String code);
int selectCount(String phoneAccount);
int updatePasswordByPhoneAccount(@Param("phoneAccount") String phoneAccount, @Param("password") String password);
UserEntity login(LoginRequest loginRequest);
UserEntity selectByPhoneAccount(String phoneAccount);
}

@ -0,0 +1,18 @@
package com.daqing.financial.hrauth.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.domain.hrms.request.LoginRequest;
import com.daqing.framework.domain.hrms.request.UserLoginRequest;
import com.daqing.framework.model.response.ResponseResult;
/**
* @auther River
* @date 2020/9/22 15:00
*/
public interface UserLoginService extends IService<UserEntity> {
Boolean getBackPwd(UserLoginRequest user);
//登录
ResponseResult login(LoginRequest loginRequest);
}

@ -0,0 +1,118 @@
package com.daqing.financial.hrauth.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.daqing.financial.hrauth.dao.UserLoginDao;
import com.daqing.financial.hrauth.service.UserLoginService;
import com.daqing.financial.hrauth.util.JwtUtil;
import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.domain.hrms.request.LoginRequest;
import com.daqing.framework.domain.hrms.request.UserLoginRequest;
import com.daqing.framework.domain.hrms.response.HrmsCode;
import com.daqing.framework.domain.hrms.response.LoginResponse;
import com.daqing.framework.exception.ExceptionCast;
import com.daqing.framework.model.response.CommonCode;
import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.util.Md5Util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @auther River
* @date 2020/9/22 15:01
*/
@Service("userLoginService")
public class UserLoginServiceImpl extends ServiceImpl<UserLoginDao, UserEntity> implements UserLoginService{
@Resource
private UserLoginDao userLoginDao;
/* @Autowired
private OdcProperties properties;*/
/* @Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
UserEntity user = userLoginDao.getUser(username);
List<SimpleGrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
System.out.println(user);
UserDetails userDetails = new User(user.getAccount(),new BCryptPasswordEncoder().encode(user.getPassword()),authorities);
return userDetails;
}*/
/**
* 忘记密码
*/
@Override
public Boolean getBackPwd(UserLoginRequest user){
//判断重置密码参数是否为空
if(StringUtils.isEmpty(user.getPhoneAccount())){
ExceptionCast.cast(HrmsCode.PHNOE_ACCOUNT_NOT_EMPTY);
}
if(StringUtils.isEmpty(user.getVerifyCode())){
ExceptionCast.cast(HrmsCode.VERIFY_CODE_ILLEGAL);
}
if(StringUtils.isEmpty(user.getNewPwd())){
ExceptionCast.cast(HrmsCode.NEW_PASSWORD_NOT_EMPTY);
}
//校验手机账号是否存在
/* int count = this.count(new QueryWrapper<UserEntity>()
.eq("phone_account", user.getPhoneAccount()));*/
int count = userLoginDao.selectCount(user.getPhoneAccount());
if (count == 0) {
ExceptionCast.cast(HrmsCode.PHNOE_ACCOUNT_NOT_EXIST);
}
//根据手机号查询相关信息
UserEntity userEntity = baseMapper.selectByPhoneAccount(user.getPhoneAccount());
//判断验证码是否匹配
String verify = "123456";
if(!verify.equals(user.getVerifyCode())){
ExceptionCast.cast(HrmsCode.VERIFY_CODE_ILLEGAL);
}
String newMD5 = Md5Util.md5(user.getNewPwd()+userEntity.getId());
//根据手机号码修改密码
int i = userLoginDao.updatePasswordByPhoneAccount(user.getPhoneAccount(),newMD5);
return i > 0;
}
public ResponseResult login(LoginRequest loginRequest) {
//判断用户登录方式
UserEntity userEntity = baseMapper.login(loginRequest);
if(loginRequest.getType() == 1){//手机号码登录
if(userEntity == null){
return ResponseResult.FAIL(CommonCode.USER_IS_NOT_EXIST.code(), CommonCode.USER_IS_NOT_EXIST.message());
}
String newPassword = Md5Util.md5(loginRequest.getPassword()+userEntity.getId());
if(!newPassword.equals(userEntity.getPassword())){
return ResponseResult.FAIL(CommonCode.PASSWORD_IS_ERROR.code(), CommonCode.PASSWORD_IS_ERROR.message());
}
}else {//微信登录
}
//登录成功,token生成
long times = 84600;
if(loginRequest.getTenDayEffective() == 1){
times = 846000;
}
String token = JwtUtil.createJwtToken(userEntity.getId(), times);
if (true) {
JwtUtil.removeTokenByUserId(userEntity.getId());
}
JwtUtil.putTokenToRedis(userEntity.getId(), token, times);
//返回用户信息
LoginResponse loginResponse = new LoginResponse();
loginResponse.setAccount(userEntity.getAccount());
loginResponse.setToken(token);
return ResponseResult.SUCCESS(loginResponse);
}
}

@ -0,0 +1,71 @@
package com.daqing.financial.hrauth.util;
import com.daqing.framework.util.Md5Util;
import java.util.Set;
/**
* @author zcw
* @version 1.0
* @date 2019/11/23 11:06
* @description jwt工具类
*/
public class JwtUtil {
//private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class);
//private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class);
/**
* 创建token
*
* @param userId;
* @param timeout; 单位是秒
*/
public static String createJwtToken(Long userId, long timeout) {
String token = Md5Util.md5("dq"+userId+timeout+System.currentTimeMillis());
RedisUtil.setEx("dq:token:"+token, String.valueOf(userId), timeout);
return token;
/*return JWT.create()
.withClaim("member", userId)
.withExpiresAt(new Date(System.currentTimeMillis() + timeout * 1000))
.sign(algorithm);*/
}
/**
* token正确且有效则返回userId
*/
/* public static Long verifyToken(String token) {
try {
String noBearerToken = token.replaceFirst("Bearer ", "");
Long userId = JWT.require(algorithm)
.build()
.verify(noBearerToken)
.getClaim("member")
.asLong();
if (RedisUtil.get(getRedisKey(userId, noBearerToken)) != null) {
return userId;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return null;
}*/
public static String getRedisKey(Long userId, String token) {
return String.format("dq:token:"+token, token, String.valueOf(userId));
}
public static void putTokenToRedis(Long userId, String token, long times) {
RedisUtil.setEx(getRedisKey(userId, token), "nothing", times);
}
public static void removeTokenByUserId(Long userId) {
Set<String> tokenSet = RedisUtil.keys(getRedisKey(userId, "*"));
for (String key : tokenSet) {
RedisUtil.del(key);
}
}
}

@ -0,0 +1,298 @@
package com.daqing.financial.hrauth.util;
import com.daqing.financial.hrauth.SpringContextHolder;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* redis工具类
*/
public class RedisUtil {
private final static StringRedisTemplate stringRedisTemplate = SpringContextHolder.getBean("stringRedisTemplate");
/**
* 匹配key
*/
public static Set<String> keys(String pattern) {
return stringRedisTemplate.keys(pattern);
}
/**
* 删除一个key
*/
public static void del(String key) {
stringRedisTemplate.delete(key);
}
/**
* 批量删除key
*/
public static void delByPattern(String pattern) {
Set<String> keySet = keys(pattern);
stringRedisTemplate.delete(keySet);
}
/**
* 设置过期时间单位为秒
*/
public static boolean expire(String key, long seconds) {
return stringRedisTemplate.expire(key, seconds, TimeUnit.SECONDS);
}
/**
* 获取自动过期时间
*/
public static long ttl(String key) {
return stringRedisTemplate.getExpire(key, TimeUnit.SECONDS);
}
/**
* 移除过期时间
*/
public static boolean persist(String key) {
return stringRedisTemplate.persist(key);
}
/////// String 操作
/**
* 给key赋值
*/
public static void set(String key, String value) {
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
op.set(key, value);
}
/**
* 给key赋值并设置过期时间单位为秒
*/
public static void setEx(String key, String value, long seconds) {
set(key, value);
expire(key, seconds);
}
/**
* 将key的值加num
*/
public static void incrBy(String key, long num) {
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
op.increment(key, num);
}
/**
* 获取key的值
*/
public static String get(String key) {
ValueOperations<String, String> op = stringRedisTemplate.opsForValue();
return op.get(key);
}
/////// list操作
/**
* 插入到表头
*/
public static void lPush(String key, String... values) {
ListOperations<String, String> listOp = stringRedisTemplate.opsForList();
listOp.leftPushAll(key, values);
}
/**
* 移除第一个
*/
public static String rPop(String key) {
ListOperations<String, String> listOp = stringRedisTemplate.opsForList();
return listOp.rightPop(key);
}
/**
* 获取list所有
*
* @param key
* @param start
* @param end
* @return
*/
public static List<String> lRange(String key, int start, int end) {
ListOperations<String, String> opsForList = stringRedisTemplate.opsForList();
return opsForList.range(key, start, end);
}
/////// hash
/*
* public static void hset(String key,String hashKey,String value){
* HashOperations<String,String,String> opsForHash =
* stringRedisTemplate.opsForHash(); opsForHash.put(key, hashKey, value); }
*/
/////// set
/////// sorted set
/**
* 存放list
* @param key
* @param list
*/
public static void setList(String key, List<String> list){
ListOperations<String, String> opsForList = stringRedisTemplate.opsForList();
opsForList.leftPushAll(key, list);
}
/**
* HashGet
* @param key 不能为null
* @param item 不能为null
* @return
*/
public static Object hGet(String key,String item){
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
return mapOp.get(key, item);
}
/**
* 获取hashKey对应的所有键值
* @param key
* @return 对应的多个键值
*/
public static Map<Object,Object> hmGet(String key){
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
return mapOp.entries(key);
}
/**
* HashSet
* @param key
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public static boolean hmSet(String key, Map<String,Object> map){
try {
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
mapOp.putAll(key, map);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* HashSet 并设置时间
* @param key
* @param map 对应多个键值
* @param time 时间()
* @return true成功 false失败
*/
public static boolean hmset(String key, Map<String,Object> map, long time){
try {
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
mapOp.putAll(key, map);
if(time>0){
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
* @param key
* @param item
* @param value
* @return true 成功 false失败
*/
public static boolean hset(String key,String item,Object value) {
try {
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
mapOp.put(key, item, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
* @param key
* @param item
* @param value
* @param time 时间() 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public static boolean hset(String key,String item,Object value,long time) {
try {
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
mapOp.put(key, item, value);
if(time>0){
expire(key, time);
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 删除hash表中的值
* @param key 不能为null
* @param item 可以使多个 不能为null
*/
public static void hdel(String key, Object... item){
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
mapOp.delete(key,item);
}
/**
* 判断hash表中是否有该项的值
* @param key 不能为null
* @param item 不能为null
* @return true 存在 false不存在
*/
public static boolean hHasKey(String key, String item){
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
return mapOp.hasKey(key, item);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
* @param key
* @param item
* @param by 要增加几(大于0)
* @return
*/
public static double hincr(String key, String item,double by){
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
return mapOp.increment(key, item, by);
}
/**
* hash递减
* @param key
* @param item
* @param by 要减少记(小于0)
* @return
*/
public static double hdecr(String key, String item,double by){
HashOperations<String, Object, Object> mapOp = stringRedisTemplate.opsForHash();
return mapOp.increment(key, item,-by);
}
}

@ -0,0 +1,19 @@
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
spring.application.name=dq-financial-hrms-auth
#<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ
spring.cloud.nacos.config.server-addr=192.168.31.142:8848
spring.cloud.nacos.config.namespace=7632bdaa-3381-4669-b3f9-2fc73be451e8
#spring.cloud.nacos.config.group=prod
spring.cloud.nacos.config.ext-config[0].data-id=datasource.yml
spring.cloud.nacos.config.ext-config[0].group=dev
spring.cloud.nacos.config.ext-config[0].refresh=true
spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml
spring.cloud.nacos.config.ext-config[1].group=dev
spring.cloud.nacos.config.ext-config[1].refresh=true
spring.cloud.nacos.config.ext-config[2].data-id=other.yml
spring.cloud.nacos.config.ext-config[2].group=dev
spring.cloud.nacos.config.ext-config[2].refresh=true

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.daqing.financial.hrauth.dao.UserLoginDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.daqing.framework.domain.hrms.UserEntity" id="userMap">
<result property="id" column="id"/>
<result property="account" column="account"/>
<result property="phoneAccount" column="phone_account"/>
<result property="password" column="password"/>
<result property="loginNum" column="login_num"/>
<result property="createTime" column="create_time"/>
<result property="motifyTime" column="motify_time"/>
</resultMap>
<update id="updatePasswordByPhoneAccount">
update hrms_user set password = #{password} where phone_account = #{phoneAccount}
</update>
<select id="getUser" parameterType="string" resultType="com.daqing.framework.domain.hrms.UserEntity">
SELECT account,password FROM hrms_user WHERE account = #{account}
</select>
<select id="selectCount" resultType="java.lang.Integer">
select count(1) from hrms_user where phone_account = #{phoneAccount}
</select>
<select id="login" parameterType="com.daqing.framework.domain.hrms.request.LoginRequest" resultType="com.daqing.framework.domain.hrms.UserEntity">
select id,account,phone_account,password,login_num from hrms_user
where del_or_not = 0 and status = 0
<if test="phone != null and phone != '' ">
and phone_account = #{phone}
</if>
<if test="wechatId != null and wechatId != '' ">
and wechat_id = #{wechatId}
</if>
</select>
<select id="selectByPhoneAccount" resultType="com.daqing.framework.domain.hrms.UserEntity">
SELECT id,account FROM hrms_user WHERE phone_account = #{phoneAccount}
</select>
</mapper>

@ -1,13 +1,13 @@
package com.daqing.financial.hrauth; //package com.daqing.financial.hrauth;
//
import org.junit.Test; //import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest; //import org.springframework.boot.test.context.SpringBootTest;
//
@SpringBootTest //@SpringBootTest
class DqFinancialHrmsAuthApplicationTests { //class DqFinancialHrmsAuthApplicationTests {
//
@Test // @Test
void contextLoads() { // void contextLoads() {
} // }
//
} //}

@ -61,6 +61,13 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.5.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>

@ -0,0 +1,47 @@
package com.daqing.financial.hrms.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Value("${security.oauth2.client.client-id}")
private String clientId;
@Value("${security.oauth2.client.client-secret}")
private String secret;
@Value("${security.oauth2.authorization.check-token-access}")
private String checkTokenEndpointUrl;
/* @Autowired
private RedisConnectionFactory redisConnectionFactory;*/
/* @Bean
public TokenStore redisTokenStore (){
return new RedisTokenStore(redisConnectionFactory);
}*/
@Bean
public RemoteTokenServices tokenService() {
RemoteTokenServices tokenService = new RemoteTokenServices();
tokenService.setClientId(clientId);
tokenService.setClientSecret(secret);
tokenService.setCheckTokenEndpointUrl(checkTokenEndpointUrl);
return tokenService;
}
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.tokenServices(tokenService());
}
}

@ -5,6 +5,9 @@ import com.daqing.framework.domain.hrms.UserEntity;
import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.utils.PageUtils; import com.daqing.framework.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
@ -79,4 +82,19 @@ public class UserController {
return ResponseResult.SUCCESS(); return ResponseResult.SUCCESS();
} }
/**
* 只有当访问用户具有 ROLE_ADMIN 权限时才能访问否则返回 401 未授权
* 通过 Authentication 参数或者 SecurityContextHolder.getContext().getAuthentication() 可以拿到授权信息进行查看
* @param authentication
* @return
*/
@GetMapping(value = "get")
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
public Object get(Authentication authentication){
//Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
authentication.getCredentials();
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)authentication.getDetails();
String token = details.getTokenValue();
return token;
}
} }

@ -1,38 +1,38 @@
package com.daqing.financial.hrms; //package com.daqing.financial.hrms;
//
import com.daqing.financial.hrms.service.impl.EmployeeServiceImpl; //import com.daqing.financial.hrms.service.impl.EmployeeServiceImpl;
import com.daqing.framework.domain.crms.CustomerEntity; //import com.daqing.framework.domain.crms.CustomerEntity;
import com.daqing.framework.domain.hrms.EmployeeEntity; //import com.daqing.framework.domain.hrms.EmployeeEntity;
import com.daqing.framework.domain.hrms.ext.EmployeeTO; //import com.daqing.framework.domain.hrms.ext.EmployeeTO;
import com.daqing.framework.utils.PageUtils; //import com.daqing.framework.utils.PageUtils;
import org.junit.Test; //import org.junit.Test;
import org.junit.runner.RunWith; //import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; //import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; //import org.springframework.test.context.junit4.SpringRunner;
//
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.List; //import java.util.List;
//
@SpringBootTest //@SpringBootTest
@RunWith(SpringRunner.class) //@RunWith(SpringRunner.class)
public class DqFinancialHrmsApplicationTests { //public class DqFinancialHrmsApplicationTests {
//
@Autowired // @Autowired
private EmployeeServiceImpl employeeServiceimpl; // private EmployeeServiceImpl employeeServiceimpl;
//
List<Long> ids = new ArrayList<>(); // List<Long> ids = new ArrayList<>();
//
@Test // @Test
public void contextLoads() { // public void contextLoads() {
ids.add(1L); // ids.add(1L);
ids.add(2L); // ids.add(2L);
ids.add(3L); // ids.add(3L);
ids.add(4L); // ids.add(4L);
List<EmployeeTO> list = employeeServiceimpl.getEmployeeAndDeptById(ids); // List<EmployeeTO> list = employeeServiceimpl.getEmployeeAndDeptById(ids);
for (EmployeeTO employeeTO : list) { // for (EmployeeTO employeeTO : list) {
System.out.println(employeeTO); // System.out.println(employeeTO);
} // }
} // }
//
} //}

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.daqing.financial</groupId>
<artifactId>dq-financial-workflow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dq-financial-workflow</name>
<description>大庆智慧金融平台-工作流服务</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.daqing.framework</groupId>
<artifactId>dq-framework-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.daqing.framework</groupId>
<artifactId>dq-framework-model</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -1,13 +0,0 @@
package com.daqing.financial.workflow;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DqFinancialWorkflowApplication {
public static void main(String[] args) {
SpringApplication.run(DqFinancialWorkflowApplication.class, args);
}
}

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--定义日志文件的存储地址,使用绝对路径-->
<property name="LOG_HOME" value="d:/logs/daqing/workflow"/>
<!-- Console 输出设置 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<fileNamePattern>${LOG_HOME}/workflow.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- 异步输出 -->
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>512</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="FILE"/>
</appender>
<logger name="org.apache.ibatis.cache.decorators.LoggingCache" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.springframework.boot" level="DEBUG"/>
<root level="info">
<!--<appender-ref ref="ASYNC"/>-->
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/>
</root>
</configuration>

@ -1,13 +0,0 @@
package com.daqing.financial.workflow;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DqFinancialWorkflowApplicationTests {
@Test
void contextLoads() {
}
}

@ -19,6 +19,18 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<!--<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>-->
<dependencies> <dependencies>
<!--导入mysql驱动--> <!--导入mysql驱动-->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
@ -102,6 +114,24 @@
<groupId>com.alibaba.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.70</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version> 2.1.8.RELEASE</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>

@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@ -60,4 +61,16 @@ public class ExceptionCatch {
ResultCode resultCode = customException.getResultCode(); ResultCode resultCode = customException.getResultCode();
return new ResponseResult(resultCode); return new ResponseResult(resultCode);
} }
@ExceptionHandler(MethodArgumentNotValidException.class)//捕获CustomException类型异常
@ResponseBody
public ResponseResult MethodArgumentNotValidException(MethodArgumentNotValidException customException) {
customException.printStackTrace();
//记录日志
LOGGER.error("catch exception:{}", customException.getMessage());
String message = customException.getBindingResult().getAllErrors().get(0).getDefaultMessage();
int code =402;
return ResponseResult.FAIL(code,message);
}
} }

@ -23,6 +23,8 @@ public enum CommonCode implements ResultCode {
UNAUTHENTICATED(false, 10001, "此操作需要登陆系统!"), UNAUTHENTICATED(false, 10001, "此操作需要登陆系统!"),
UNAUTHORISE(false, 10002, "权限不足,无权操作!"), UNAUTHORISE(false, 10002, "权限不足,无权操作!"),
INVALID_PARAM(false, 10003, "非法参数!"), INVALID_PARAM(false, 10003, "非法参数!"),
USER_IS_NOT_EXIST(false, 10004, "用户不存在或用户已禁用!"),
PASSWORD_IS_ERROR(false, 10005, "密码错误!"),
SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!");
/** /**

@ -52,7 +52,7 @@ public class ResponseResult<T> {
return new ResponseResult(CommonCode.SUCCESS); return new ResponseResult(CommonCode.SUCCESS);
} }
public ResponseResult SUCCESS(T t) { public static ResponseResult SUCCESS(Object t) {
return new ResponseResult<>(true, 10000, t, "操作成功!"); return new ResponseResult<>(true, 10000, t, "操作成功!");
} }
@ -64,4 +64,8 @@ public class ResponseResult<T> {
return new ResponseResult(CommonCode.FAIL); return new ResponseResult(CommonCode.FAIL);
} }
public static ResponseResult FAIL(int code, String message) {
return new ResponseResult<>(false, code, null, message);
}
} }

@ -0,0 +1,24 @@
package com.daqing.framework.util;
import org.springframework.util.DigestUtils;
/**
* @author zcw
* @version 1.0
* @date 2020/1/6 17:03
* @description md5工具类
*/
public class Md5Util {
public static String md5(String str) {
if (str == null) {
return null;
}
return DigestUtils.md5DigestAsHex(str.getBytes());
}
public static void main(String[] args) {
System.out.printf(md5("1234561"));
}
}

@ -3,10 +3,10 @@ package com.daqing.framework.domain.hrms;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import lombok.Data;
/** /**
* 人资管理系统员工账号信息表用于存储员工账号密码等登录相关数据 * 人资管理系统员工账号信息表用于存储员工账号密码等登录相关数据

@ -0,0 +1,25 @@
package com.daqing.framework.domain.hrms.request;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class LoginRequest {
private int id;
@ApiModelProperty(value = "手机号码")
private String phone;
@ApiModelProperty(value = "登录类型(1:手机号 2:微信登录)")
private int type;
@ApiModelProperty(value = "微信唯一编号")
private String wechatId;
@ApiModelProperty(value = "密码")
private String password;
@ApiModelProperty(value = "登录十天有效 1:有效 2:不处理")
private int tenDayEffective;
}

@ -0,0 +1,33 @@
package com.daqing.framework.domain.hrms.request;
import lombok.Data;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
/**
* 登录找回密码请求体对象
*
* @author gongsj
* @email gongsj@gmail.com
* @date 2020-09-07 17:12:14
*/
@Data
public class UserLoginRequest implements Serializable {
/**
* 手机账号
*/
@Pattern(regexp = "^1(3([0-35-9]\\d|4[1-8])|4[14-9]\\d|5([0125689]\\d|7[1-79])|66\\d|7[2-35-8]\\d|8\\d{2}|9[13589]\\d)\\d{7}$",message = "手机号格式不正确!")
private String phoneAccount;
/**
* 验证码
*/
private String verifyCode;
/**
* 新密码
*/
@Pattern(regexp = "^(?=.*[0-9].*)(?=.*[A-Z].*)(?=.*[a-z].*).{6,20}$",message = "密码格式不正确!")
private String newPwd;
}

@ -20,8 +20,17 @@ public enum HrmsCode implements ResultCode {
DEPT_LEVEL_ILLEGAL(false, 22003, "部门层级不可超出5级!"), DEPT_LEVEL_ILLEGAL(false, 22003, "部门层级不可超出5级!"),
DEPT_EMP_EXSIT(false, 22004, "请将部门下所有员工移除后再执行删除操作!"), DEPT_EMP_EXSIT(false, 22004, "请将部门下所有员工移除后再执行删除操作!"),
DEPT_POSITION_EXSIT(false, 22005, "该部门下已存在该职位!"), DEPT_POSITION_EXSIT(false, 22005, "该部门下已存在该职位!"),
PHNOE_ACCOUNT_NOT_EMPTY(false,33001,"手机号码为空!"),
VERIFY_CODE_NOT_EMPTY(false,33002,"短信验证码为空!"),
NEW_PASSWORD_NOT_EMPTY(false,33003,"新密码不能为空!"),
NEW_PASSWORD_ILLEGAL(false,33004,"新密码格式不正确!"),
VERIFY_CODE_ILLEGAL(false,33005,"验证码不匹配!"),
PHNOE_ACCOUNT_NOT_EXIST(false,33006,"手机号码不存在!"),
EMP_POSITION_EXSIT(false, 22006, "该职位下已关联员工!"); EMP_POSITION_EXSIT(false, 22006, "该职位下已关联员工!");
/** /**
* 操作是否成功 * 操作是否成功
*/ */

@ -0,0 +1,12 @@
package com.daqing.framework.domain.hrms.response;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class LoginResponse {
@ApiModelProperty(value = "用户名")
private String account;
@ApiModelProperty("token令牌")
private String token;
}

@ -25,6 +25,18 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<!--<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>-->
<dependencies> <dependencies>
<dependency> <dependency>

@ -2,6 +2,7 @@ package com.daqing.financial.gateway.config;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.daqing.financial.gateway.util.JwtUtil; import com.daqing.financial.gateway.util.JwtUtil;
import com.daqing.financial.gateway.util.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GatewayFilterChain;
@ -57,10 +58,11 @@ public class ApiGlobalFilter implements GlobalFilter, Ordered {
//有数据 //有数据
}else { }else {
//校验token //校验token
Long userId = verifyJWT(token); //Long userId = verifyJWT(token);
if (userId == null){ String userId = RedisUtil.get("dq:token:"+token);
if (userId == null || "".equals(userId)){
JSONObject message = new JSONObject(); JSONObject message = new JSONObject();
message.put("message", "请重新登录"); message.put("message", "登录已失效,请重新登录");
message.put("code", "401"); message.put("code", "401");
byte[] bits = message.toString().getBytes(StandardCharsets.UTF_8); byte[] bits = message.toString().getBytes(StandardCharsets.UTF_8);
DataBuffer buffer = response.bufferFactory().wrap(bits); DataBuffer buffer = response.bufferFactory().wrap(bits);
@ -69,7 +71,7 @@ public class ApiGlobalFilter implements GlobalFilter, Ordered {
return response.writeWith(Mono.just(buffer)); return response.writeWith(Mono.just(buffer));
} }
//将现在的request,添加当前身份 //将现在的request,添加当前身份
ServerHttpRequest mutableReq = exchange.getRequest().mutate().header("Authorization-UserId", String.valueOf(userId)).build(); ServerHttpRequest mutableReq = exchange.getRequest().mutate().header("Authorization-UserId", userId).build();
ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build(); ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build();
return chain.filter(mutableExchange); return chain.filter(mutableExchange);
} }
@ -83,6 +85,7 @@ public class ApiGlobalFilter implements GlobalFilter, Ordered {
* @return userPhone * @return userPhone
*/ */
private Long verifyJWT(String token){ private Long verifyJWT(String token){
String id = RedisUtil.get("dq:token:"+token);
return JwtUtil.verifyToken(token); return JwtUtil.verifyToken(token);
} }

@ -1,25 +0,0 @@
package com.daqing.financial.gateway.exception;
import com.daqing.financial.gateway.util.ResultCodeEnum;
import lombok.Data;
@Data
public class DqException extends RuntimeException {
private int code;
private ResultCodeEnum resultCodeEnum;
public DqException(ResultCodeEnum codeEnum) {
super(codeEnum.getRemark());
code = codeEnum.getCode();
}
public int getCode() {
return code;
}
public ResultCodeEnum getResultCodeEnum() {
return resultCodeEnum;
}
}

@ -1,10 +1,9 @@
package com.daqing.financial.gateway.util; package com.daqing.financial.gateway.util;
import com.auth0.jwt.JWT; import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.algorithms.Algorithm;
import com.daqing.financial.gateway.SpringContextHolder; import com.daqing.financial.gateway.SpringContextHolder;
import com.daqing.financial.gateway.exception.DqException;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
@ -19,7 +18,7 @@ public class JwtUtil {
private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class); private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class);
private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class); //private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class);
/** /**
* 创建token * 创建token
@ -49,17 +48,18 @@ public class JwtUtil {
return userId; return userId;
} }
} catch (Exception e) { } catch (Exception e) {
throw new DqException(ResultCodeEnum.UN_AUTHORIZATION); e.printStackTrace();
return null;
} }
throw new DqException(ResultCodeEnum.UN_AUTHORIZATION); return null;
} }
public static String getRedisKey(Long userId, String token) { public static String getRedisKey(Long userId, String token) {
return String.format(properties.getConfig().getTokenRedisKeyFormat(), userId, token); return String.format("dq:token:%d:%s", userId, token);
} }
public static void putTokenToRedis(Long userId, String token) { public static void putTokenToRedis(Long userId, String token, long times) {
RedisUtil.setEx(getRedisKey(userId, token), "nothing", properties.getConfig().getTokenExpireSeconds()); RedisUtil.setEx(getRedisKey(userId, token), "nothing", times);
} }
public static void removeTokenByUserId(Long userId) { public static void removeTokenByUserId(Long userId) {

@ -1,62 +0,0 @@
package com.daqing.financial.gateway.util;
public enum ResultCodeEnum {
SUCCESS(0, "请求成功"),
BAD_REQUEST(400, "错误请求"),
UN_AUTHORIZATION(401, "未授权"),
SERVER_EXCEPTION(500, "服务器异常"),
ACCOUNT_NOT_EXIST(10000, "账号不存在"),
ACCOUNT_NOT_BIND(10001, "账号未绑定钱包"),
ACCOUNT_NOT_ACTIVE(10002, "账号未激活"),
ACCOUNT_EXIST(10003, "账号已存在,请登录"),
COIN_ADDRESS_IS_NOT_EXIST(10004, "该币种地址不存在"),
COIN_NAME_IS_NOT_EXIST(10005, "该币种不存在"),
WALLET_BAD_PARAM(10100, "非法参数,禁止访问他人账号"),
WALLET_NOT_ENOUGH(10101, "可用余额不足"),
SUB_ACCOUNT_NOT_ALLOW_WITHDRAW(10102, "子账号不允许提币"),
USER_NAME_ALREADY_EXISTS(10103,"用户名已存在"),
USER_EMAIL_ALREADY_EXISTS(10104,"邮箱已存在"),
INVITATION_CODE_NOT_EXIST(10105,"邀请码不存在"),
DEVICE_EXIST(10106,"设备号相同"),
LOGINPASSWORD_ERROR(10107,"登录密码错误"),
ACCOUNT_DISABLED(10108,"账号已禁用"),
USER_NAME_IS_ENABLE(10109,"用户名不存在"),
USER_IS_ACTIVE(10111,"该用户已激活"),
PAY_PASSWORD_IS_ERROR(10112,"支付密码错误"),
USER_IS_ACTIVE_MAX(10113,"您的激活次数已上线"),
WITHDRAW_IS_ENABLE(10114,"该币种已关闭提币通道"),
WITHDRAW_IS_NOT_BEGIN_TIME(10115,"未到提币时间"),
WITHDRAW_IS_SUPER_END_TIME(10116,"提币时间已过"),
WITHDRAW_MIN_ERROR(10117,"不能小于最小提币金额"),
WITHDRAW_MAX_ERROR(10118,"不能大于最大提币金额"),
WITHDRAW_MAX_TODAY(10120,"当日提币金额已上限"),
TRANSFER_IS_ENABLE(10121,"该币种已关闭转账通道"),
TRANSFER_MIN_ERROR(10122,"不能小于最小转账金额"),
TRANSFER_MAX_ERROR(10123,"不能大于最大转账金额"),
TRANSFER_MAX_TODAY(10124,"当日转账金额已上限"),
USERNAME_AND_EMAIL_ERROR(10125,"用户名和邮箱不匹配"),
EMAIL_CODE_IS_ERROR(10126,"验证码错误"),
PAY_PASSWORD_IS_NULL(10127,"请先设置支付密码"),
CHAIN_IS_ERROR(10128,"链上异常请联系管理员");
private final int code;
private final String remark;
ResultCodeEnum(int code, String remark) {
this.code = code;
this.remark = remark;
}
public int getCode() {
return code;
}
public String getRemark() {
return remark;
}
}

@ -13,23 +13,14 @@ spring:
# - Query=url,qq # - Query=url,qq
# #
- id: hrms_route - id: hrms_route
#uri: lb://dq-financial-hrms uri: lb://dq-financial-hrms
uri: http://dq-financial-hrms
predicates: predicates:
- Path=/api/** - Path=/api/**
filters: filters:
- RewritePath=/api/(?<segment>.*),/ $\{segment} - RewritePath=/api/(?<segment>.*), /$\{segment}
- id: hrms_auth_route
# - id: crms_auth uri: http://localhost:9000/dq-financial-hrms-auth #lb://dq-financial-hrms-auth
# uri: lb://dq-financial-crms predicates:
# predicates: - Path=/apiHrmsAuth/**
# - Path=/crms/** filters:
# filters: - RewritePath=/apiHrmsAuth/(?<segment>.*), /$\{segment}
# - RewritePath=/crms/(?<segment>.*),/ $\{segment}
redis:
host:
port:
password:
database: 1
timeout: 60s

@ -1 +1 @@
jwt.ignoreUrlList=/api/hrms/employee/list,/route-api/refresh jwt.ignoreUrlList=/apiHrmsAuth/hrms/auth/userlogin/getBackPwd,/apiHrmsAuth/hrms/auth/userlogin/login

@ -1,15 +1,15 @@
package com.daqing.financial.gateway; //package com.daqing.financial.gateway;
//
import org.junit.Test; //import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest; //import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; //import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
//
@EnableDiscoveryClient //@EnableDiscoveryClient
@SpringBootTest //@SpringBootTest
class DqGovernGatewayApplicationTests { //class DqGovernGatewayApplicationTests {
//
@Test // @Test
void contextLoads() { // void contextLoads() {
} // }
//
} //}

@ -18,7 +18,7 @@
<module>dq-financial-hrms-auth</module> <module>dq-financial-hrms-auth</module>
<module>dq-financial-crms</module> <module>dq-financial-crms</module>
<module>dq-financial-crms-auth</module> <module>dq-financial-crms-auth</module>
<module>dq-financial-workflow</module> <!-- <module>dq-financial-workflow</module>
<module>dq-financial-guarantee</module> <module>dq-financial-guarantee</module>-->
</modules> </modules>
</project> </project>

Loading…
Cancel
Save