From 9ed590b83e66d4aed101699aba7f0834cf4704f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E9=A3=9E=E4=BA=91?= <1941783199@qq.com> Date: Mon, 26 Oct 2020 10:05:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9D=E8=B5=96=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dq-financial-crms-auth/pom.xml | 104 ------------------ .../DqFinancialCrmsAuthApplication.java | 19 ---- .../crauth/config/AuthorizationServer.java | 104 ------------------ .../crauth/config/SecurityConfig.java | 68 ------------ .../financial/crauth/config/TokenConfig.java | 22 ---- .../controller/CustomerLoginController.java | 27 ----- .../crauth/dao/CustomerLoginDao.java | 14 --- .../crauth/service/CustomerLoginService.java | 8 -- .../impl/CustomerLoginServiceImpl.java | 39 ------- .../src/main/resources/bootstrap.properties | 37 ------- .../src/main/resources/logback-spring.xml | 47 -------- .../mapper/crmsauth/CustomerLoginMapper.xml | 10 -- .../DqFinancialCrmsAuthApplicationTests.java | 13 --- dq-financial-crms/pom.xml | 8 +- .../src/main/resources/bootstrap.properties | 74 ++++++------- dq-financial-hrms/pom.xml | 8 +- 16 files changed, 45 insertions(+), 557 deletions(-) delete mode 100644 dq-financial-crms-auth/pom.xml delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplication.java delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/AuthorizationServer.java delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/SecurityConfig.java delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/TokenConfig.java delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/controller/CustomerLoginController.java delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/dao/CustomerLoginDao.java delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/CustomerLoginService.java delete mode 100644 dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/impl/CustomerLoginServiceImpl.java delete mode 100644 dq-financial-crms-auth/src/main/resources/bootstrap.properties delete mode 100644 dq-financial-crms-auth/src/main/resources/logback-spring.xml delete mode 100644 dq-financial-crms-auth/src/main/resources/mapper/crmsauth/CustomerLoginMapper.xml delete mode 100644 dq-financial-crms-auth/src/test/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.java diff --git a/dq-financial-crms-auth/pom.xml b/dq-financial-crms-auth/pom.xml deleted file mode 100644 index c48a935e..00000000 --- a/dq-financial-crms-auth/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.8.RELEASE - - - com.daqing.financial - dq-financial-crms-auth - 0.0.1-SNAPSHOT - dq-financial-crms-auth - 大庆智慧金融平台-客户资源认证服务 - - - 1.8 - Greenwich.SR3 - - - - - - com.daqing.framework - dq-framework-model - 1.0-SNAPSHOT - - - - - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - org.springframework.security.oauth - spring-security-oauth2 - - 2.3.3.RELEASE - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - 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 deleted file mode 100644 index 1360824d..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplication.java +++ /dev/null @@ -1,19 +0,0 @@ -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) { - SpringApplication.run(DqFinancialCrmsAuthApplication.class, 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 deleted file mode 100644 index 3ff57348..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/AuthorizationServer.java +++ /dev/null @@ -1,104 +0,0 @@ -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 deleted file mode 100644 index 20a71a06..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/SecurityConfig.java +++ /dev/null @@ -1,68 +0,0 @@ -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 deleted file mode 100644 index c6db268d..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/config/TokenConfig.java +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index a9dfed54..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/controller/CustomerLoginController.java +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index 5408f65d..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/dao/CustomerLoginDao.java +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 65089e78..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/CustomerLoginService.java +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index dfda02ee..00000000 --- a/dq-financial-crms-auth/src/main/java/com/daqing/financial/crauth/service/impl/CustomerLoginServiceImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -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.getPhone(),new BCryptPasswordEncoder().encode(customer.getPassword()),authorities); - - return userDetails; - } -} diff --git a/dq-financial-crms-auth/src/main/resources/bootstrap.properties b/dq-financial-crms-auth/src/main/resources/bootstrap.properties deleted file mode 100644 index a6616fae..00000000 --- a/dq-financial-crms-auth/src/main/resources/bootstrap.properties +++ /dev/null @@ -1,37 +0,0 @@ - -#�������� -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 - -# 开发和测试环境(prod) -#spring.application.name=dq-financial-crms -#spring.cloud.nacos.config.server-addr=120.78.127.12:8848 -#spring.cloud.nacos.config.namespace=204f5ba8-12e0-46b3-b7ea-5c8e4a966640 -##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=prod -#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=prod -#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=prod -#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/logback-spring.xml b/dq-financial-crms-auth/src/main/resources/logback-spring.xml deleted file mode 100644 index 9d44c6c1..00000000 --- a/dq-financial-crms-auth/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - utf8 - - - - - - - - ${LOG_HOME}/crms_auth.%d{yyyy-MM-dd}.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - 0 - - 512 - - - - - - - - - - - - - - - \ 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 deleted file mode 100644 index ac1cc76d..00000000 --- a/dq-financial-crms-auth/src/main/resources/mapper/crmsauth/CustomerLoginMapper.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/dq-financial-crms-auth/src/test/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.java b/dq-financial-crms-auth/src/test/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.java deleted file mode 100644 index 9f9da1bf..00000000 --- a/dq-financial-crms-auth/src/test/java/com/daqing/financial/crauth/DqFinancialCrmsAuthApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -//package com.daqing.financial.crauth; -// -//import org.junit.Test; -//import org.springframework.boot.test.context.SpringBootTest; -// -//@SpringBootTest -//class DqFinancialCrmsAuthApplicationTests { -// -// @Test -// void contextLoads() { -// } -// -//} diff --git a/dq-financial-crms/pom.xml b/dq-financial-crms/pom.xml index 03108c82..f86c18b2 100644 --- a/dq-financial-crms/pom.xml +++ b/dq-financial-crms/pom.xml @@ -21,13 +21,13 @@ - - + + - +