diff --git a/dq-financial-crms-auth/pom.xml b/dq-financial-crms-auth/pom.xml
index e2266989..2e38007c 100644
--- a/dq-financial-crms-auth/pom.xml
+++ b/dq-financial-crms-auth/pom.xml
@@ -38,6 +38,26 @@
org.springframework.cloud
spring-cloud-starter-openfeign
+
+ org.springframework.cloud
+ spring-cloud-starter-security
+
+
+ org.springframework.security
+ spring-security-jwt
+ 1.1.1.RELEASE
+
+
+ io.jsonwebtoken
+ jjwt
+ 0.9.0
+
+
+ org.springframework.security.oauth
+ spring-security-oauth2
+
+ 2.3.3.RELEASE
+
org.springframework.boot
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplication.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplication.java
index 76c68c1b..1360824d 100644
--- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplication.java
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplication.java
@@ -2,8 +2,14 @@ package com.daqing.financial.crauth;
import org.springframework.boot.SpringApplication;
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.crauth.feign")
+@EnableDiscoveryClient
@SpringBootApplication
+@ComponentScan(basePackages = "com.daqing")
public class DqFinancialCrmsAuthApplication {
public static void main(String[] args) {
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/AuthorizationServer.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/AuthorizationServer.java
new file mode 100644
index 00000000..3ff57348
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/AuthorizationServer.java
@@ -0,0 +1,104 @@
+package com.daqing.financial.crauth.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.authorization.AuthorityReactiveAuthorizationManager;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+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;
+
+ /**
+ * 配置令牌的安全约束(允许哪些请求访问)
+ */
+ @Override
+ public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
+ security
+ .tokenKeyAccess("permitAll()") // 公开提供公钥加密的端点(就是使用jwt令牌的时候需要的)
+ .checkTokenAccess("permitAll()") // 校验令牌
+ .allowFormAuthenticationForClients(); //允许表单提交
+ }
+
+ /**
+ * 配置支持哪些客户端访问
+ */
+ @Override
+ public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
+ clients.inMemory() // 配置在内存里,后期配置在数据库
+ .withClient("river") // 客户端id
+ .secret(new BCryptPasswordEncoder().encode("secret")) // 客户端秘钥(后期客户端访问会带着这个秘钥)
+ .resourceIds("resource1") // 客户端可以访问的资源列表(支持多个)
+ .authorizedGrantTypes("authorization_code","password","client_credentials","implicit","refresh_token") // 该客户端允许授权的方式
+ .scopes("all") // 允许授权的范围
+ .autoApprove(false) // false表示跳转到授权页面授权
+ .redirectUris("http://www.baidu.com"); // 加上验证回调地址
+ }
+
+ /**
+ * 配置令牌(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();
+ }
+}
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/SecurityConfig.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/SecurityConfig.java
new file mode 100644
index 00000000..6ffb91a8
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/SecurityConfig.java
@@ -0,0 +1,68 @@
+package com.daqing.financial.crauth.config;
+
+import com.daqing.financial.crauth.service.impl.CustomerLoginServiceImpl;
+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.config.authentication.PasswordEncoderParser;
+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 CustomerLoginServiceImpl customerLoginService(){
+
+ return new CustomerLoginServiceImpl();
+ }
+
+ // 定义用户信息(查询用户信息),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"); // 登录成功跳转路径
+ }
+}
+
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/TokenConfig.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/TokenConfig.java
new file mode 100644
index 00000000..c6db268d
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/TokenConfig.java
@@ -0,0 +1,22 @@
+package com.daqing.financial.crauth.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();
+ }
+}
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/controller/CustomerLoginController.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/controller/CustomerLoginController.java
new file mode 100644
index 00000000..a9dfed54
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/controller/CustomerLoginController.java
@@ -0,0 +1,27 @@
+package com.daqing.financial.crauth.controller;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @auther River
+ * @date 2020/9/22 15:27
+ */
+@RestController
+@RequestMapping("/customerLogin")
+public class CustomerLoginController {
+
+ @PostMapping("/loginSuccess")
+ public String loginSuccess(){
+
+ return "success";
+ }
+
+ @GetMapping("/test")
+ public String test(){
+
+ return "Hello";
+ }
+}
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/dao/CustomerLoginDao.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/dao/CustomerLoginDao.java
new file mode 100644
index 00000000..5408f65d
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/dao/CustomerLoginDao.java
@@ -0,0 +1,14 @@
+package com.daqing.financial.crauth.dao;
+
+import com.daqing.framework.domain.crms.CustomerEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @auther River
+ * @date 2020/9/22 14:55
+ */
+@Mapper
+public interface CustomerLoginDao {
+
+ CustomerEntity getCustomer(String code);
+}
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/CustomerLoginService.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/CustomerLoginService.java
new file mode 100644
index 00000000..65089e78
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/CustomerLoginService.java
@@ -0,0 +1,8 @@
+package com.daqing.financial.crauth.service;
+
+/**
+ * @auther River
+ * @date 2020/9/22 15:00
+ */
+public interface CustomerLoginService {
+}
diff --git a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/impl/CustomerLoginServiceImpl.java b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/impl/CustomerLoginServiceImpl.java
new file mode 100644
index 00000000..9c564a85
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/impl/CustomerLoginServiceImpl.java
@@ -0,0 +1,39 @@
+package com.daqing.financial.crauth.service.impl;
+
+import com.daqing.financial.crauth.dao.CustomerLoginDao;
+import com.daqing.financial.crauth.service.CustomerLoginService;
+import com.daqing.framework.domain.crms.CustomerEntity;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @auther River
+ * @date 2020/9/22 15:01
+ */
+@Service
+public class CustomerLoginServiceImpl implements CustomerLoginService, UserDetailsService {
+
+ @Autowired
+ private CustomerLoginDao customerLoginDao;
+
+ @Override
+ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
+
+ CustomerEntity customer = customerLoginDao.getCustomer(username);
+ List authorities = new ArrayList<>();
+ authorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
+ System.out.println(customer);
+ UserDetails userDetails = new User(customer.getCode(),new BCryptPasswordEncoder().encode(customer.getPassword()),authorities);
+
+ return userDetails;
+ }
+}
diff --git a/dq-financial-crms-auth/src/main/resources/application.properties b/dq-financial-crms-auth/src/main/resources/application.properties
deleted file mode 100644
index 8b137891..00000000
--- a/dq-financial-crms-auth/src/main/resources/application.properties
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/dq-financial-crms-auth/src/main/resources/bootstrap.properties b/dq-financial-crms-auth/src/main/resources/bootstrap.properties
new file mode 100644
index 00000000..160ddf8b
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/resources/bootstrap.properties
@@ -0,0 +1,19 @@
+
+#
+spring.application.name=dq-financial-crms
+#ĵַ
+spring.cloud.nacos.config.server-addr=192.168.31.142:8848
+spring.cloud.nacos.config.namespace=37d72d30-3178-4173-8b5e-269a23355ed9
+#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
\ No newline at end of file
diff --git a/dq-financial-crms-auth/src/main/resources/mapper/crmsauth/CustomerLoginMapper.xml b/dq-financial-crms-auth/src/main/resources/mapper/crmsauth/CustomerLoginMapper.xml
new file mode 100644
index 00000000..13e9de18
--- /dev/null
+++ b/dq-financial-crms-auth/src/main/resources/mapper/crmsauth/CustomerLoginMapper.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java
index 559a7c53..5405652b 100644
--- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java
+++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java
@@ -12,13 +12,13 @@ import com.daqing.financial.crms.service.CustomerService;
import com.daqing.framework.domain.crms.CompanyCustomerEntity;
import com.daqing.framework.domain.crms.CustomerEntity;
import com.daqing.framework.domain.crms.PersonalCustomerEntity;
-import com.daqing.framework.domain.crms.ext.CrmsConstant;
-import com.daqing.framework.domain.crms.ext.CustomerTO;
-import com.daqing.framework.domain.crms.ext.CustomerCompanyVO;
-import com.daqing.framework.domain.crms.ext.CustomerPersonalVO;
+import com.daqing.framework.domain.crms.ext.*;
import com.daqing.framework.domain.crms.request.CustomerRequest;
+import com.daqing.framework.domain.crms.response.CrmsCode;
import com.daqing.framework.domain.hrms.ext.EmployeeTO;
import com.daqing.framework.domain.hrms.ext.EmployeeVO;
+import com.daqing.framework.domain.hrms.response.HrmsCode;
+import com.daqing.framework.exception.ExceptionCast;
import com.daqing.framework.model.response.ResponseResult;
import com.daqing.framework.utils.PageUtils;
import com.daqing.framework.utils.SnowflakeIdUtils;
@@ -208,25 +208,30 @@ public class CustomerServiceImpl extends ServiceImpl companyList = new ArrayList<>();
- List personalList = new ArrayList<>();
- List longList = customerDao.listCustomerId();
- for (Long id : longList) {
- ResponseResult responseResult = this.queryCustomerById(id);
- if ((responseResult.getData()).getClass() == CustomerCompanyVO.class){
- companyList.add((CustomerCompanyVO) responseResult.getData());
- }else {
- personalList.add((CustomerPersonalVO) responseResult.getData());
+ try {
+ List companyList = new ArrayList<>();
+ List personalList = new ArrayList<>();
+ List longList = customerDao.listCustomerId();
+ for (Long id : longList) {
+ ResponseResult responseResult = this.queryCustomerById(id);
+ if ((responseResult.getData()).getClass() == CustomerCompanyVO.class){
+ companyList.add((CustomerCompanyVO) responseResult.getData());
+ }else {
+ personalList.add((CustomerPersonalVO) responseResult.getData());
+ }
}
+ ExcelUtil.writeExcelWithSheets(response,personalList,"客户资源信息一览表","个人类型",new CustomerPersonalVO())
+ .write(companyList,"企业类型",new CustomerCompanyVO())
+ .finish();
+ }catch (Exception e){
+ ExceptionCast.cast(CrmsCode.CUSTOMER_EXPORT_EXSIT);
}
- ExcelUtil.writeExcelWithSheets(response,personalList,"客户资源信息一览表","个人类型",new CustomerPersonalVO())
- .write(companyList,"企业类型",new CustomerCompanyVO())
- .finish();
}
/**
@@ -234,37 +239,68 @@ public class CustomerServiceImpl extends ServiceImpl companyList = new ArrayList<>();
- List personalList = new ArrayList<>();
- ExcelUtil.writeExcelWithSheets(response,personalList,"客户资源信息表模板","个人类型",new CustomerPersonalVO())
- .write(companyList,"企业类型",new CustomerCompanyVO())
- .finish();
+ try {
+ List companyList = new ArrayList<>();
+ List personalList = new ArrayList<>();
+ ExcelUtil.writeExcelWithSheets(response,personalList,"客户资源信息表模板","个人类型",new CustomerPersonalVO())
+ .write(companyList,"企业类型",new CustomerCompanyVO())
+ .finish();
+ }catch (Exception e){
+ ExceptionCast.cast(CrmsCode.CUSTOMER_EXPORTTEMPLATE_EXSIT);
+ }
}
/**
* 导入excel数据
* @param excel
*/
+ @Transactional
@Override
public void excelImportCustomer(MultipartFile excel) {
//TODO 导入excel数据到数据库,思路耗时太长,有待优化
- List