1. zipkin-service工程

pom

  • 最新版本的 zipkin-server不是这样使用
  • zipkin server要去官网下jar包
  • 它现在不支持sdk的形式嵌入了
    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.6.RELEASE</version><relativePath/></parent><spring-cloud.version>Greenwich.SR2</spring-cloud.version><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-server</artifactId><version>2.11.8</version><exclusions><exclusion><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId></exclusion></exclusions></dependency><dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-autoconfigure-ui</artifactId><version>2.11.8</version></dependency><!--<dependency><groupId>io.zipkin.java</groupId><artifactId>zipkin-storage-mysql</artifactId><version>2.4.1</version></dependency> -->starter-webeureka-client<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies>

yaml 和 enable

spring:application:name: zipkin-server
server:port: 9411eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/#关闭自动收集web请求
management:metrics:web:server:auto-time-requests: false
@EnableEurekaClient
@EnableZipkinServer //已经过时
<a href="https://github.com/openzipkin/zipkin#quick-start">

2. monitoring-server工程

pom

     <dependency> config<groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId></dependency> <dependency> turbine<groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-turbine</artifactId></dependency><dependency> actuator<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!--hystrix-dashboard--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></dependency><!--hystrix --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency>

yaml 和 main方法

spring:application:name: monitor-servicecloud:config:uri: http://localhost:8769fail-fast: trueprofiles:active: pro
@SpringBootApplication //boot
@EnableEurekaClient //eurekaClient
@EnableDiscoveryClient //服务发现client,上面不用开启了
@RestController //json controller
@EnableHystrix //hystrix
@EnableHystrixDashboard //hystrix dashboard
@EnableCircuitBreaker //circuit breaker 要在SpringCloud中使用断路器,需要加上
@EnableTurbine //turbine
public class MonitorServiceApplication {public static void main(String[] args) {SpringApplication.run(MonitorServiceApplication.class, args);}
}

没有这个配置

feign:hystrix:enabled: true

3. uaa-service

流程

  1. 浏览器 用户名 + 密码,到 user_blog, 加入 clientId,请求到 uaa 授权服务器
  2. uaa验证 clientId username 和 pwd,返回JWT
  3. 浏览器 得到 userInfo 和 JWT
  4. 浏览器 header加入 JWT
  5. user_blog 解密JWT,验证权限。 有权限 ,返回资源

pom

<dependencies><!-- 配置-->starter-configstarter-web<dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-jwt</artifactId></dependency><dependency><groupId>org.springframework.security.oauth</groupId><artifactId>spring-security-oauth2</artifactId></dependency>starter-netflix-eureka-client<dependency> jpa<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>starter-actuator<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><configuration><nonFilteredFileExtensions> jks<nonFilteredFileExtension>cert</nonFilteredFileExtension><nonFilteredFileExtension>jks</nonFilteredFileExtension></nonFilteredFileExtensions></configuration></plugin></plugins></build>

yaml

spring:application:name: uaa-servicecloud:config:uri: http://localhost:8769fail-fast: trueprofiles:active: pro
management:security:enabled: false #报错

resources文件下其他代码

fzp-jwt.jks

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration><include resource="org/springframework/boot/logging/logback/base.xml" /><logger name="org.springframework.web" level="INFO"/></configuration>

代码

@EnableEurekaClient

1. entity

role

@Entity
public class Role implements GrantedAuthority {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;@Column(nullable = false)private String name;@Overridepublic String getAuthority() {return name;}@Overridepublic String toString() {return name;}
}

user

@Entity
public class User implements UserDetails, Serializable {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)private Long id;@Column(nullable = false,  unique = true)private String username;@Columnprivate String password;@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)@JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"),inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"))private List<Role> authorities;public User() {}public Long getId() {return id;}public void setId(Long id) {this.id = id;}@Overridepublic Collection<? extends GrantedAuthority> getAuthorities() {return authorities;}public void setAuthorities(List<Role> authorities) {this.authorities = authorities;}}

2. dao 和 service

public interface UserDao extends JpaRepository<User, Long> {User findByUsername(String username);
}@Service
public class UserServiceDetail implements UserDetailsService {@Autowiredprivate UserDao userRepository;@Overridepublic UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {return userRepository.findByUsername(username);}
}

3. config

oauth2 config继承 Authorization Server Configurer Adapter

@Configuration
@Enable Authorization Server //开启 认证server
public class OAuth2Config extends Authorization Server Configurer Adapter {@Override //Client Details Service Configurerpublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {clients.inMemory() //内存 .withClient("uaa-service").secret("123456").scopes("service").autoApprove(true).authorizedGrantTypes("implicit","refresh_token", "password", "authorization_code") //4种都支持.accessTokenValiditySeconds(24*3600);//24小时过期}@Override //Authorization Server Endpoints Configurerpublic void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {//token Store,jwtToken enhancerendpoints.tokenStore(tokenStore()).tokenEnhancer(jwtTokenEnhancer()).authenticationManager(authenticationManager);}@Override//Authorization Server Security Configurerpublic void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()").allowFormAuthenticationForClients().passwordEncoder(NoOpPasswordEncoder.getInstance());/*** 这就是为什么以前,可以fein,却不可以 postMMan吧* 必须设置allowFormAuthenticationForClients 否则没有办法用postman获取token* 也需要指定密码加密方式BCryptPasswordEncoder*/}@Autowired@Qualifier("authenticationManagerBean")private AuthenticationManager authenticationManager;@Bean //tokenpublic TokenStore tokenStore() {return new JwtTokenStore(jwtTokenEnhancer());}@Beanprotected JwtAccessTokenConverter jwtTokenEnhancer() {//得到 key工程KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("fzp-jwt.jks"), "fzp123".toCharArray());//创建 converterJwtAccessTokenConverter converter = new JwtAccessTokenConverter();//设置 keyPair 。注意 这个.jks,可能已经过期,这里会报错,重新生成converter.setKeyPair(keyStoreKeyFactory.getKeyPair("fzp-jwt"));return converter;}
}

resource server配置 Resource Server Configurer Adapter

@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends Resource Server Configurer Adapter{Logger log = LoggerFactory.getLogger(ResourceServerConfiguration.class);@Overridepublic void configure(HttpSecurity http) throws Exception {http.csrf().disable().authorizeRequests() //下面这些请求,直接放行.regexMatchers(".*swagger.*",".*v2.*",".*webjars.*","/user/login.*","/user/registry.*","/user/test.*",".*actuator.*").permitAll().antMatchers("/**").authenticated();
//        .antMatchers("/**").permitAll();}}

security配置 WebSecurity Configurer Adapter

@Configuration
class WebSecurityConfig extends WebSecurity Configurer Adapter {@Override@Beanpublic AuthenticationManager authenticationManagerBean() throws Exception {return super.authentication Manager Bean();}@Overrideprotected void configure(HttpSecurity http) throws Exception {//CSRF:因为不再依赖于Cookie,所以你就不需要考虑对CSRF(跨站请求伪造)的防范。http.csrf().disable().exceptionHandling()// .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)).authenticationEntryPoint(new AuthenticationEntryPoint() {@Overridepublic void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); //401}}).and().authorizeRequests().antMatchers("/**").authenticated().and().httpBasic();}@AutowiredUserServiceDetail userServiceDetail;@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.userDetailsService(userServiceDetail).passwordEncoder(new BCryptPasswordEncoder());}
}
  • UserUtils在后面赋值代码
  • feign的 /oauth/token,依然在后面复制代码
@FeignClient(value = "uaa-service")
@PostMapping(value = "/oauth/token")

14. 微服务综合案例2 zipkin dashboard turbine uaa (2刷)相关推荐

  1. 微服务综合案例-04-业务逻辑处理

      现在我们已经创建好了所需的各个项目,我们的需求是完成用户购买书籍,完成订单操作:   而具体的流程是:下订单需要经过: 登录,查看产品,下订单等操作. 测试登录 账号 admin admin 查看 ...

  2. 微服务架构案例(01):项目技术选型简介,架构图解说明

    本文源码:GitHub·点这里 || GitEE·点这里 一.单体架构 单体架构在中等偏小的业务中比较常见,场景模式就是单个应用.单个数据库.一个程序包(例如war格式或者Jar格式)包含所有业务需求 ...

  3. 阿里云Kuberneters微服务部署案例

    3. 如何安装Docker Desktop for Mac 如何安装Docker Desktop for Mac 4. SpringCloud微服务应用 SpringCloud微服务应用 5. Kub ...

  4. 【DDD/CQRS/微服务架构案例】在Ubuntu 14.04.4 LTS中运行WeText项目的服务端

    在<WeText项目:一个基于.NET实现的DDD.CQRS与微服务架构的演示案例>文章中,我介绍了自己用Visual Studio 2015(C# 6.0 with .NET Frame ...

  5. mycat分库分表+springcloud微服务小案例实现

    文章目录 1. MyCat综合案例 1.1 案例概述 1.1.1 案例介绍 1.1.2 系统架构 1.1.3 技术选型 1.2 案例需求 1.3 案例环境搭建 1.3.1 数据库 1.3.2 工程预览 ...

  6. python sanic加速_python微服务sanic 使用异步zipkin(2) - 一步步创建Sanic插件: sanic-zipin...

    关键字:python sanic 微服务 异步 zipkin sanic-plugin 插件 Sanic-Plugins-Framewor Pypi发布 所需环境:python3.7, Docker, ...

  7. 微服务架构案例(03):数据库选型简介,业务数据规划设计

    本文源码:GitHub·点这里 || GitEE·点这里 更新进度(共6节): 01:项目技术选型简介,架构图解说明 02:业务架构设计,系统分层管理 03:数据库选型,业务数据设计规划 一.数据库选 ...

  8. 微服务架构案例(02):业务架构设计,系统分层管理

    本文源码:GitHub·点这里 || GitEE·点这里 更新进度(共6节): 01:项目技术选型简介,架构图解说明 02:业务架构设计,系统分层管理 一.业务架构设计 1.基础概念 服务的架构设计决 ...

  9. 微服务链路追踪之zipkin搭建

    前言 微服务治理方案中,链路追踪是必修课,SpringCloud的组件其实使用很简单,生产环境中真正令人头疼的往往是软件维护,接口在微服务间的调用究竟哪个环节出现了问题,哪个环节耗时较长,这都是项目上 ...

最新文章

  1. SlickGrid控件最后一行触数据更新条件
  2. opengl 设置每个点的颜色_OpenGL学习笔记(四)着色器
  3. ACE之Reactor模式使用实例
  4. Matlab:成功解决引用了已清除的变量 handles
  5. docker安装配置分布式elasticsearch、kibana、head、cerebro
  6. 使用Nginx代理和转发Websocket连接
  7. 学习笔记(36):Python网络编程并发编程-IO模型介绍
  8. linux tcp cork,Socket选项系列之TCP_CORK(转)
  9. 站立会议中发现的一些新问题
  10. 使用nginx搭建流媒体直播平台(该方式不适用与多人聊天)
  11. 使用Mysql进行数据管理
  12. python中对象和类的关系_Python面向对象之类与类之间的关系
  13. 错误调试:GPU 版 TensorFlow failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
  14. 第05课 Linux命令初探(一)
  15. Alamofire拦截请求AOP,URLProtocol
  16. 区块链在保险业的应用
  17. 无线路由器显示无服务器,路由器没信号怎么办?三招教你解决问题!
  18. jQuery Validate表单中文正则验证+手机号正则验证
  19. antv g6多次渲染问题解决
  20. 西北大新生赛:星球大战【切割线定理】

热门文章

  1. Webpack学习笔记(官网教程)
  2. 错了!王慧文要做的是OpenAl,不只是ChatGPT
  3. 记录今天面试网易游戏—IT技术支持/桌面运维 面试题
  4. 从科学的角度来理解和田玉---第一篇
  5. 汽车行业每周新闻纵览与职位需求
  6. 689-电脑的外部设备驱动程序
  7. 信息系统项目管理师核心考点(四十六)采购工作说明书(SOW)
  8. JS判断某年某月有多少天
  9. 按后退键退出到主界面
  10. ibm软件下载网页链接